Improve ZHA routes vizualization (#26270)

This commit is contained in:
Petar Petrov 2025-07-23 15:48:47 +03:00 committed by GitHub
parent 20dab92ad8
commit d9bf605c3f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -290,7 +290,8 @@ export class ZHANetworkVisualizationPage extends LitElement {
}, },
symbolSize: (width / 4) * 6 + 3, // range 3-9 symbolSize: (width / 4) * 6 + 3, // range 3-9
// By default, all links should be ignored for force layout // 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); links.push(link);
existingLinks.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 // Except for the coordinator which can have multiple strong connections
devices.forEach((device) => { devices.forEach((device) => {
if (device.device_type === "Coordinator") { if (device.device_type === "Coordinator") {
@ -342,18 +343,21 @@ export class ZHANetworkVisualizationPage extends LitElement {
}); });
} else { } else {
// Find the link that corresponds to this strongest connection // Find the link that corresponds to this strongest connection
let strongestLink: NetworkLink | undefined; let bestLink: NetworkLink | undefined;
links.forEach((link) => { const alreadyHasBestLink = links.some((link) => {
if ( if (link.source === device.ieee || link.target === device.ieee) {
(link.source === device.ieee || link.target === device.ieee) && if (!link.ignoreForceLayout) {
link.value! > (strongestLink?.value ?? 0) return true;
) { }
strongestLink = link; if (link.value! > (bestLink?.value ?? -1)) {
bestLink = link;
}
} }
return false;
}); });
if (strongestLink) { if (!alreadyHasBestLink && bestLink) {
strongestLink.ignoreForceLayout = false; bestLink.ignoreForceLayout = false;
} }
} }
}); });