@@ -165,27 +165,36 @@ async def test_get_entities_by_device_class(self, mock_hass, mock_agent_config):
165165 if not HOMEASSISTANT_AVAILABLE :
166166 pytest .skip ("Home Assistant not available" )
167167
168- # Create mock states with device_class attributes
168+ # Create mock states with device_class attributes and last_changed
169169 temp_sensor = MagicMock ()
170170 temp_sensor .entity_id = "sensor.bedroom_temperature"
171171 temp_sensor .state = "22.5"
172+ temp_sensor .last_changed = None
172173 temp_sensor .attributes = {
173174 "device_class" : "temperature" ,
174175 "unit_of_measurement" : "°C" ,
176+ "friendly_name" : "Bedroom Temperature" ,
175177 }
176178
177179 humidity_sensor = MagicMock ()
178180 humidity_sensor .entity_id = "sensor.living_room_humidity"
179181 humidity_sensor .state = "55"
182+ humidity_sensor .last_changed = None
180183 humidity_sensor .attributes = {
181184 "device_class" : "humidity" ,
182185 "unit_of_measurement" : "%" ,
186+ "friendly_name" : "Living Room Humidity" ,
183187 }
184188
185189 other_sensor = MagicMock ()
186190 other_sensor .entity_id = "sensor.power_usage"
187191 other_sensor .state = "150"
188- other_sensor .attributes = {"device_class" : "power" , "unit_of_measurement" : "W" }
192+ other_sensor .last_changed = None
193+ other_sensor .attributes = {
194+ "device_class" : "power" ,
195+ "unit_of_measurement" : "W" ,
196+ "friendly_name" : "Power Usage" ,
197+ }
189198
190199 mock_hass .states .async_all .return_value = [
191200 temp_sensor ,
@@ -231,17 +240,26 @@ async def test_get_climate_related_entities(self, mock_hass, mock_agent_config):
231240 climate_entity = MagicMock ()
232241 climate_entity .entity_id = "climate.thermostat"
233242 climate_entity .state = "heat"
234- climate_entity .attributes = {}
243+ climate_entity .last_changed = None
244+ climate_entity .attributes = {"friendly_name" : "Thermostat" }
235245
236246 temp_sensor = MagicMock ()
237247 temp_sensor .entity_id = "sensor.bedroom_temperature"
238248 temp_sensor .state = "22.5"
239- temp_sensor .attributes = {"device_class" : "temperature" }
249+ temp_sensor .last_changed = None
250+ temp_sensor .attributes = {
251+ "device_class" : "temperature" ,
252+ "friendly_name" : "Bedroom Temperature" ,
253+ }
240254
241255 humidity_sensor = MagicMock ()
242256 humidity_sensor .entity_id = "sensor.living_room_humidity"
243257 humidity_sensor .state = "55"
244- humidity_sensor .attributes = {"device_class" : "humidity" }
258+ humidity_sensor .last_changed = None
259+ humidity_sensor .attributes = {
260+ "device_class" : "humidity" ,
261+ "friendly_name" : "Living Room Humidity" ,
262+ }
245263
246264 mock_hass .states .async_all .return_value = [
247265 climate_entity ,
@@ -281,17 +299,29 @@ async def test_get_climate_related_entities_sensors_only(
281299 temp_sensor1 = MagicMock ()
282300 temp_sensor1 .entity_id = "sensor.bedroom_temperature"
283301 temp_sensor1 .state = "22.5"
284- temp_sensor1 .attributes = {"device_class" : "temperature" }
302+ temp_sensor1 .last_changed = None
303+ temp_sensor1 .attributes = {
304+ "device_class" : "temperature" ,
305+ "friendly_name" : "Bedroom Temperature" ,
306+ }
285307
286308 temp_sensor2 = MagicMock ()
287309 temp_sensor2 .entity_id = "sensor.kitchen_temperature"
288310 temp_sensor2 .state = "23.1"
289- temp_sensor2 .attributes = {"device_class" : "temperature" }
311+ temp_sensor2 .last_changed = None
312+ temp_sensor2 .attributes = {
313+ "device_class" : "temperature" ,
314+ "friendly_name" : "Kitchen Temperature" ,
315+ }
290316
291317 humidity_sensor = MagicMock ()
292318 humidity_sensor .entity_id = "sensor.living_room_humidity"
293319 humidity_sensor .state = "55"
294- humidity_sensor .attributes = {"device_class" : "humidity" }
320+ humidity_sensor .last_changed = None
321+ humidity_sensor .attributes = {
322+ "device_class" : "humidity" ,
323+ "friendly_name" : "Living Room Humidity" ,
324+ }
295325
296326 mock_hass .states .async_all .return_value = [
297327 temp_sensor1 ,
@@ -332,7 +362,8 @@ async def test_climate_related_entities_deduplication(
332362 climate_entity = MagicMock ()
333363 climate_entity .entity_id = "climate.thermostat"
334364 climate_entity .state = "heat"
335- climate_entity .attributes = {}
365+ climate_entity .last_changed = None
366+ climate_entity .attributes = {"friendly_name" : "Thermostat" }
336367
337368 mock_hass .states .async_all .return_value = [climate_entity ]
338369 mock_hass .states .get = lambda entity_id : (
0 commit comments