@@ -374,12 +374,16 @@ async def get_system_overview(
374374 entity_registry_task = self .client .send_websocket_message (
375375 {"type" : "config/entity_registry/list" }
376376 )
377+ device_registry_task = self .client .send_websocket_message (
378+ {"type" : "config/device_registry/list" }
379+ )
377380
378381 results = await asyncio .gather (
379382 entities_task ,
380383 services_task ,
381384 area_registry_task ,
382385 entity_registry_task ,
386+ device_registry_task ,
383387 return_exceptions = True ,
384388 )
385389
@@ -401,11 +405,26 @@ async def get_system_overview(
401405 elif isinstance (results [3 ], dict ) and results [3 ].get ("success" ):
402406 entity_registry = results [3 ].get ("result" , [])
403407
404- # Build entity_id -> area_id mapping from entity registry
408+ # Handle device registry result
409+ device_area_map : dict [str , str | None ] = {}
410+ if isinstance (results [4 ], Exception ):
411+ logger .debug (f"Could not fetch device registry: { results [4 ]} " )
412+ elif isinstance (results [4 ], dict ) and results [4 ].get ("success" ):
413+ for device in results [4 ].get ("result" , []):
414+ device_id = device .get ("id" , "" )
415+ if device_id :
416+ device_area_map [device_id ] = device .get ("area_id" )
417+
418+ # Build entity_id -> area_id mapping from entity + device registries
419+ # Priority: entity direct area_id > device area_id
405420 entity_area_map : dict [str , str | None ] = {}
406421 for entry in entity_registry :
407422 entity_id = entry .get ("entity_id" )
408423 area_id = entry .get ("area_id" )
424+ if not area_id :
425+ device_id = entry .get ("device_id" )
426+ if device_id :
427+ area_id = device_area_map .get (device_id )
409428 if entity_id :
410429 entity_area_map [entity_id ] = area_id
411430
@@ -417,9 +436,19 @@ async def get_system_overview(
417436 if include_entity_id is None :
418437 include_entity_id = detail_level == "full"
419438
439+ # Pre-populate area_stats to include empty areas
440+ area_stats : dict [str , dict [str , Any ]] = {}
441+ for area in area_registry :
442+ area_id = area .get ("area_id" , "" )
443+ if area_id :
444+ area_stats [area_id ] = {
445+ "name" : area .get ("name" , area_id ),
446+ "count" : 0 ,
447+ "domains" : {},
448+ }
449+
420450 # Analyze entities by domain
421451 domain_stats : dict [str , dict [str , Any ]] = {}
422- area_stats : dict [str , dict [str , Any ]] = {}
423452 device_types : dict [str , int ] = {}
424453
425454 for entity in entities :
@@ -454,11 +483,9 @@ async def get_system_overview(
454483
455484 domain_stats [domain ]["all_entities" ].append (entity_data )
456485
457- # Area analysis - use entity registry mapping, not state attributes
486+ # Area analysis - use entity + device registry mapping
458487 area_id = entity_area_map .get (entity_id )
459- if area_id :
460- if area_id not in area_stats :
461- area_stats [area_id ] = {"count" : 0 , "domains" : {}}
488+ if area_id and area_id in area_stats :
462489 area_stats [area_id ]["count" ] += 1
463490 if domain not in area_stats [area_id ]["domains" ]:
464491 area_stats [area_id ]["domains" ][domain ] = 0
0 commit comments