예제 #1
0
async def async_get_trigger_capabilities(hass, config):
    """List trigger capabilities."""
    try:
        unit_of_measurement = get_unit_of_measurement(hass,
                                                      config[CONF_ENTITY_ID])
    except HomeAssistantError:
        unit_of_measurement = None

    if not unit_of_measurement:
        raise InvalidDeviceAutomationConfig(
            f"No unit of measurement found for trigger entity {config[CONF_ENTITY_ID]}"
        )

    return {
        "extra_fields":
        vol.Schema({
            vol.Optional(CONF_ABOVE,
                         description={"suffix": unit_of_measurement}):
            vol.Coerce(float),
            vol.Optional(CONF_BELOW,
                         description={"suffix": unit_of_measurement}):
            vol.Coerce(float),
            vol.Optional(CONF_FOR):
            cv.positive_time_period_dict,
        })
    }
예제 #2
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
예제 #3
0
async def async_get_condition_capabilities(
        hass: HomeAssistant, config: ConfigType) -> dict[str, vol.Schema]:
    """List condition capabilities."""
    try:
        unit_of_measurement = get_unit_of_measurement(hass,
                                                      config[CONF_ENTITY_ID])
    except HomeAssistantError:
        unit_of_measurement = None

    if not unit_of_measurement:
        raise InvalidDeviceAutomationConfig(
            "No unit of measurement found for condition entity {config[CONF_ENTITY_ID]}"
        )

    return {
        "extra_fields":
        vol.Schema({
            vol.Optional(CONF_ABOVE,
                         description={"suffix": unit_of_measurement}):
            vol.Coerce(float),
            vol.Optional(CONF_BELOW,
                         description={"suffix": unit_of_measurement}):
            vol.Coerce(float),
        })
    }
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
예제 #5
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
        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_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