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
// 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;
}
}
});