Esempio n. 1
0
def listcmd(ctx, entityfilter):
    """List all state from Home Assistant."""
    ctx.auto_output("table")
    states = api.get_states(ctx)

    result = []  # type: List[Dict]
    if entityfilter == ".*":
        result = states
    else:
        entityfilterre = re.compile(entityfilter)  # type: Pattern

        for entity in states:
            if entityfilterre.search(entity['entity_id']):
                result.append(entity)
    ctx.echo(
        helper.format_output(
            ctx,
            result,
            columns=ctx.columns if ctx.columns else const.COLUMNS_ENTITIES,
        ))
Esempio n. 2
0
def listcmd(ctx, entityfilter):
    """List all state from Home Assistant."""
    ctx.auto_output("table")
    states = api.get_states(ctx)

    result = []  # type: List[Dict]
    if entityfilter == ".*":
        result = states
    else:
        entityfilterre = re.compile(entityfilter)  # type: Pattern

        for entity in states:
            if entityfilterre.search(entity['entity_id']):
                result.append(entity)
    ctx.echo(
        helper.format_output(
            ctx,
            result,
            columns=ctx.columns if ctx.columns else const.COLUMNS_ENTITIES,
        )
    )
Esempio n. 3
0
def entities(ctx: Configuration, args: List,
             incomplete: str) -> List[Tuple[str, str]]:
    """Entities."""
    _init_ctx(ctx)
    try:
        response = api.get_states(ctx)
    except HTTPError:
        response = []

    completions = []  # type List[Tuple[str, str]]

    if response:
        for entity in response:
            friendly_name = entity['attributes'].get('friendly_name', '')
            completions.append((entity['entity_id'], friendly_name))

        completions.sort()

        return [c for c in completions if incomplete in c[0]]

    return completions
def entities(
    ctx: Configuration, args: List, incomplete: str
) -> List[Tuple[str, str]]:
    """Entities."""
    _init_ctx(ctx)
    try:
        response = api.get_states(ctx)
    except HTTPError:
        response = []

    completions = []  # type List[Tuple[str, str]]

    if response:
        for entity in response:
            friendly_name = entity['attributes'].get('friendly_name', '')
            completions.append((entity['entity_id'], friendly_name))

        completions.sort()

        return [c for c in completions if incomplete in c[0]]

    return completions