3434 group ,
3535 label_registry as lr ,
3636)
37+ from .deprecation import deprecated_class
3738from .event import async_track_state_change_event
3839from .typing import ConfigType
3940
@@ -53,8 +54,8 @@ def _has_match(ids: str | list[str] | None) -> TypeGuard[str | list[str]]:
5354 return ids not in (None , ENTITY_MATCH_NONE )
5455
5556
56- class TargetSelectorData :
57- """Class to hold data of target selector ."""
57+ class TargetSelection :
58+ """Class to represent target selection ."""
5859
5960 __slots__ = ("area_ids" , "device_ids" , "entity_ids" , "floor_ids" , "label_ids" )
6061
@@ -81,8 +82,8 @@ def __init__(self, config: ConfigType) -> None:
8182 )
8283
8384 @property
84- def has_any_selector (self ) -> bool :
85- """Determine if any selectors are present."""
85+ def has_any_target (self ) -> bool :
86+ """Determine if any target is present."""
8687 return bool (
8788 self .entity_ids
8889 or self .device_ids
@@ -92,6 +93,16 @@ def has_any_selector(self) -> bool:
9293 )
9394
9495
96+ @deprecated_class ("TargetSelection" , breaks_in_ha_version = "2026.12.0" )
97+ class TargetSelectorData (TargetSelection ):
98+ """Class to represent target selector data."""
99+
100+ @property
101+ def has_any_selector (self ) -> bool :
102+ """Determine if any selectors are present."""
103+ return super ().has_any_target
104+
105+
95106@dataclasses .dataclass (slots = True )
96107class SelectedEntities :
97108 """Class to hold the selected entities."""
@@ -135,49 +146,49 @@ def log_missing(self, missing_entities: set[str], logger: Logger) -> None:
135146
136147
137148def async_extract_referenced_entity_ids (
138- hass : HomeAssistant , selector_data : TargetSelectorData , expand_group : bool = True
149+ hass : HomeAssistant , target_selection : TargetSelection , expand_group : bool = True
139150) -> SelectedEntities :
140- """Extract referenced entity IDs from a target selector ."""
151+ """Extract referenced entity IDs from a target selection ."""
141152 selected = SelectedEntities ()
142153
143- if not selector_data . has_any_selector :
154+ if not target_selection . has_any_target :
144155 return selected
145156
146- entity_ids : set [str ] | list [str ] = selector_data .entity_ids
157+ entity_ids : set [str ] | list [str ] = target_selection .entity_ids
147158 if expand_group :
148159 entity_ids = group .expand_entity_ids (hass , entity_ids )
149160
150161 selected .referenced .update (entity_ids )
151162
152163 if (
153- not selector_data .device_ids
154- and not selector_data .area_ids
155- and not selector_data .floor_ids
156- and not selector_data .label_ids
164+ not target_selection .device_ids
165+ and not target_selection .area_ids
166+ and not target_selection .floor_ids
167+ and not target_selection .label_ids
157168 ):
158169 return selected
159170
160171 entities = er .async_get (hass ).entities
161172 dev_reg = dr .async_get (hass )
162173 area_reg = ar .async_get (hass )
163174
164- if selector_data .floor_ids :
175+ if target_selection .floor_ids :
165176 floor_reg = fr .async_get (hass )
166- for floor_id in selector_data .floor_ids :
177+ for floor_id in target_selection .floor_ids :
167178 if floor_id not in floor_reg .floors :
168179 selected .missing_floors .add (floor_id )
169180
170- for area_id in selector_data .area_ids :
181+ for area_id in target_selection .area_ids :
171182 if area_id not in area_reg .areas :
172183 selected .missing_areas .add (area_id )
173184
174- for device_id in selector_data .device_ids :
185+ for device_id in target_selection .device_ids :
175186 if device_id not in dev_reg .devices :
176187 selected .missing_devices .add (device_id )
177188
178- if selector_data .label_ids :
189+ if target_selection .label_ids :
179190 label_reg = lr .async_get (hass )
180- for label_id in selector_data .label_ids :
191+ for label_id in target_selection .label_ids :
181192 if label_id not in label_reg .labels :
182193 selected .missing_labels .add (label_id )
183194
@@ -192,15 +203,15 @@ def async_extract_referenced_entity_ids(
192203 selected .referenced_areas .add (area_entry .id )
193204
194205 # Find areas for targeted floors
195- if selector_data .floor_ids :
206+ if target_selection .floor_ids :
196207 selected .referenced_areas .update (
197208 area_entry .id
198- for floor_id in selector_data .floor_ids
209+ for floor_id in target_selection .floor_ids
199210 for area_entry in area_reg .areas .get_areas_for_floor (floor_id )
200211 )
201212
202- selected .referenced_areas .update (selector_data .area_ids )
203- selected .referenced_devices .update (selector_data .device_ids )
213+ selected .referenced_areas .update (target_selection .area_ids )
214+ selected .referenced_devices .update (target_selection .device_ids )
204215
205216 if not selected .referenced_areas and not selected .referenced_devices :
206217 return selected
@@ -263,13 +274,13 @@ class TargetStateChangeTracker:
263274 def __init__ (
264275 self ,
265276 hass : HomeAssistant ,
266- selector_data : TargetSelectorData ,
277+ target_selection : TargetSelection ,
267278 action : Callable [[TargetStateChangedData ], Any ],
268279 entity_filter : Callable [[set [str ]], set [str ]],
269280 ) -> None :
270281 """Initialize the state change tracker."""
271282 self ._hass = hass
272- self ._selector_data = selector_data
283+ self ._target_selection = target_selection
273284 self ._action = action
274285 self ._entity_filter = entity_filter
275286
@@ -285,7 +296,7 @@ def async_setup(self) -> Callable[[], None]:
285296 def _track_entities_state_change (self ) -> None :
286297 """Set up state change tracking for currently selected entities."""
287298 selected = async_extract_referenced_entity_ids (
288- self ._hass , self ._selector_data , expand_group = False
299+ self ._hass , self ._target_selection , expand_group = False
289300 )
290301
291302 tracked_entities = self ._entity_filter (
@@ -352,10 +363,10 @@ def async_track_target_selector_state_change_event(
352363 entity_filter : Callable [[set [str ]], set [str ]] = lambda x : x ,
353364) -> CALLBACK_TYPE :
354365 """Track state changes for entities referenced directly or indirectly in a target selector."""
355- selector_data = TargetSelectorData (target_selector_config )
356- if not selector_data . has_any_selector :
366+ target_selection = TargetSelection (target_selector_config )
367+ if not target_selection . has_any_target :
357368 raise HomeAssistantError (
358369 f"Target selector { target_selector_config } does not have any selectors defined"
359370 )
360- tracker = TargetStateChangeTracker (hass , selector_data , action , entity_filter )
371+ tracker = TargetStateChangeTracker (hass , target_selection , action , entity_filter )
361372 return tracker .async_setup ()
0 commit comments