Home Assistant Unofficial Reference 2024.12.1
device_condition.py
Go to the documentation of this file.
1 """Provides device conditions for lights."""
2 
3 from __future__ import annotations
4 
5 import voluptuous as vol
6 
7 from homeassistant.components.device_automation import toggle_entity
8 from homeassistant.const import CONF_DOMAIN
9 from homeassistant.core import HomeAssistant, callback
10 from homeassistant.helpers.condition import ConditionCheckerType
11 from homeassistant.helpers.typing import ConfigType
12 
13 from . import DOMAIN
14 
15 # mypy: disallow-any-generics
16 
17 CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
18  {vol.Required(CONF_DOMAIN): DOMAIN}
19 )
20 
21 
22 @callback
24  hass: HomeAssistant, config: ConfigType
25 ) -> ConditionCheckerType:
26  """Evaluate state based on configuration."""
27  return toggle_entity.async_condition_from_config(hass, config)
28 
29 
31  hass: HomeAssistant, device_id: str
32 ) -> list[dict[str, str]]:
33  """List device conditions."""
34  return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
35 
36 
38  hass: HomeAssistant, config: ConfigType
39 ) -> dict[str, vol.Schema]:
40  """List condition capabilities."""
41  return await toggle_entity.async_get_condition_capabilities(hass, config)
ConditionCheckerType async_condition_from_config(HomeAssistant hass, ConfigType config)
list[dict[str, str]] async_get_conditions(HomeAssistant hass, str device_id)
dict[str, vol.Schema] async_get_condition_capabilities(HomeAssistant hass, ConfigType config)