mirror of
https://github.com/home-assistant/core.git
synced 2025-08-06 12:08:19 +00:00
Adjust condition and trigger method names (#150060)
This commit is contained in:
parent
12dca4b1bf
commit
2b0cda0ad1
@ -61,7 +61,7 @@ class DeviceCondition(Condition):
|
||||
self._hass = hass
|
||||
|
||||
@classmethod
|
||||
async def async_validate_condition_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate device condition config."""
|
||||
@ -69,7 +69,7 @@ class DeviceCondition(Condition):
|
||||
hass, config, cv.DEVICE_CONDITION_SCHEMA, DeviceAutomationType.CONDITION
|
||||
)
|
||||
|
||||
async def async_condition_from_config(self) -> condition.ConditionCheckerType:
|
||||
async def async_get_checker(self) -> condition.ConditionCheckerType:
|
||||
"""Test a device condition."""
|
||||
platform = await async_get_device_automation_platform(
|
||||
self._hass, self._config[CONF_DOMAIN], DeviceAutomationType.CONDITION
|
||||
|
@ -131,13 +131,13 @@ class SunCondition(Condition):
|
||||
self._hass = hass
|
||||
|
||||
@classmethod
|
||||
async def async_validate_condition_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
return _CONDITION_SCHEMA(config) # type: ignore[no-any-return]
|
||||
|
||||
async def async_condition_from_config(self) -> ConditionCheckerType:
|
||||
async def async_get_checker(self) -> ConditionCheckerType:
|
||||
"""Wrap action method with sun based condition."""
|
||||
before = self._config.get("before")
|
||||
after = self._config.get("after")
|
||||
|
@ -100,13 +100,13 @@ class ZoneCondition(Condition):
|
||||
self._config = config
|
||||
|
||||
@classmethod
|
||||
async def async_validate_condition_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
return _CONDITION_SCHEMA(config) # type: ignore[no-any-return]
|
||||
|
||||
async def async_condition_from_config(self) -> ConditionCheckerType:
|
||||
async def async_get_checker(self) -> ConditionCheckerType:
|
||||
"""Wrap action method with zone based condition."""
|
||||
entity_ids = self._config.get(CONF_ENTITY_ID, [])
|
||||
zone_entity_ids = self._config.get(CONF_ZONE, [])
|
||||
|
@ -263,13 +263,13 @@ class EventTrigger(Trigger):
|
||||
self._hass = hass
|
||||
|
||||
@classmethod
|
||||
async def async_validate_trigger_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
return await async_validate_trigger_config(hass, config)
|
||||
|
||||
async def async_attach_trigger(
|
||||
async def async_attach(
|
||||
self,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
|
@ -216,13 +216,13 @@ class ValueUpdatedTrigger(Trigger):
|
||||
self._hass = hass
|
||||
|
||||
@classmethod
|
||||
async def async_validate_trigger_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
return await async_validate_trigger_config(hass, config)
|
||||
|
||||
async def async_attach_trigger(
|
||||
async def async_attach(
|
||||
self,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
|
@ -199,14 +199,14 @@ class Condition(abc.ABC):
|
||||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
async def async_validate_condition_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
|
||||
@abc.abstractmethod
|
||||
async def async_condition_from_config(self) -> ConditionCheckerType:
|
||||
"""Evaluate state based on configuration."""
|
||||
async def async_get_checker(self) -> ConditionCheckerType:
|
||||
"""Get the condition checker."""
|
||||
|
||||
|
||||
class ConditionProtocol(Protocol):
|
||||
@ -346,7 +346,7 @@ async def async_from_config(
|
||||
if platform is not None:
|
||||
condition_descriptors = await platform.async_get_conditions(hass)
|
||||
condition_instance = condition_descriptors[condition](hass, config)
|
||||
return await condition_instance.async_condition_from_config()
|
||||
return await condition_instance.async_get_checker()
|
||||
|
||||
for fmt in (ASYNC_FROM_CONFIG_FORMAT, FROM_CONFIG_FORMAT):
|
||||
factory = getattr(sys.modules[__name__], fmt.format(condition), None)
|
||||
@ -974,7 +974,7 @@ async def async_validate_condition_config(
|
||||
condition_descriptors = await platform.async_get_conditions(hass)
|
||||
if not (condition_class := condition_descriptors.get(condition)):
|
||||
raise vol.Invalid(f"Invalid condition '{condition}' specified")
|
||||
return await condition_class.async_validate_condition_config(hass, config)
|
||||
return await condition_class.async_validate_config(hass, config)
|
||||
if platform is None and condition in ("numeric_state", "state"):
|
||||
validator = cast(
|
||||
Callable[[HomeAssistant, ConfigType], ConfigType],
|
||||
|
@ -173,18 +173,18 @@ class Trigger(abc.ABC):
|
||||
|
||||
@classmethod
|
||||
@abc.abstractmethod
|
||||
async def async_validate_trigger_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
|
||||
@abc.abstractmethod
|
||||
async def async_attach_trigger(
|
||||
async def async_attach(
|
||||
self,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
) -> CALLBACK_TYPE:
|
||||
"""Attach a trigger."""
|
||||
"""Attach the trigger."""
|
||||
|
||||
|
||||
class TriggerProtocol(Protocol):
|
||||
@ -390,7 +390,7 @@ async def async_validate_trigger_config(
|
||||
)
|
||||
if not (trigger := trigger_descriptors.get(relative_trigger_key)):
|
||||
raise vol.Invalid(f"Invalid trigger '{trigger_key}' specified")
|
||||
conf = await trigger.async_validate_trigger_config(hass, conf)
|
||||
conf = await trigger.async_validate_config(hass, conf)
|
||||
elif hasattr(platform, "async_validate_trigger_config"):
|
||||
conf = await platform.async_validate_trigger_config(hass, conf)
|
||||
else:
|
||||
@ -495,7 +495,7 @@ async def async_initialize_triggers(
|
||||
platform_domain, trigger_key
|
||||
)
|
||||
trigger = trigger_descriptors[relative_trigger_key](hass, conf)
|
||||
coro = trigger.async_attach_trigger(action_wrapper, info)
|
||||
coro = trigger.async_attach(action_wrapper, info)
|
||||
else:
|
||||
coro = platform.async_attach_trigger(hass, conf, action_wrapper, info)
|
||||
|
||||
|
@ -977,7 +977,7 @@ async def test_zwave_js_event_invalid_config_entry_id(
|
||||
async def test_invalid_trigger_configs(hass: HomeAssistant) -> None:
|
||||
"""Test invalid trigger configs."""
|
||||
with pytest.raises(vol.Invalid):
|
||||
await TRIGGERS["event"].async_validate_trigger_config(
|
||||
await TRIGGERS["event"].async_validate_config(
|
||||
hass,
|
||||
{
|
||||
"platform": f"{DOMAIN}.event",
|
||||
@ -988,7 +988,7 @@ async def test_invalid_trigger_configs(hass: HomeAssistant) -> None:
|
||||
)
|
||||
|
||||
with pytest.raises(vol.Invalid):
|
||||
await TRIGGERS["value_updated"].async_validate_trigger_config(
|
||||
await TRIGGERS["value_updated"].async_validate_config(
|
||||
hass,
|
||||
{
|
||||
"platform": f"{DOMAIN}.value_updated",
|
||||
@ -1026,7 +1026,7 @@ async def test_zwave_js_trigger_config_entry_unloaded(
|
||||
await hass.config_entries.async_unload(integration.entry_id)
|
||||
|
||||
# Test full validation for both events
|
||||
assert await TRIGGERS["value_updated"].async_validate_trigger_config(
|
||||
assert await TRIGGERS["value_updated"].async_validate_config(
|
||||
hass,
|
||||
{
|
||||
"platform": f"{DOMAIN}.value_updated",
|
||||
@ -1036,7 +1036,7 @@ async def test_zwave_js_trigger_config_entry_unloaded(
|
||||
},
|
||||
)
|
||||
|
||||
assert await TRIGGERS["event"].async_validate_trigger_config(
|
||||
assert await TRIGGERS["event"].async_validate_config(
|
||||
hass,
|
||||
{
|
||||
"platform": f"{DOMAIN}.event",
|
||||
|
@ -2089,7 +2089,7 @@ async def test_platform_multiple_conditions(hass: HomeAssistant) -> None:
|
||||
"""Initialize condition."""
|
||||
|
||||
@classmethod
|
||||
async def async_validate_condition_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
@ -2098,14 +2098,14 @@ async def test_platform_multiple_conditions(hass: HomeAssistant) -> None:
|
||||
class MockCondition1(MockCondition):
|
||||
"""Mock condition 1."""
|
||||
|
||||
async def async_condition_from_config(self) -> condition.ConditionCheckerType:
|
||||
async def async_get_checker(self) -> condition.ConditionCheckerType:
|
||||
"""Evaluate state based on configuration."""
|
||||
return lambda hass, vars: True
|
||||
|
||||
class MockCondition2(MockCondition):
|
||||
"""Mock condition 2."""
|
||||
|
||||
async def async_condition_from_config(self) -> condition.ConditionCheckerType:
|
||||
async def async_get_checker(self) -> condition.ConditionCheckerType:
|
||||
"""Evaluate state based on configuration."""
|
||||
return lambda hass, vars: False
|
||||
|
||||
|
@ -461,7 +461,7 @@ async def test_platform_multiple_triggers(hass: HomeAssistant) -> None:
|
||||
"""Initialize trigger."""
|
||||
|
||||
@classmethod
|
||||
async def async_validate_trigger_config(
|
||||
async def async_validate_config(
|
||||
cls, hass: HomeAssistant, config: ConfigType
|
||||
) -> ConfigType:
|
||||
"""Validate config."""
|
||||
@ -470,7 +470,7 @@ async def test_platform_multiple_triggers(hass: HomeAssistant) -> None:
|
||||
class MockTrigger1(MockTrigger):
|
||||
"""Mock trigger 1."""
|
||||
|
||||
async def async_attach_trigger(
|
||||
async def async_attach(
|
||||
self,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
@ -481,7 +481,7 @@ async def test_platform_multiple_triggers(hass: HomeAssistant) -> None:
|
||||
class MockTrigger2(MockTrigger):
|
||||
"""Mock trigger 2."""
|
||||
|
||||
async def async_attach_trigger(
|
||||
async def async_attach(
|
||||
self,
|
||||
action: TriggerActionType,
|
||||
trigger_info: TriggerInfo,
|
||||
|
Loading…
x
Reference in New Issue
Block a user