Ejemplo n.º 1
0
def cli(ctx: Configuration) -> None:
    """Print the current location on a map."""
    response = api.get_config(ctx)

    if response:
        url = '{0}/?mlat={2}&mlon={3}#map={1}/{2}/{3}'.format(
            OSM_URL, ZOOM, response.get('latitude'), response.get('longitude'))
        webbrowser.open_new_tab(url)
Ejemplo n.º 2
0
def release(ctx: Configuration):
    """Get the release of Home Assistant."""
    click.echo(
        format_output(
            ctx,
            [api.get_config(ctx)['version']],
            columns=ctx.columns if ctx.columns else [('VERSION', '$')],
        ))
Ejemplo n.º 3
0
def whitelist_dirs(ctx: Configuration):
    """Get the whitelisted directories from Home Assistant."""
    click.echo(
        format_output(
            ctx,
            api.get_config(ctx)['whitelist_external_dirs'],
            columns=ctx.columns if ctx.columns else [('DIRECTORY', '$')],
        ))
Ejemplo n.º 4
0
def components(ctx: Configuration):
    """Get loaded components from Home Assistant."""
    click.echo(
        format_output(
            ctx,
            api.get_config(ctx)['components'],
            columns=ctx.columns if ctx.columns else [('COMPONENT', '$')],
        ))
Ejemplo n.º 5
0
def full(ctx: Configuration):
    """Get full details on the configuration from Home Assistant."""
    click.echo(
        format_output(
            ctx,
            [api.get_config(ctx)],
            columns=ctx.columns if ctx.columns else COLUMNS_DETAILS,
        ))
Ejemplo n.º 6
0
def cli(ctx: Configuration) -> None:
    """Print the current location on a map."""
    response = api.get_config(ctx)

    if response:
        url = '{0}/?mlat={2}&mlon={3}#map={1}/{2}/{3}'.format(
            OSM_URL, ZOOM, response.get('latitude'), response.get('longitude')
        )
        webbrowser.open_new_tab(url)
Ejemplo n.º 7
0
def cli(ctx: Configuration, service: str, entity: str) -> None:
    """Show the location of the config or an entity on a map."""
    latitude = None
    longitude = None

    if entity:
        thing = entity
        data = api.get_state(ctx, entity)
        if data:
            attr = data.get('attributes', {})
            latitude = attr.get('latitude')
            longitude = attr.get('longitude')
            thing = attr.get('friendly_name', entity)
    else:
        thing = "configuration"
        response = api.get_config(ctx)
        if response:
            latitude = response.get('latitude')
            longitude = response.get('longitude')
            thing = response.get('location_name', thing)

    if latitude and longitude:
        urlpattern = SERVICE.get(service)
        import urllib.parse

        if urlpattern:
            url = urlpattern.format(latitude, longitude,
                                    urllib.parse.quote_plus(thing))
            ctx.echo("{} location is at {}, {}".format(thing, latitude,
                                                       longitude))
            webbrowser.open_new_tab(url)
        else:
            ctx.echo(
                "Could not find url pattern for service {}".format(service))
    else:
        ctx.echo("No exact location info found in {}".format(thing))
        sys.exit(2)