2929from tests .common import MockConfigEntry , mock_device_registry
3030
3131
32- async def target_entities (hass : HomeAssistant , domain : str ) -> list [str ]:
33- """Create multiple entities associated with different targets."""
32+ async def target_entities (
33+ hass : HomeAssistant , domain : str
34+ ) -> tuple [list [str ], list [str ]]:
35+ """Create multiple entities associated with different targets.
36+
37+ Returns a dict with the following keys:
38+ - included: List of entity_ids meant to be targeted.
39+ - excluded: List of entity_ids not meant to be targeted.
40+ """
3441 await async_setup_component (hass , domain , {})
3542
3643 config_entry = MockConfigEntry (domain = "test" )
@@ -55,40 +62,71 @@ async def target_entities(hass: HomeAssistant, domain: str) -> list[str]:
5562 mock_device_registry (hass , {device .id : device })
5663
5764 entity_reg = er .async_get (hass )
58- # Entity associated with area
65+ # Entities associated with area
5966 entity_area = entity_reg .async_get_or_create (
6067 domain = domain ,
6168 platform = "test" ,
6269 unique_id = f"{ domain } _area" ,
6370 suggested_object_id = f"area_{ domain } " ,
6471 )
6572 entity_reg .async_update_entity (entity_area .entity_id , area_id = area .id )
73+ entity_area_excluded = entity_reg .async_get_or_create (
74+ domain = domain ,
75+ platform = "test" ,
76+ unique_id = f"{ domain } _area_excluded" ,
77+ suggested_object_id = f"area_{ domain } _excluded" ,
78+ )
79+ entity_reg .async_update_entity (entity_area_excluded .entity_id , area_id = area .id )
6680
67- # Entity associated with device
81+ # Entities associated with device
6882 entity_reg .async_get_or_create (
6983 domain = domain ,
7084 platform = "test" ,
7185 unique_id = f"{ domain } _device" ,
7286 suggested_object_id = f"device_{ domain } " ,
7387 device_id = device .id ,
7488 )
89+ entity_reg .async_get_or_create (
90+ domain = domain ,
91+ platform = "test" ,
92+ unique_id = f"{ domain } _device_excluded" ,
93+ suggested_object_id = f"device_{ domain } _excluded" ,
94+ device_id = device .id ,
95+ )
7596
76- # Entity associated with label
97+ # Entities associated with label
7798 entity_label = entity_reg .async_get_or_create (
7899 domain = domain ,
79100 platform = "test" ,
80101 unique_id = f"{ domain } _label" ,
81102 suggested_object_id = f"label_{ domain } " ,
82103 )
83104 entity_reg .async_update_entity (entity_label .entity_id , labels = {label .label_id })
105+ entity_label_excluded = entity_reg .async_get_or_create (
106+ domain = domain ,
107+ platform = "test" ,
108+ unique_id = f"{ domain } _label_excluded" ,
109+ suggested_object_id = f"label_{ domain } _excluded" ,
110+ )
111+ entity_reg .async_update_entity (
112+ entity_label_excluded .entity_id , labels = {label .label_id }
113+ )
84114
85115 # Return all available entities
86- return [
87- f"{ domain } .standalone_{ domain } " ,
88- f"{ domain } .label_{ domain } " ,
89- f"{ domain } .area_{ domain } " ,
90- f"{ domain } .device_{ domain } " ,
91- ]
116+ return {
117+ "included" : [
118+ f"{ domain } .standalone_{ domain } " ,
119+ f"{ domain } .label_{ domain } " ,
120+ f"{ domain } .area_{ domain } " ,
121+ f"{ domain } .device_{ domain } " ,
122+ ],
123+ "excluded" : [
124+ f"{ domain } .standalone_{ domain } _excluded" ,
125+ f"{ domain } .label_{ domain } _excluded" ,
126+ f"{ domain } .area_{ domain } _excluded" ,
127+ f"{ domain } .device_{ domain } _excluded" ,
128+ ],
129+ }
92130
93131
94132def parametrize_target_entities (domain : str ) -> list [tuple [dict , str , int ]]:
@@ -112,11 +150,18 @@ def parametrize_target_entities(domain: str) -> list[tuple[dict, str, int]]:
112150 ]
113151
114152
115- class StateDescription (TypedDict ):
153+ class _StateDescription (TypedDict ):
116154 """Test state and expected service call count."""
117155
118156 state : str | None
119157 attributes : dict
158+
159+
160+ class StateDescription (TypedDict ):
161+ """Test state and expected service call count."""
162+
163+ included : _StateDescription
164+ excluded : _StateDescription
120165 count : int
121166
122167
@@ -147,10 +192,26 @@ def state_with_attributes(
147192 ) -> dict :
148193 """Return (state, attributes) dict."""
149194 if isinstance (state , str ) or state is None :
150- return {"state" : state , "attributes" : additional_attributes , "count" : count }
195+ return {
196+ "included" : {
197+ "state" : state ,
198+ "attributes" : additional_attributes ,
199+ },
200+ "excluded" : {
201+ "state" : state ,
202+ "attributes" : {},
203+ },
204+ "count" : count ,
205+ }
151206 return {
152- "state" : state [0 ],
153- "attributes" : state [1 ] | additional_attributes ,
207+ "included" : {
208+ "state" : state [0 ],
209+ "attributes" : state [1 ] | additional_attributes ,
210+ },
211+ "excluded" : {
212+ "state" : state [0 ],
213+ "attributes" : state [1 ],
214+ },
154215 "count" : count ,
155216 }
156217
0 commit comments