diff --git a/homeassistant/components/zwave_js/triggers/event.py b/homeassistant/components/zwave_js/triggers/event.py index b8b8662c0b5..5cecf7096f2 100644 --- a/homeassistant/components/zwave_js/triggers/event.py +++ b/homeassistant/components/zwave_js/triggers/event.py @@ -256,11 +256,6 @@ async def async_attach_trigger( class EventTrigger(Trigger): """Z-Wave JS event trigger.""" - def __init__(self, hass: HomeAssistant, config: ConfigType) -> None: - """Initialize trigger.""" - self._config = config - self._hass = hass - @classmethod async def async_validate_trigger_config( cls, hass: HomeAssistant, config: ConfigType @@ -268,12 +263,13 @@ class EventTrigger(Trigger): """Validate config.""" return await async_validate_trigger_config(hass, config) + @classmethod async def async_attach_trigger( - self, + cls, + hass: HomeAssistant, + config: ConfigType, action: TriggerActionType, trigger_info: TriggerInfo, ) -> CALLBACK_TYPE: """Attach a trigger.""" - return await async_attach_trigger( - self._hass, self._config, action, trigger_info - ) + return await async_attach_trigger(hass, config, action, trigger_info) diff --git a/homeassistant/components/zwave_js/triggers/value_updated.py b/homeassistant/components/zwave_js/triggers/value_updated.py index a50053fa2db..ba856344a03 100644 --- a/homeassistant/components/zwave_js/triggers/value_updated.py +++ b/homeassistant/components/zwave_js/triggers/value_updated.py @@ -207,11 +207,6 @@ async def async_attach_trigger( class ValueUpdatedTrigger(Trigger): """Z-Wave JS value updated trigger.""" - def __init__(self, hass: HomeAssistant, config: ConfigType) -> None: - """Initialize trigger.""" - self._config = config - self._hass = hass - @classmethod async def async_validate_trigger_config( cls, hass: HomeAssistant, config: ConfigType @@ -219,12 +214,13 @@ class ValueUpdatedTrigger(Trigger): """Validate config.""" return await async_validate_trigger_config(hass, config) + @classmethod async def async_attach_trigger( - self, + cls, + hass: HomeAssistant, + config: ConfigType, action: TriggerActionType, trigger_info: TriggerInfo, ) -> CALLBACK_TYPE: """Attach a trigger.""" - return await async_attach_trigger( - self._hass, self._config, action, trigger_info - ) + return await async_attach_trigger(hass, config, action, trigger_info) diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index 62aebdf6fd7..73e3c4a0852 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -53,9 +53,6 @@ DATA_PLUGGABLE_ACTIONS: HassKey[defaultdict[tuple, PluggableActionsEntry]] = Has class Trigger(abc.ABC): """Trigger class.""" - def __init__(self, hass: HomeAssistant, config: ConfigType) -> None: - """Initialize trigger.""" - @classmethod @abc.abstractmethod async def async_validate_trigger_config( @@ -63,9 +60,12 @@ class Trigger(abc.ABC): ) -> ConfigType: """Validate config.""" + @classmethod @abc.abstractmethod async def async_attach_trigger( - self, + cls, + hass: HomeAssistant, + config: ConfigType, action: TriggerActionType, trigger_info: TriggerInfo, ) -> CALLBACK_TYPE: @@ -370,15 +370,17 @@ async def async_initialize_triggers( trigger_data=trigger_data, ) - action_wrapper = _trigger_action_wrapper(hass, action, conf) if hasattr(platform, "async_get_triggers"): trigger_descriptors = await platform.async_get_triggers(hass) - trigger = trigger_descriptors[conf[CONF_PLATFORM]](hass, conf) - coro = trigger.async_attach_trigger(action_wrapper, info) + attach_fn = trigger_descriptors[conf[CONF_PLATFORM]].async_attach_trigger else: - coro = platform.async_attach_trigger(hass, conf, action_wrapper, info) + attach_fn = platform.async_attach_trigger - triggers.append(create_eager_task(coro)) + triggers.append( + create_eager_task( + attach_fn(hass, conf, _trigger_action_wrapper(hass, action, conf), info) + ) + ) attach_results = await asyncio.gather(*triggers, return_exceptions=True) removes: list[Callable[[], None]] = []