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_validate_entity_ids( registry, config[CONF_ENTITY_ID]) return config
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_validate_entity_ids(registry, [entry1.id, entry2.id]) == expected expected = ["light.beer", "light.milk"] assert er.async_validate_entity_ids(registry, ["light.beer", entry2.id]) == expected with pytest.raises(vol.Invalid): er.async_validate_entity_ids(registry, ["light.beer", "bad_uuid"]) expected = ["light.unknown"] assert er.async_validate_entity_ids(registry, ["light.unknown"]) == expected with pytest.raises(vol.Invalid): er.async_validate_entity_ids(registry, ["unknown_uuid"])
async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Initialize Fan Group config entry.""" registry = er.async_get(hass) entities = er.async_validate_entity_ids( registry, config_entry.options[CONF_ENTITIES]) async_add_entities( [FanGroup(config_entry.entry_id, config_entry.title, entities)])
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_validate_entity_ids( registry, cv.entity_ids_or_uuids(config[CONF_ENTITY_ID])) return config
async def async_setup_entry( hass: HomeAssistant, config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: """Initialize min/max/mean config entry.""" registry = er.async_get(hass) entity_ids = er.async_validate_entity_ids( registry, config_entry.options[CONF_ENTITY_IDS]) sensor_type = config_entry.options[CONF_TYPE] round_digits = int(config_entry.options[CONF_ROUND_DIGITS]) async_add_entities([ MinMaxSensor( entity_ids, config_entry.title, sensor_type, round_digits, config_entry.entry_id, ) ])