diff --git a/homeassistant/components/device_automation/condition.py b/homeassistant/components/device_automation/condition.py index 5e2146a533c..426cc45a895 100644 --- a/homeassistant/components/device_automation/condition.py +++ b/homeassistant/components/device_automation/condition.py @@ -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 diff --git a/homeassistant/components/sun/condition.py b/homeassistant/components/sun/condition.py index f48505b4993..15f3ea90c73 100644 --- a/homeassistant/components/sun/condition.py +++ b/homeassistant/components/sun/condition.py @@ -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") diff --git a/homeassistant/components/zone/condition.py b/homeassistant/components/zone/condition.py index 0fb30eeda9c..b0fe30b26fd 100644 --- a/homeassistant/components/zone/condition.py +++ b/homeassistant/components/zone/condition.py @@ -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, []) diff --git a/homeassistant/components/zwave_js/triggers/event.py b/homeassistant/components/zwave_js/triggers/event.py index a9e37a8efa2..77449af3e36 100644 --- a/homeassistant/components/zwave_js/triggers/event.py +++ b/homeassistant/components/zwave_js/triggers/event.py @@ -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, diff --git a/homeassistant/components/zwave_js/triggers/value_updated.py b/homeassistant/components/zwave_js/triggers/value_updated.py index abd231ea568..f46592769cb 100644 --- a/homeassistant/components/zwave_js/triggers/value_updated.py +++ b/homeassistant/components/zwave_js/triggers/value_updated.py @@ -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, diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index 3c6120f523f..5aa39e73166 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -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], diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index e9c4a3d5b02..741fac3fcf7 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -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) diff --git a/tests/components/zwave_js/test_trigger.py b/tests/components/zwave_js/test_trigger.py index 4186f1a778e..7b00a9d0eef 100644 --- a/tests/components/zwave_js/test_trigger.py +++ b/tests/components/zwave_js/test_trigger.py @@ -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", diff --git a/tests/helpers/test_condition.py b/tests/helpers/test_condition.py index 86aab3cb681..94e71696270 100644 --- a/tests/helpers/test_condition.py +++ b/tests/helpers/test_condition.py @@ -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 diff --git a/tests/helpers/test_trigger.py b/tests/helpers/test_trigger.py index 13441065691..d5621a1ae61 100644 --- a/tests/helpers/test_trigger.py +++ b/tests/helpers/test_trigger.py @@ -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,