コード例 #1
0
async def async_get_triggers(hass, device_id):
    """List device triggers."""
    triggers = []
    entity_registry = await hass.helpers.entity_registry.async_get_registry()

    entries = [
        entry for entry in async_entries_for_device(entity_registry, device_id)
        if entry.domain == DOMAIN
    ]

    for entry in entries:
        device_class = get_device_class(hass,
                                        entry.entity_id) or DEVICE_CLASS_NONE
        unit_of_measurement = get_unit_of_measurement(hass, entry.entity_id)

        if not unit_of_measurement:
            continue

        templates = ENTITY_TRIGGERS.get(device_class,
                                        ENTITY_TRIGGERS[DEVICE_CLASS_NONE])

        triggers.extend({
            **automation,
            "platform": "device",
            "device_id": device_id,
            "entity_id": entry.entity_id,
            "domain": DOMAIN,
        } for automation in templates)

    return triggers
コード例 #2
0
async def async_get_triggers(
    hass: HomeAssistant, device_id: str
) -> list[dict[str, str]]:
    """List device triggers."""
    triggers: list[dict[str, str]] = []
    entity_registry = er.async_get(hass)

    entries = [
        entry
        for entry in er.async_entries_for_device(entity_registry, device_id)
        if entry.domain == DOMAIN
    ]

    for entry in entries:
        device_class = get_device_class(hass, entry.entity_id) or DEVICE_CLASS_NONE

        templates = ENTITY_TRIGGERS.get(
            device_class, ENTITY_TRIGGERS[DEVICE_CLASS_NONE]
        )

        triggers.extend(
            {
                **automation,
                "platform": "device",
                "device_id": device_id,
                "entity_id": entry.entity_id,
                "domain": DOMAIN,
            }
            for automation in templates
        )

    return triggers
コード例 #3
0
async def async_get_conditions(hass: HomeAssistant,
                               device_id: str) -> list[dict[str, str]]:
    """List device conditions."""
    conditions: list[dict[str, str]] = []
    entity_registry = await async_get_registry(hass)
    entries = [
        entry for entry in async_entries_for_device(entity_registry, device_id)
        if entry.domain == DOMAIN
    ]

    for entry in entries:
        device_class = get_device_class(hass,
                                        entry.entity_id) or DEVICE_CLASS_NONE
        state_class = get_capability(hass, entry.entity_id, ATTR_STATE_CLASS)
        unit_of_measurement = get_unit_of_measurement(hass, entry.entity_id)

        if not unit_of_measurement and not state_class:
            continue

        templates = ENTITY_CONDITIONS.get(device_class,
                                          ENTITY_CONDITIONS[DEVICE_CLASS_NONE])

        conditions.extend({
            **template,
            "condition": "device",
            "device_id": device_id,
            "entity_id": entry.entity_id,
            "domain": DOMAIN,
        } for template in templates)

    return conditions
コード例 #4
0
ファイル: device_condition.py プロジェクト: jcgoette/core
async def async_get_conditions(hass: HomeAssistant,
                               device_id: str) -> list[dict[str, str]]:
    """List device conditions."""
    conditions: list[dict[str, str]] = []
    entity_registry = er.async_get(hass)
    entries = [
        entry
        for entry in er.async_entries_for_device(entity_registry, device_id)
        if entry.domain == DOMAIN
    ]

    for entry in entries:
        device_class = get_device_class(hass,
                                        entry.entity_id) or DEVICE_CLASS_NONE

        templates = ENTITY_CONDITIONS.get(device_class,
                                          ENTITY_CONDITIONS[DEVICE_CLASS_NONE])

        conditions.extend({
            **template,
            "condition": "device",
            "device_id": device_id,
            "entity_id": entry.entity_id,
            "domain": DOMAIN,
        } for template in templates)

    return conditions