diff --git a/src/panels/config/integrations/integration-panels/zha/zha-network-visualization-page.ts b/src/panels/config/integrations/integration-panels/zha/zha-network-visualization-page.ts index dffe1d8c7f..657f8a8209 100644 --- a/src/panels/config/integrations/integration-panels/zha/zha-network-visualization-page.ts +++ b/src/panels/config/integrations/integration-panels/zha/zha-network-visualization-page.ts @@ -290,7 +290,8 @@ export class ZHANetworkVisualizationPage extends LitElement { }, symbolSize: (width / 4) * 6 + 3, // range 3-9 // By default, all links should be ignored for force layout - ignoreForceLayout: true, + // unless it's a route to the coordinator + ignoreForceLayout: route.dest_nwk !== "0x0000", }; links.push(link); existingLinks.push(link); @@ -331,7 +332,7 @@ export class ZHANetworkVisualizationPage extends LitElement { } }); - // Now set ignoreForceLayout to false for the strongest connection of each device + // Now set ignoreForceLayout to false for the best connection of each device // Except for the coordinator which can have multiple strong connections devices.forEach((device) => { if (device.device_type === "Coordinator") { @@ -342,18 +343,21 @@ export class ZHANetworkVisualizationPage extends LitElement { }); } else { // Find the link that corresponds to this strongest connection - let strongestLink: NetworkLink | undefined; - links.forEach((link) => { - if ( - (link.source === device.ieee || link.target === device.ieee) && - link.value! > (strongestLink?.value ?? 0) - ) { - strongestLink = link; + let bestLink: NetworkLink | undefined; + const alreadyHasBestLink = links.some((link) => { + if (link.source === device.ieee || link.target === device.ieee) { + if (!link.ignoreForceLayout) { + return true; + } + if (link.value! > (bestLink?.value ?? -1)) { + bestLink = link; + } } + return false; }); - if (strongestLink) { - strongestLink.ignoreForceLayout = false; + if (!alreadyHasBestLink && bestLink) { + bestLink.ignoreForceLayout = false; } } });