Remove optional validation when creating conditions (#60481)
This commit is contained in:
parent
76b047dd12
commit
caf5ee2fab
24 changed files with 486 additions and 580 deletions
|
@ -152,7 +152,6 @@ def trace_condition_function(condition: ConditionCheckerType) -> ConditionChecke
|
|||
async def async_from_config(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType | Template,
|
||||
config_validation: bool = True,
|
||||
) -> ConditionCheckerType:
|
||||
"""Turn a condition configuration into a method.
|
||||
|
||||
|
@ -181,21 +180,15 @@ async def async_from_config(
|
|||
check_factory = check_factory.func
|
||||
|
||||
if asyncio.iscoroutinefunction(check_factory):
|
||||
return cast(
|
||||
ConditionCheckerType, await factory(hass, config, config_validation)
|
||||
)
|
||||
return cast(ConditionCheckerType, factory(config, config_validation))
|
||||
return cast(ConditionCheckerType, await factory(hass, config))
|
||||
return cast(ConditionCheckerType, factory(config))
|
||||
|
||||
|
||||
async def async_and_from_config(
|
||||
hass: HomeAssistant, config: ConfigType, config_validation: bool = True
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> ConditionCheckerType:
|
||||
"""Create multi condition matcher using 'AND'."""
|
||||
if config_validation:
|
||||
config = cv.AND_CONDITION_SCHEMA(config)
|
||||
checks = [
|
||||
await async_from_config(hass, entry, False) for entry in config["conditions"]
|
||||
]
|
||||
checks = [await async_from_config(hass, entry) for entry in config["conditions"]]
|
||||
|
||||
@trace_condition_function
|
||||
def if_and_condition(
|
||||
|
@ -223,14 +216,10 @@ async def async_and_from_config(
|
|||
|
||||
|
||||
async def async_or_from_config(
|
||||
hass: HomeAssistant, config: ConfigType, config_validation: bool = True
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> ConditionCheckerType:
|
||||
"""Create multi condition matcher using 'OR'."""
|
||||
if config_validation:
|
||||
config = cv.OR_CONDITION_SCHEMA(config)
|
||||
checks = [
|
||||
await async_from_config(hass, entry, False) for entry in config["conditions"]
|
||||
]
|
||||
checks = [await async_from_config(hass, entry) for entry in config["conditions"]]
|
||||
|
||||
@trace_condition_function
|
||||
def if_or_condition(
|
||||
|
@ -258,14 +247,10 @@ async def async_or_from_config(
|
|||
|
||||
|
||||
async def async_not_from_config(
|
||||
hass: HomeAssistant, config: ConfigType, config_validation: bool = True
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> ConditionCheckerType:
|
||||
"""Create multi condition matcher using 'NOT'."""
|
||||
if config_validation:
|
||||
config = cv.NOT_CONDITION_SCHEMA(config)
|
||||
checks = [
|
||||
await async_from_config(hass, entry, False) for entry in config["conditions"]
|
||||
]
|
||||
checks = [await async_from_config(hass, entry) for entry in config["conditions"]]
|
||||
|
||||
@trace_condition_function
|
||||
def if_not_condition(
|
||||
|
@ -433,12 +418,8 @@ def async_numeric_state( # noqa: C901
|
|||
return True
|
||||
|
||||
|
||||
def async_numeric_state_from_config(
|
||||
config: ConfigType, config_validation: bool = True
|
||||
) -> ConditionCheckerType:
|
||||
def async_numeric_state_from_config(config: ConfigType) -> ConditionCheckerType:
|
||||
"""Wrap action method with state based condition."""
|
||||
if config_validation:
|
||||
config = cv.NUMERIC_STATE_CONDITION_SCHEMA(config)
|
||||
entity_ids = config.get(CONF_ENTITY_ID, [])
|
||||
attribute = config.get(CONF_ATTRIBUTE)
|
||||
below = config.get(CONF_BELOW)
|
||||
|
@ -548,12 +529,8 @@ def state(
|
|||
return duration_ok
|
||||
|
||||
|
||||
def state_from_config(
|
||||
config: ConfigType, config_validation: bool = True
|
||||
) -> ConditionCheckerType:
|
||||
def state_from_config(config: ConfigType) -> ConditionCheckerType:
|
||||
"""Wrap action method with state based condition."""
|
||||
if config_validation:
|
||||
config = cv.STATE_CONDITION_SCHEMA(config)
|
||||
entity_ids = config.get(CONF_ENTITY_ID, [])
|
||||
req_states: str | list[str] = config.get(CONF_STATE, [])
|
||||
for_period = config.get("for")
|
||||
|
@ -656,12 +633,8 @@ def sun(
|
|||
return True
|
||||
|
||||
|
||||
def sun_from_config(
|
||||
config: ConfigType, config_validation: bool = True
|
||||
) -> ConditionCheckerType:
|
||||
def sun_from_config(config: ConfigType) -> ConditionCheckerType:
|
||||
"""Wrap action method with sun based condition."""
|
||||
if config_validation:
|
||||
config = cv.SUN_CONDITION_SCHEMA(config)
|
||||
before = config.get("before")
|
||||
after = config.get("after")
|
||||
before_offset = config.get("before_offset")
|
||||
|
@ -703,12 +676,8 @@ def async_template(
|
|||
return result
|
||||
|
||||
|
||||
def async_template_from_config(
|
||||
config: ConfigType, config_validation: bool = True
|
||||
) -> ConditionCheckerType:
|
||||
def async_template_from_config(config: ConfigType) -> ConditionCheckerType:
|
||||
"""Wrap action method with state based condition."""
|
||||
if config_validation:
|
||||
config = cv.TEMPLATE_CONDITION_SCHEMA(config)
|
||||
value_template = cast(Template, config.get(CONF_VALUE_TEMPLATE))
|
||||
|
||||
@trace_condition_function
|
||||
|
@ -808,12 +777,8 @@ def time(
|
|||
return True
|
||||
|
||||
|
||||
def time_from_config(
|
||||
config: ConfigType, config_validation: bool = True
|
||||
) -> ConditionCheckerType:
|
||||
def time_from_config(config: ConfigType) -> ConditionCheckerType:
|
||||
"""Wrap action method with time based condition."""
|
||||
if config_validation:
|
||||
config = cv.TIME_CONDITION_SCHEMA(config)
|
||||
before = config.get(CONF_BEFORE)
|
||||
after = config.get(CONF_AFTER)
|
||||
weekday = config.get(CONF_WEEKDAY)
|
||||
|
@ -873,12 +838,8 @@ def zone(
|
|||
)
|
||||
|
||||
|
||||
def zone_from_config(
|
||||
config: ConfigType, config_validation: bool = True
|
||||
) -> ConditionCheckerType:
|
||||
def zone_from_config(config: ConfigType) -> ConditionCheckerType:
|
||||
"""Wrap action method with zone based condition."""
|
||||
if config_validation:
|
||||
config = cv.ZONE_CONDITION_SCHEMA(config)
|
||||
entity_ids = config.get(CONF_ENTITY_ID, [])
|
||||
zone_entity_ids = config.get(CONF_ZONE, [])
|
||||
|
||||
|
@ -915,28 +876,24 @@ def zone_from_config(
|
|||
|
||||
|
||||
async def async_device_from_config(
|
||||
hass: HomeAssistant, config: ConfigType, config_validation: bool = True
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> ConditionCheckerType:
|
||||
"""Test a device condition."""
|
||||
if config_validation:
|
||||
config = cv.DEVICE_CONDITION_SCHEMA(config)
|
||||
platform = await async_get_device_automation_platform(
|
||||
hass, config[CONF_DOMAIN], "condition"
|
||||
)
|
||||
return trace_condition_function(
|
||||
cast(
|
||||
ConditionCheckerType,
|
||||
platform.async_condition_from_config(config, config_validation), # type: ignore
|
||||
platform.async_condition_from_config(config), # type: ignore
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
async def async_trigger_from_config(
|
||||
hass: HomeAssistant, config: ConfigType, config_validation: bool = True
|
||||
hass: HomeAssistant, config: ConfigType
|
||||
) -> ConditionCheckerType:
|
||||
"""Test a trigger condition."""
|
||||
if config_validation:
|
||||
config = cv.TRIGGER_CONDITION_SCHEMA(config)
|
||||
trigger_id = config[CONF_ID]
|
||||
|
||||
@trace_condition_function
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue