From 3c266183e1dc4a44623889f2ec7c792bbb11aefe Mon Sep 17 00:00:00 2001 From: Petro31 <35082313+Petro31@users.noreply.github.com> Date: Mon, 9 Feb 2026 01:54:40 -0500 Subject: [PATCH] Add new template entity framework to event platform (#162228) --- homeassistant/components/template/event.py | 52 ++++++---------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/homeassistant/components/template/event.py b/homeassistant/components/template/event.py index 98450499661..92c7f330ce0 100644 --- a/homeassistant/components/template/event.py +++ b/homeassistant/components/template/event.py @@ -124,14 +124,24 @@ class AbstractTemplateEvent(AbstractTemplateEntity, EventEntity): # This ensures that the __init__ on AbstractTemplateEntity is not called twice. def __init__(self, config: dict[str, Any]) -> None: # pylint: disable=super-init-not-called """Initialize the features.""" - self._event_type_template = config[CONF_EVENT_TYPE] - self._event_types_template = config[CONF_EVENT_TYPES] - self._attr_device_class = config.get(CONF_DEVICE_CLASS) self._event_type = None self._attr_event_types = [] + self.setup_template( + CONF_EVENT_TYPES, + "_attr_event_types", + None, + self._update_event_types, + ) + self.setup_template( + CONF_EVENT_TYPE, + "_event_type", + None, + self._update_event_type, + ) + @callback def _update_event_types(self, event_types: Any) -> None: """Update the event types from the template.""" @@ -179,25 +189,6 @@ class StateEventEntity(TemplateEntity, AbstractTemplateEvent): TemplateEntity.__init__(self, hass, config, unique_id) AbstractTemplateEvent.__init__(self, config) - @callback - def _async_setup_templates(self) -> None: - """Set up templates.""" - self.add_template_attribute( - "_attr_event_types", - self._event_types_template, - None, - self._update_event_types, - none_on_template_error=True, - ) - self.add_template_attribute( - "_event_type", - self._event_type_template, - None, - self._update_event_type, - none_on_template_error=True, - ) - super()._async_setup_templates() - class TriggerEventEntity(TriggerEntity, AbstractTemplateEvent, RestoreEntity): """Event entity based on trigger data.""" @@ -217,20 +208,3 @@ class TriggerEventEntity(TriggerEntity, AbstractTemplateEvent, RestoreEntity): """Initialize the entity.""" TriggerEntity.__init__(self, hass, coordinator, config) AbstractTemplateEvent.__init__(self, config) - - @callback - def _handle_coordinator_update(self) -> None: - """Handle update of the data.""" - self._process_data() - - if not self.available: - return - - for key, updater in ( - (CONF_EVENT_TYPES, self._update_event_types), - (CONF_EVENT_TYPE, self._update_event_type), - ): - updater(self._rendered[key]) - - self.async_set_context(self.coordinator.data["context"]) - self.async_write_ha_state()