2019-09-24 21:57:05 +00:00
|
|
|
"""Provides device conditions for lights."""
|
2021-03-18 12:07:04 +00:00
|
|
|
from __future__ import annotations
|
2019-12-08 17:16:23 +00:00
|
|
|
|
2019-09-24 21:57:05 +00:00
|
|
|
import voluptuous as vol
|
|
|
|
|
|
|
|
from homeassistant.components.device_automation import toggle_entity
|
|
|
|
from homeassistant.const import CONF_DOMAIN
|
2020-01-29 21:59:45 +00:00
|
|
|
from homeassistant.core import HomeAssistant, callback
|
2019-09-24 21:57:05 +00:00
|
|
|
from homeassistant.helpers.condition import ConditionCheckerType
|
2019-12-08 17:16:23 +00:00
|
|
|
from homeassistant.helpers.typing import ConfigType
|
2019-09-24 21:57:05 +00:00
|
|
|
|
2019-12-08 17:16:23 +00:00
|
|
|
from . import DOMAIN
|
2019-09-24 21:57:05 +00:00
|
|
|
|
|
|
|
CONDITION_SCHEMA = toggle_entity.CONDITION_SCHEMA.extend(
|
|
|
|
{vol.Required(CONF_DOMAIN): DOMAIN}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2020-01-29 21:59:45 +00:00
|
|
|
@callback
|
2019-09-24 21:57:05 +00:00
|
|
|
def async_condition_from_config(
|
|
|
|
config: ConfigType, config_validation: bool
|
|
|
|
) -> ConditionCheckerType:
|
|
|
|
"""Evaluate state based on configuration."""
|
2019-10-02 22:58:14 +00:00
|
|
|
if config_validation:
|
|
|
|
config = CONDITION_SCHEMA(config)
|
2019-10-07 04:06:16 +00:00
|
|
|
return toggle_entity.async_condition_from_config(config)
|
2019-09-24 21:57:05 +00:00
|
|
|
|
|
|
|
|
2019-10-14 20:03:37 +00:00
|
|
|
async def async_get_conditions(
|
|
|
|
hass: HomeAssistant, device_id: str
|
2021-03-18 12:07:04 +00:00
|
|
|
) -> list[dict[str, str]]:
|
2019-09-24 21:57:05 +00:00
|
|
|
"""List device conditions."""
|
|
|
|
return await toggle_entity.async_get_conditions(hass, device_id, DOMAIN)
|
2019-10-03 20:29:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def async_get_condition_capabilities(hass: HomeAssistant, config: dict) -> dict:
|
|
|
|
"""List condition capabilities."""
|
|
|
|
return await toggle_entity.async_get_condition_capabilities(hass, config)
|