1 """Platform allowing several event entities to be grouped into one event."""
3 from __future__
import annotations
8 import voluptuous
as vol
13 DOMAIN
as EVENT_DOMAIN,
14 PLATFORM_SCHEMA
as EVENT_PLATFORM_SCHEMA,
34 from .entity
import GroupEntity
36 DEFAULT_NAME =
"Event group"
41 PLATFORM_SCHEMA = EVENT_PLATFORM_SCHEMA.extend(
43 vol.Required(CONF_ENTITIES): cv.entities_domain(EVENT_DOMAIN),
44 vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
45 vol.Optional(CONF_UNIQUE_ID): cv.string,
53 async_add_entities: AddEntitiesCallback,
54 __: DiscoveryInfoType |
None =
None,
56 """Set up the event group platform."""
60 config.get(CONF_UNIQUE_ID),
62 config[CONF_ENTITIES],
70 config_entry: ConfigEntry,
71 async_add_entities: AddEntitiesCallback,
73 """Initialize event group config entry."""
74 registry = er.async_get(hass)
75 entities = er.async_validate_entity_ids(
76 registry, config_entry.options[CONF_ENTITIES]
81 config_entry.entry_id,
91 hass: HomeAssistant, name: str, validated_config: dict[str, Any]
93 """Create a preview sensor."""
97 validated_config[CONF_ENTITIES],
102 """Representation of an event group."""
104 _attr_available =
False
105 _attr_should_poll =
False
109 unique_id: str |
None,
111 entity_ids: list[str],
113 """Initialize an event group."""
121 """Register callbacks."""
124 def async_state_changed_listener(
125 event: Event[EventStateChangedData],
127 """Handle child updates."""
128 if not self.
hasshass.is_running:
139 (old_state := event.data[
"old_state"])
140 and old_state.state
not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
141 and (new_state := event.data[
"new_state"])
142 and new_state.state
not in (STATE_UNAVAILABLE, STATE_UNKNOWN)
143 and (event_type := new_state.attributes.get(ATTR_EVENT_TYPE))
145 event_attributes = new_state.attributes.copy()
149 del event_attributes[ATTR_EVENT_TYPE]
150 del event_attributes[ATTR_EVENT_TYPES]
151 event_attributes.pop(ATTR_DEVICE_CLASS,
None)
152 event_attributes.pop(ATTR_FRIENDLY_NAME,
None)
161 self.
hasshass, self.
_entity_ids_entity_ids, async_state_changed_listener
169 """Query all members and determine the event group properties."""
173 if (state := self.
hasshass.states.get(entity_id))
is not None
184 itertools.chain.from_iterable(
185 state.attributes.get(ATTR_EVENT_TYPES, [])
for state
in states
None _trigger_event(self, str event_type, dict[str, Any]|None event_attributes=None)
None async_update_group_state(self)
None __init__(self, str|None unique_id, str name, list[str] entity_ids)
_attr_extra_state_attributes
None async_update_group_state(self)
None async_added_to_hass(self)
None async_write_ha_state(self)
None async_on_remove(self, CALLBACK_TYPE func)
None async_set_context(self, Context context)
None async_setup_platform(HomeAssistant _, ConfigType config, AddEntitiesCallback async_add_entities, DiscoveryInfoType|None __=None)
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
EventGroup async_create_preview_event(HomeAssistant hass, str name, dict[str, Any] validated_config)
CALLBACK_TYPE async_track_state_change_event(HomeAssistant hass, str|Iterable[str] entity_ids, Callable[[Event[EventStateChangedData]], Any] action, HassJobType|None job_type=None)