Ejemplo n.º 1
0
async def async_validate_trigger_config(hass: HomeAssistant,
                                        config: ConfigType) -> ConfigType:
    """Validate trigger config."""
    config = _TRIGGER_SCHEMA(config)
    registry = er.async_get(hass)
    config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
        registry, config[CONF_ENTITY_ID])
    return config
Ejemplo n.º 2
0
async def test_resolve_entity_ids(hass, registry):
    """Test resolving entity IDs."""

    entry1 = registry.async_get_or_create(
        "light", "hue", "1234", suggested_object_id="beer"
    )
    assert entry1.entity_id == "light.beer"

    entry2 = registry.async_get_or_create(
        "light", "hue", "2345", suggested_object_id="milk"
    )
    assert entry2.entity_id == "light.milk"

    expected = ["light.beer", "light.milk"]
    assert er.async_resolve_entity_ids(registry, [entry1.id, entry2.id]) == expected

    expected = ["light.beer", "light.milk"]
    assert er.async_resolve_entity_ids(registry, ["light.beer", entry2.id]) == expected

    with pytest.raises(vol.Invalid):
        er.async_resolve_entity_ids(registry, ["light.beer", "bad_uuid"])

    expected = ["light.unknown"]
    assert er.async_resolve_entity_ids(registry, ["light.unknown"]) == expected

    with pytest.raises(vol.Invalid):
        er.async_resolve_entity_ids(registry, ["unknown_uuid"])
Ejemplo n.º 3
0
def state_validate_config(hass: HomeAssistant,
                          config: ConfigType) -> ConfigType:
    """Validate state condition config."""

    registry = er.async_get(hass)
    config = dict(config)
    config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
        registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID]))
    return config
Ejemplo n.º 4
0
async def async_validate_trigger_config(hass: HomeAssistant,
                                        config: ConfigType) -> ConfigType:
    """Validate trigger config."""
    if not isinstance(config, dict):
        raise vol.Invalid("Expected a dictionary")

    # We use this approach instead of vol.Any because
    # this gives better error messages.
    if CONF_ATTRIBUTE in config:
        config = TRIGGER_ATTRIBUTE_SCHEMA(config)
    else:
        config = TRIGGER_STATE_SCHEMA(config)

    registry = er.async_get(hass)
    config[CONF_ENTITY_ID] = er.async_resolve_entity_ids(
        registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID]))

    return config