1 """Provide the device automations for Vacuum."""
3 from __future__
import annotations
5 import voluptuous
as vol
17 config_validation
as cv,
18 entity_registry
as er,
23 from .
import DOMAIN, STATE_CLEANING, STATE_DOCKED, STATE_RETURNING
25 CONDITION_TYPES = {
"is_cleaning",
"is_docked"}
27 CONDITION_SCHEMA = DEVICE_CONDITION_BASE_SCHEMA.extend(
29 vol.Required(CONF_ENTITY_ID): cv.entity_id_or_uuid,
30 vol.Required(CONF_TYPE): vol.In(CONDITION_TYPES),
36 hass: HomeAssistant, device_id: str
37 ) -> list[dict[str, str]]:
38 """List device conditions for Vacuum devices."""
39 registry = er.async_get(hass)
43 for entry
in er.async_entries_for_device(registry, device_id):
44 if entry.domain != DOMAIN:
48 CONF_CONDITION:
"device",
49 CONF_DEVICE_ID: device_id,
51 CONF_ENTITY_ID: entry.id,
54 conditions += [{**base_condition, CONF_TYPE: cond}
for cond
in CONDITION_TYPES]
61 hass: HomeAssistant, config: ConfigType
62 ) -> condition.ConditionCheckerType:
63 """Create a function to test a device condition."""
64 if config[CONF_TYPE] ==
"is_docked":
65 test_states = [STATE_DOCKED]
67 test_states = [STATE_CLEANING, STATE_RETURNING]
69 registry = er.async_get(hass)
70 entity_id = er.async_resolve_entity_id(registry, config[CONF_ENTITY_ID])
72 def test_is_state(hass: HomeAssistant, variables: TemplateVarsType) -> bool:
73 """Test if an entity is a certain state."""
76 and (state := hass.states.get(entity_id))
is not None
77 and state.state
in test_states
condition.ConditionCheckerType async_condition_from_config(HomeAssistant hass, ConfigType config)
list[dict[str, str]] async_get_conditions(HomeAssistant hass, str device_id)