2323 DOMAIN ,
2424 PANEL_ICON ,
2525 PANEL_TITLE ,
26- PANEL_URL ,
2726)
2827from .graph import GraphBuilder
2928
@@ -45,9 +44,7 @@ class EntityMapRuntimeData:
4544type EntityMapConfigEntry = ConfigEntry [EntityMapRuntimeData ]
4645
4746
48- async def async_setup_entry (
49- hass : HomeAssistant , entry : EntityMapConfigEntry
50- ) -> bool :
47+ async def async_setup_entry (hass : HomeAssistant , entry : EntityMapConfigEntry ) -> bool :
5148 """Set up EntityMap from a config entry."""
5249 from .panel import EntityMapPanelView
5350 from .services import async_register_services
@@ -87,6 +84,7 @@ async def async_setup_entry(
8784 # Schedule initial scan
8885 options = entry .options
8986 if options .get (CONF_SCAN_ON_STARTUP , DEFAULT_SCAN_ON_STARTUP ):
87+
9088 async def _startup_scan (_event : Event ) -> None :
9189 """Run initial scan after HA is fully started."""
9290 await builder .async_build ()
@@ -99,6 +97,7 @@ async def _startup_scan(_event: Event) -> None:
9997
10098 # Auto-refresh on registry changes
10199 if options .get (CONF_AUTO_REFRESH , DEFAULT_AUTO_REFRESH ):
100+
102101 @callback
103102 def _handle_registry_change (_event : Event ) -> None :
104103 """Schedule a rescan when registries change."""
@@ -108,14 +107,10 @@ def _handle_registry_change(_event: Event) -> None:
108107 "entity_registry_updated" ,
109108 "device_registry_updated" ,
110109 ):
111- unsub_listeners .append (
112- hass .bus .async_listen (event_type , _handle_registry_change )
113- )
110+ unsub_listeners .append (hass .bus .async_listen (event_type , _handle_registry_change ))
114111
115112 # Periodic reconciliation scan
116- scan_interval = options .get (
117- CONF_SCAN_INTERVAL_HOURS , DEFAULT_SCAN_INTERVAL_HOURS
118- )
113+ scan_interval = options .get (CONF_SCAN_INTERVAL_HOURS , DEFAULT_SCAN_INTERVAL_HOURS )
119114
120115 async def _periodic_scan (_now : Any ) -> None :
121116 """Periodic reconciliation scan."""
@@ -135,16 +130,12 @@ async def _periodic_scan(_now: Any) -> None:
135130 return True
136131
137132
138- async def _async_update_options (
139- hass : HomeAssistant , entry : EntityMapConfigEntry
140- ) -> None :
133+ async def _async_update_options (hass : HomeAssistant , entry : EntityMapConfigEntry ) -> None :
141134 """Handle options update — reload the integration."""
142135 await hass .config_entries .async_reload (entry .entry_id )
143136
144137
145- async def async_unload_entry (
146- hass : HomeAssistant , entry : EntityMapConfigEntry
147- ) -> bool :
138+ async def async_unload_entry (hass : HomeAssistant , entry : EntityMapConfigEntry ) -> bool :
148139 """Unload a config entry."""
149140 from homeassistant .components import frontend
150141
@@ -189,9 +180,7 @@ async def _async_register_panel(hass: HomeAssistant) -> None:
189180 )
190181
191182
192- async def _async_create_repair_issues (
193- hass : HomeAssistant , builder : GraphBuilder
194- ) -> None :
183+ async def _async_create_repair_issues (hass : HomeAssistant , builder : GraphBuilder ) -> None :
195184 """Create repair issues for critical fragility findings."""
196185 from homeassistant .helpers import issue_registry as ir
197186
@@ -202,9 +191,7 @@ async def _async_create_repair_issues(
202191
203192 # Count device_id references
204193 device_id_count = sum (
205- 1
206- for f in findings
207- if f .fragility_type == FragilityType .DEVICE_ID_REFERENCE
194+ 1 for f in findings if f .fragility_type == FragilityType .DEVICE_ID_REFERENCE
208195 )
209196 if device_id_count > 0 :
210197 ir .async_create_issue (
@@ -218,11 +205,7 @@ async def _async_create_repair_issues(
218205 )
219206
220207 # Missing entity references
221- missing_refs = [
222- f
223- for f in findings
224- if f .fragility_type == FragilityType .MISSING_ENTITY
225- ]
208+ missing_refs = [f for f in findings if f .fragility_type == FragilityType .MISSING_ENTITY ]
226209 for finding in missing_refs [:5 ]: # Limit to 5 repair issues
227210 related = finding .related_node_ids [0 ] if finding .related_node_ids else "unknown"
228211 ir .async_create_issue (
@@ -256,9 +239,7 @@ def _register_websocket_commands(hass: HomeAssistant) -> None:
256239 from .analysis import analyze_impact
257240 from .fragility import detect_fragility
258241
259- @websocket_api .websocket_command (
260- {vol .Required ("type" ): "entitymap/graph" }
261- )
242+ @websocket_api .websocket_command ({vol .Required ("type" ): "entitymap/graph" })
262243 @websocket_api .async_response
263244 async def ws_get_graph (
264245 hass : HomeAssistant ,
@@ -318,9 +299,7 @@ async def ws_get_neighborhood(
318299 {"nodes" : nodes , "edges" : [e .as_dict () for e in edges ]},
319300 )
320301
321- @websocket_api .websocket_command (
322- {vol .Required ("type" ): "entitymap/scan" }
323- )
302+ @websocket_api .websocket_command ({vol .Required ("type" ): "entitymap/scan" })
324303 @websocket_api .async_response
325304 async def ws_scan (
326305 hass : HomeAssistant ,
@@ -338,9 +317,7 @@ async def ws_scan(
338317 {"node_count" : graph .node_count , "edge_count" : graph .edge_count },
339318 )
340319
341- @websocket_api .websocket_command (
342- {vol .Required ("type" ): "entitymap/findings" }
343- )
320+ @websocket_api .websocket_command ({vol .Required ("type" ): "entitymap/findings" })
344321 @websocket_api .async_response
345322 async def ws_get_findings (
346323 hass : HomeAssistant ,
@@ -378,17 +355,13 @@ async def ws_get_migration(
378355 if not builder :
379356 connection .send_error (msg ["id" ], "not_loaded" , "EntityMap not loaded" )
380357 return
381- suggestions = get_migration_report (
382- builder .graph , msg ["node_id" ], msg .get ("target_node_id" )
383- )
358+ suggestions = get_migration_report (builder .graph , msg ["node_id" ], msg .get ("target_node_id" ))
384359 connection .send_result (
385360 msg ["id" ],
386361 {"suggestions" : [s .as_dict () for s in suggestions ]},
387362 )
388363
389- @websocket_api .websocket_command (
390- {vol .Required ("type" ): "entitymap/hierarchy" }
391- )
364+ @websocket_api .websocket_command ({vol .Required ("type" ): "entitymap/hierarchy" })
392365 @websocket_api .async_response
393366 async def ws_get_hierarchy (
394367 hass : HomeAssistant ,
@@ -418,7 +391,8 @@ def _get_builder(hass: HomeAssistant) -> GraphBuilder | None:
418391 return None
419392 entry = entries [0 ]
420393 if hasattr (entry , "runtime_data" ) and entry .runtime_data :
421- return entry .runtime_data .builder
394+ builder : GraphBuilder = entry .runtime_data .builder
395+ return builder
422396 return None
423397
424398
@@ -502,8 +476,10 @@ def _build_hierarchy(graph: Any) -> dict[str, Any]:
502476 area ["entities" ] = entities_by_area .get (area_id , [])
503477 # Counts
504478 area ["device_count" ] = len (area ["devices" ])
505- area ["entity_count" ] = area ["device_count" ] + len (area ["entities" ]) + sum (
506- len (d ["entities" ]) for d in area ["devices" ]
479+ area ["entity_count" ] = (
480+ area ["device_count" ]
481+ + len (area ["entities" ])
482+ + sum (len (d ["entities" ]) for d in area ["devices" ])
507483 )
508484 result_areas .append (area )
509485
0 commit comments