mirror of
https://github.com/home-assistant/core.git
synced 2025-08-03 20:55:10 +02:00
Update device condition
This commit is contained in:
@@ -10,6 +10,7 @@ from homeassistant.const import CONF_DOMAIN
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.condition import (
|
from homeassistant.helpers.condition import (
|
||||||
|
Condition,
|
||||||
ConditionCheckerType,
|
ConditionCheckerType,
|
||||||
trace_condition_function,
|
trace_condition_function,
|
||||||
)
|
)
|
||||||
@@ -51,20 +52,38 @@ class DeviceAutomationConditionProtocol(Protocol):
|
|||||||
"""List conditions."""
|
"""List conditions."""
|
||||||
|
|
||||||
|
|
||||||
async def async_validate_condition_config(
|
class DeviceCondition(Condition):
|
||||||
hass: HomeAssistant, config: ConfigType
|
"""Device condition."""
|
||||||
) -> ConfigType:
|
|
||||||
"""Validate device condition config."""
|
def __init__(self, hass: HomeAssistant, config: ConfigType) -> None:
|
||||||
return await async_validate_device_automation_config(
|
"""Initialize condition."""
|
||||||
hass, config, cv.DEVICE_CONDITION_SCHEMA, DeviceAutomationType.CONDITION
|
self._config = config
|
||||||
)
|
self._hass = hass
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
async def async_validate_condition_config(
|
||||||
|
cls, hass: HomeAssistant, config: ConfigType
|
||||||
|
) -> ConfigType:
|
||||||
|
"""Validate device condition config."""
|
||||||
|
return await async_validate_device_automation_config(
|
||||||
|
hass, config, cv.DEVICE_CONDITION_SCHEMA, DeviceAutomationType.CONDITION
|
||||||
|
)
|
||||||
|
|
||||||
|
async def async_condition_from_config(self) -> condition.ConditionCheckerType:
|
||||||
|
"""Test a device condition."""
|
||||||
|
platform = await async_get_device_automation_platform(
|
||||||
|
self._hass, self._config[CONF_DOMAIN], DeviceAutomationType.CONDITION
|
||||||
|
)
|
||||||
|
return trace_condition_function(
|
||||||
|
platform.async_condition_from_config(self._hass, self._config)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
async def async_condition_from_config(
|
CONDITIONS: dict[str, type[Condition]] = {
|
||||||
hass: HomeAssistant, config: ConfigType
|
"device": DeviceCondition,
|
||||||
) -> condition.ConditionCheckerType:
|
}
|
||||||
"""Test a device condition."""
|
|
||||||
platform = await async_get_device_automation_platform(
|
|
||||||
hass, config[CONF_DOMAIN], DeviceAutomationType.CONDITION
|
async def async_get_conditions(hass: HomeAssistant) -> dict[str, type[Condition]]:
|
||||||
)
|
"""Return the sun conditions."""
|
||||||
return trace_condition_function(platform.async_condition_from_config(hass, config))
|
return CONDITIONS
|
||||||
|
Reference in New Issue
Block a user