@matter-server/dashboard 0.3.3 → 0.3.5-alpha.0-20260203-66f5d74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +76 -0
- package/dist/esm/components/dialogs/binding/node-binding-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/binding/node-binding-dialog.js +44 -17
- package/dist/esm/components/dialogs/binding/node-binding-dialog.js.map +1 -1
- package/dist/esm/entrypoint/main.js +1 -1
- package/dist/esm/entrypoint/main.js.map +1 -1
- package/dist/esm/pages/components/node-details.js +1 -1
- package/dist/esm/pages/components/node-details.js.map +1 -1
- package/dist/esm/pages/matter-cluster-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-cluster-view.js +9 -4
- package/dist/esm/pages/matter-cluster-view.js.map +1 -1
- package/dist/esm/pages/matter-endpoint-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-endpoint-view.js +8 -2
- package/dist/esm/pages/matter-endpoint-view.js.map +1 -1
- package/dist/esm/pages/matter-network-view.d.ts +5 -0
- package/dist/esm/pages/matter-network-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-network-view.js +96 -13
- package/dist/esm/pages/matter-network-view.js.map +1 -1
- package/dist/esm/pages/matter-node-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-node-view.js +17 -3
- package/dist/esm/pages/matter-node-view.js.map +1 -1
- package/dist/esm/pages/network/base-network-graph.d.ts +34 -0
- package/dist/esm/pages/network/base-network-graph.d.ts.map +1 -1
- package/dist/esm/pages/network/base-network-graph.js +116 -25
- package/dist/esm/pages/network/base-network-graph.js.map +1 -1
- package/dist/esm/pages/network/device-icons.js +1 -1
- package/dist/esm/pages/network/network-details.d.ts +31 -1
- package/dist/esm/pages/network/network-details.d.ts.map +1 -1
- package/dist/esm/pages/network/network-details.js +233 -15
- package/dist/esm/pages/network/network-details.js.map +1 -1
- package/dist/esm/pages/network/network-types.d.ts +6 -0
- package/dist/esm/pages/network/network-types.d.ts.map +1 -1
- package/dist/esm/pages/network/network-utils.d.ts +26 -0
- package/dist/esm/pages/network/network-utils.d.ts.map +1 -1
- package/dist/esm/pages/network/network-utils.js +71 -3
- package/dist/esm/pages/network/network-utils.js.map +1 -1
- package/dist/esm/pages/network/thread-graph.d.ts.map +1 -1
- package/dist/esm/pages/network/thread-graph.js +5 -2
- package/dist/esm/pages/network/thread-graph.js.map +1 -1
- package/dist/esm/pages/network/update-connections-dialog.d.ts +55 -0
- package/dist/esm/pages/network/update-connections-dialog.d.ts.map +1 -0
- package/dist/esm/pages/network/update-connections-dialog.js +284 -0
- package/dist/esm/pages/network/update-connections-dialog.js.map +6 -0
- package/dist/esm/pages/network/wifi-graph.d.ts.map +1 -1
- package/dist/esm/pages/network/wifi-graph.js +5 -3
- package/dist/esm/pages/network/wifi-graph.js.map +1 -1
- package/dist/esm/util/format_hex.d.ts +18 -0
- package/dist/esm/util/format_hex.d.ts.map +1 -1
- package/dist/esm/util/format_hex.js +21 -1
- package/dist/esm/util/format_hex.js.map +1 -1
- package/dist/esm/util/matter-status.d.ts +49 -0
- package/dist/esm/util/matter-status.d.ts.map +1 -0
- package/dist/esm/util/matter-status.js +110 -0
- package/dist/esm/util/matter-status.js.map +6 -0
- package/dist/web/js/{commission-node-dialog-B1_khzZb.js → commission-node-dialog-DBugVQOl.js} +5 -5
- package/dist/web/js/{commission-node-existing-RpdajrwF.js → commission-node-existing-ts2MN2bQ.js} +2 -2
- package/dist/web/js/{commission-node-thread-5f2itkTG.js → commission-node-thread-CixfNuM3.js} +2 -2
- package/dist/web/js/{commission-node-wifi-DZ_pWqsa.js → commission-node-wifi-CWC30EYn.js} +2 -2
- package/dist/web/js/{dialog-box-DEUxM4B1.js → dialog-box-SeMuFiWx.js} +2 -2
- package/dist/web/js/{fire_event-BczBMT8E.js → fire_event-B63oGTcK.js} +1 -1
- package/dist/web/js/{log-level-dialog-Cr3PfX1X.js → log-level-dialog-J0gFiLLM.js} +2 -2
- package/dist/web/js/main.js +2 -2
- package/dist/web/js/{matter-dashboard-app-BuCe_Jxf.js → matter-dashboard-app-D7YWrgXj.js} +2041 -246
- package/dist/web/js/{node-binding-dialog-DMiHNDLA.js → node-binding-dialog-DSBwIJcQ.js} +147 -19
- package/dist/web/js/prevent_default-D-ohDGsN.js +8 -0
- package/package.json +4 -4
- package/src/components/dialogs/binding/node-binding-dialog.ts +45 -21
- package/src/entrypoint/main.ts +2 -0
- package/src/pages/components/node-details.ts +1 -1
- package/src/pages/matter-cluster-view.ts +11 -4
- package/src/pages/matter-endpoint-view.ts +10 -3
- package/src/pages/matter-network-view.ts +102 -13
- package/src/pages/matter-node-view.ts +19 -4
- package/src/pages/network/base-network-graph.ts +147 -33
- package/src/pages/network/device-icons.ts +1 -1
- package/src/pages/network/network-details.ts +281 -16
- package/src/pages/network/network-types.ts +6 -0
- package/src/pages/network/network-utils.ts +109 -0
- package/src/pages/network/thread-graph.ts +7 -1
- package/src/pages/network/update-connections-dialog.ts +327 -0
- package/src/pages/network/wifi-graph.ts +4 -3
- package/src/util/format_hex.ts +39 -0
- package/src/util/matter-status.ts +165 -0
- package/dist/web/js/prevent_default-D4FX_PIh.js +0 -774
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025-2026 Open Home Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import "@material/web/button/filled-button";
|
|
8
|
+
import "@material/web/button/text-button";
|
|
9
|
+
import "@material/web/checkbox/checkbox";
|
|
10
|
+
import "@material/web/dialog/dialog";
|
|
11
|
+
import type { MatterClient, MatterNode } from "@matter-server/ws-client";
|
|
12
|
+
import { mdiLoading } from "@mdi/js";
|
|
13
|
+
import { LitElement, css, html, nothing, svg } from "lit";
|
|
14
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
15
|
+
import { getNetworkType } from "./network-utils.js";
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
interface HTMLElementTagNameMap {
|
|
19
|
+
"update-connections-dialog": UpdateConnectionsDialog;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Thread network attributes to read */
|
|
24
|
+
const THREAD_ATTRIBUTE_PATHS = ["0/53/7", "0/53/8", "0/51/0"]; // NeighborTable, RouteTable, NetworkInterfaces
|
|
25
|
+
|
|
26
|
+
/** WiFi network attributes to read */
|
|
27
|
+
const WIFI_ATTRIBUTE_PATHS = ["0/54/0", "0/54/3", "0/54/4"]; // BSSID, Channel, RSSI
|
|
28
|
+
|
|
29
|
+
@customElement("update-connections-dialog")
|
|
30
|
+
export class UpdateConnectionsDialog extends LitElement {
|
|
31
|
+
@property({ type: Object })
|
|
32
|
+
public client!: MatterClient;
|
|
33
|
+
|
|
34
|
+
@property({ type: Object })
|
|
35
|
+
public nodes: Record<string, MatterNode> = {};
|
|
36
|
+
|
|
37
|
+
@property({ type: String })
|
|
38
|
+
public selectedNodeType: "online" | "offline" | "unknown" = "online";
|
|
39
|
+
|
|
40
|
+
@property({ type: String })
|
|
41
|
+
public selectedNodeName: string = "";
|
|
42
|
+
|
|
43
|
+
@property()
|
|
44
|
+
public selectedNodeId: number | string | null = null;
|
|
45
|
+
|
|
46
|
+
@property({ type: Array })
|
|
47
|
+
public onlineNeighborIds: string[] = [];
|
|
48
|
+
|
|
49
|
+
@state()
|
|
50
|
+
private _includeNeighbors: boolean = false;
|
|
51
|
+
|
|
52
|
+
@state()
|
|
53
|
+
private _isUpdating: boolean = false;
|
|
54
|
+
|
|
55
|
+
/** Timeout ID for auto-close */
|
|
56
|
+
private _timeoutId: ReturnType<typeof setTimeout> | null = null;
|
|
57
|
+
|
|
58
|
+
/** Track if we've already dispatched close event to prevent double-firing */
|
|
59
|
+
private _hasClosedEvent: boolean = false;
|
|
60
|
+
|
|
61
|
+
override firstUpdated(): void {
|
|
62
|
+
// Open dialog when component is first rendered
|
|
63
|
+
const dialog = this.shadowRoot?.querySelector("md-dialog") as HTMLElement & { show: () => void };
|
|
64
|
+
dialog?.show();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
override disconnectedCallback(): void {
|
|
68
|
+
super.disconnectedCallback();
|
|
69
|
+
// Clean up timeout when component is removed
|
|
70
|
+
if (this._timeoutId) {
|
|
71
|
+
clearTimeout(this._timeoutId);
|
|
72
|
+
this._timeoutId = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Get the number of nodes that will be updated.
|
|
78
|
+
*/
|
|
79
|
+
private get _updateCount(): number {
|
|
80
|
+
if (this.selectedNodeType === "online") {
|
|
81
|
+
return this._includeNeighbors ? 1 + this.onlineNeighborIds.length : 1;
|
|
82
|
+
}
|
|
83
|
+
// offline and unknown: update neighbors only
|
|
84
|
+
return this.onlineNeighborIds.length;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Get the attribute paths to read for a node based on its network type.
|
|
89
|
+
*/
|
|
90
|
+
private _getAttributePathsForNode(nodeId: string): string[] {
|
|
91
|
+
const node = this.nodes[nodeId];
|
|
92
|
+
if (!node) return [];
|
|
93
|
+
|
|
94
|
+
const networkType = getNetworkType(node);
|
|
95
|
+
|
|
96
|
+
if (networkType === "thread") {
|
|
97
|
+
return THREAD_ATTRIBUTE_PATHS;
|
|
98
|
+
}
|
|
99
|
+
if (networkType === "wifi") {
|
|
100
|
+
return WIFI_ATTRIBUTE_PATHS;
|
|
101
|
+
}
|
|
102
|
+
// Ethernet and unknown have no dynamic network data
|
|
103
|
+
return [];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Get the list of node IDs to update based on current state.
|
|
108
|
+
*/
|
|
109
|
+
private _getNodeIdsToUpdate(): string[] {
|
|
110
|
+
if (this.selectedNodeType === "online") {
|
|
111
|
+
const nodeIds = [String(this.selectedNodeId)];
|
|
112
|
+
if (this._includeNeighbors) {
|
|
113
|
+
nodeIds.push(...this.onlineNeighborIds);
|
|
114
|
+
}
|
|
115
|
+
return nodeIds;
|
|
116
|
+
}
|
|
117
|
+
// offline and unknown: update neighbors only
|
|
118
|
+
return this.onlineNeighborIds;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private async _executeUpdate(): Promise<void> {
|
|
122
|
+
if (this._isUpdating || this._updateCount === 0) return;
|
|
123
|
+
|
|
124
|
+
this._isUpdating = true;
|
|
125
|
+
|
|
126
|
+
// Set up 30s timeout to auto-close dialog
|
|
127
|
+
this._timeoutId = setTimeout(() => {
|
|
128
|
+
console.warn("Update connections timed out after 30s");
|
|
129
|
+
this._closeDialog();
|
|
130
|
+
}, 30000);
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const nodeIds = this._getNodeIdsToUpdate();
|
|
134
|
+
|
|
135
|
+
// Build promises for all node updates
|
|
136
|
+
const updatePromises = nodeIds.map(async nodeIdStr => {
|
|
137
|
+
const node = this.nodes[nodeIdStr];
|
|
138
|
+
if (!node) return;
|
|
139
|
+
|
|
140
|
+
const paths = this._getAttributePathsForNode(nodeIdStr);
|
|
141
|
+
if (paths.length === 0) return;
|
|
142
|
+
|
|
143
|
+
// Use the actual node_id from the node object (number | bigint)
|
|
144
|
+
await this.client.readAttribute(node.node_id, paths);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Wait for all to complete (results come via events, we just need completion)
|
|
148
|
+
await Promise.all(updatePromises);
|
|
149
|
+
|
|
150
|
+
// Close dialog on success
|
|
151
|
+
this._closeDialog();
|
|
152
|
+
} catch (error) {
|
|
153
|
+
console.error("Failed to update connections:", error);
|
|
154
|
+
// Close dialog on error too - don't leave user stuck
|
|
155
|
+
this._closeDialog();
|
|
156
|
+
} finally {
|
|
157
|
+
// Clear timeout if we finished before 30s
|
|
158
|
+
if (this._timeoutId) {
|
|
159
|
+
clearTimeout(this._timeoutId);
|
|
160
|
+
this._timeoutId = null;
|
|
161
|
+
}
|
|
162
|
+
this._isUpdating = false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private _closeDialog(): void {
|
|
167
|
+
// Prevent double-firing the close event
|
|
168
|
+
if (this._hasClosedEvent) return;
|
|
169
|
+
this._hasClosedEvent = true;
|
|
170
|
+
|
|
171
|
+
const dialog = this.shadowRoot?.querySelector("md-dialog") as HTMLElement & { close: () => void };
|
|
172
|
+
dialog?.close();
|
|
173
|
+
// Use 'dialog-closed' to avoid conflicting with network-details 'close' event
|
|
174
|
+
this.dispatchEvent(new CustomEvent("dialog-closed", { bubbles: true, composed: true }));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Handle native dialog closed event (ESC key, backdrop click, etc.) */
|
|
178
|
+
private _handleDialogClosed(): void {
|
|
179
|
+
this._closeDialog();
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
private _handleCheckboxChange(e: Event): void {
|
|
183
|
+
const checkbox = e.target as HTMLInputElement;
|
|
184
|
+
this._includeNeighbors = checkbox.checked;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
private _renderOnlineContent(): unknown {
|
|
188
|
+
return html`
|
|
189
|
+
<p>Refresh network information for "<strong>${this.selectedNodeName}</strong>".</p>
|
|
190
|
+
${this.onlineNeighborIds.length > 0
|
|
191
|
+
? html`
|
|
192
|
+
<label class="checkbox-row">
|
|
193
|
+
<md-checkbox
|
|
194
|
+
?checked=${this._includeNeighbors}
|
|
195
|
+
@change=${this._handleCheckboxChange}
|
|
196
|
+
?disabled=${this._isUpdating}
|
|
197
|
+
></md-checkbox>
|
|
198
|
+
<span
|
|
199
|
+
>Include ${this.onlineNeighborIds.length} connected online
|
|
200
|
+
neighbor${this.onlineNeighborIds.length !== 1 ? "s" : ""}</span
|
|
201
|
+
>
|
|
202
|
+
</label>
|
|
203
|
+
`
|
|
204
|
+
: nothing}
|
|
205
|
+
`;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private _renderOfflineContent(): unknown {
|
|
209
|
+
return html`
|
|
210
|
+
<p>"<strong>${this.selectedNodeName}</strong>" appears to be offline.</p>
|
|
211
|
+
${this.onlineNeighborIds.length > 0
|
|
212
|
+
? html`
|
|
213
|
+
<p>
|
|
214
|
+
Update network data from its ${this.onlineNeighborIds.length} online
|
|
215
|
+
neighbor${this.onlineNeighborIds.length !== 1 ? "s" : ""} to refresh connection info.
|
|
216
|
+
</p>
|
|
217
|
+
`
|
|
218
|
+
: html` <p>No online neighbors available to update.</p> `}
|
|
219
|
+
`;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private _renderUnknownContent(): unknown {
|
|
223
|
+
return html`
|
|
224
|
+
<p>This device is not commissioned to this fabric and cannot be queried directly.</p>
|
|
225
|
+
${this.onlineNeighborIds.length > 0
|
|
226
|
+
? html`
|
|
227
|
+
<p>
|
|
228
|
+
Update network data from ${this.onlineNeighborIds.length}
|
|
229
|
+
node${this.onlineNeighborIds.length !== 1 ? "s" : ""} that
|
|
230
|
+
see${this.onlineNeighborIds.length === 1 ? "s" : ""} this device to refresh info.
|
|
231
|
+
</p>
|
|
232
|
+
`
|
|
233
|
+
: html` <p>No online nodes available that see this device.</p> `}
|
|
234
|
+
`;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
override render() {
|
|
238
|
+
const buttonText =
|
|
239
|
+
this._updateCount === 0
|
|
240
|
+
? "No nodes to update"
|
|
241
|
+
: `Update ${this._updateCount} node${this._updateCount !== 1 ? "s" : ""}`;
|
|
242
|
+
|
|
243
|
+
return html`
|
|
244
|
+
<md-dialog @closed=${this._handleDialogClosed}>
|
|
245
|
+
<div slot="headline">Update Connection Data</div>
|
|
246
|
+
<div slot="content">
|
|
247
|
+
${this.selectedNodeType === "online"
|
|
248
|
+
? this._renderOnlineContent()
|
|
249
|
+
: this.selectedNodeType === "offline"
|
|
250
|
+
? this._renderOfflineContent()
|
|
251
|
+
: this._renderUnknownContent()}
|
|
252
|
+
</div>
|
|
253
|
+
<div slot="actions">
|
|
254
|
+
<md-text-button @click=${this._closeDialog} ?disabled=${this._isUpdating}>Cancel</md-text-button>
|
|
255
|
+
<md-filled-button
|
|
256
|
+
@click=${this._executeUpdate}
|
|
257
|
+
?disabled=${this._isUpdating || this._updateCount === 0}
|
|
258
|
+
>
|
|
259
|
+
${this._isUpdating
|
|
260
|
+
? html`<span class="updating-content"
|
|
261
|
+
>${svg`<svg class="spinner" viewBox="0 0 24 24" width="18" height="18"><path fill="currentColor" d="${mdiLoading}"/></svg>`}Updating...</span
|
|
262
|
+
>`
|
|
263
|
+
: buttonText}
|
|
264
|
+
</md-filled-button>
|
|
265
|
+
</div>
|
|
266
|
+
</md-dialog>
|
|
267
|
+
`;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
static override styles = css`
|
|
271
|
+
md-dialog {
|
|
272
|
+
--md-dialog-container-color: var(--md-sys-color-surface, #fff);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
[slot="content"] {
|
|
276
|
+
padding: 0 24px;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
[slot="content"] p {
|
|
280
|
+
margin: 0 0 16px 0;
|
|
281
|
+
font-size: 0.875rem;
|
|
282
|
+
line-height: 1.5;
|
|
283
|
+
color: var(--md-sys-color-on-surface, #333);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
[slot="content"] p:last-child {
|
|
287
|
+
margin-bottom: 0;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
.checkbox-row {
|
|
291
|
+
display: flex;
|
|
292
|
+
align-items: center;
|
|
293
|
+
gap: 8px;
|
|
294
|
+
cursor: pointer;
|
|
295
|
+
font-size: 0.875rem;
|
|
296
|
+
color: var(--md-sys-color-on-surface, #333);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
.updating-content {
|
|
300
|
+
display: inline-flex;
|
|
301
|
+
align-items: center;
|
|
302
|
+
gap: 8px;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
.spinner {
|
|
306
|
+
animation: spin 1s linear infinite;
|
|
307
|
+
flex-shrink: 0;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.updating-content svg {
|
|
311
|
+
color: inherit;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
@keyframes spin {
|
|
315
|
+
from {
|
|
316
|
+
transform: rotate(0deg);
|
|
317
|
+
}
|
|
318
|
+
to {
|
|
319
|
+
transform: rotate(360deg);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
md-filled-button {
|
|
324
|
+
min-width: 140px;
|
|
325
|
+
}
|
|
326
|
+
`;
|
|
327
|
+
}
|
|
@@ -69,9 +69,9 @@ export class WiFiGraph extends BaseNetworkGraph {
|
|
|
69
69
|
// Clear stored edge colors since we're rebuilding edges
|
|
70
70
|
this._clearOriginalEdgeColors();
|
|
71
71
|
|
|
72
|
-
// Get WiFi
|
|
72
|
+
// Get WiFi devices only (Ethernet has no dynamic network data)
|
|
73
73
|
const categorized = categorizeDevices(this.nodes);
|
|
74
|
-
const wifiNodeIds =
|
|
74
|
+
const wifiNodeIds = categorized.wifi;
|
|
75
75
|
|
|
76
76
|
if (wifiNodeIds.length === 0) {
|
|
77
77
|
this._nodesDataSet.clear();
|
|
@@ -156,6 +156,7 @@ export class WiFiGraph extends BaseNetworkGraph {
|
|
|
156
156
|
},
|
|
157
157
|
width: 2,
|
|
158
158
|
title: wifiDiag.rssi !== null ? `RSSI: ${wifiDiag.rssi} dBm` : "RSSI: Unknown",
|
|
159
|
+
dashes: isOffline, // Dashed lines for offline devices
|
|
159
160
|
});
|
|
160
161
|
}
|
|
161
162
|
}
|
|
@@ -176,7 +177,7 @@ export class WiFiGraph extends BaseNetworkGraph {
|
|
|
176
177
|
|
|
177
178
|
override render() {
|
|
178
179
|
const categorized = categorizeDevices(this.nodes);
|
|
179
|
-
const wifiCount = categorized.wifi.length
|
|
180
|
+
const wifiCount = categorized.wifi.length;
|
|
180
181
|
|
|
181
182
|
if (wifiCount === 0) {
|
|
182
183
|
return html`
|
package/src/util/format_hex.ts
CHANGED
|
@@ -43,3 +43,42 @@ export function formatNodeAddress(fabricIndex: number | undefined, nodeId: numbe
|
|
|
43
43
|
const fabricPart = fabricIndex !== undefined ? fabricIndex : "?";
|
|
44
44
|
return `@${fabricPart}:${nodeId.toString(16)}`;
|
|
45
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Get the effective fabric index for formatting a node address.
|
|
49
|
+
* Returns undefined for test nodes or when fabric index is not available,
|
|
50
|
+
* which will result in "?" being displayed.
|
|
51
|
+
*
|
|
52
|
+
* @param serverFabricIndex - The fabric_index from client.serverInfo
|
|
53
|
+
* @param isTestNode - Whether this is a test node (from isTestNodeId())
|
|
54
|
+
*/
|
|
55
|
+
export function getEffectiveFabricIndex(
|
|
56
|
+
serverFabricIndex: number | undefined,
|
|
57
|
+
isTestNode: boolean,
|
|
58
|
+
): number | undefined {
|
|
59
|
+
return isTestNode || serverFabricIndex === undefined ? undefined : serverFabricIndex;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Format a node address, handling string node IDs.
|
|
64
|
+
* Useful when node IDs come from various sources (string keys, numbers, bigints).
|
|
65
|
+
*
|
|
66
|
+
* @param fabricIndex - The fabric index (or undefined for "?")
|
|
67
|
+
* @param nodeId - The node ID as string, number, or bigint
|
|
68
|
+
* @returns Formatted address like "@1:7b" or empty string if nodeId is invalid
|
|
69
|
+
*/
|
|
70
|
+
export function formatNodeAddressFromAny(fabricIndex: number | undefined, nodeId: number | bigint | string): string {
|
|
71
|
+
let numericId: bigint;
|
|
72
|
+
if (typeof nodeId === "bigint") {
|
|
73
|
+
numericId = nodeId;
|
|
74
|
+
} else if (typeof nodeId === "number") {
|
|
75
|
+
numericId = BigInt(nodeId);
|
|
76
|
+
} else {
|
|
77
|
+
try {
|
|
78
|
+
numericId = BigInt(nodeId);
|
|
79
|
+
} catch {
|
|
80
|
+
return "";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return formatNodeAddress(fabricIndex, numericId);
|
|
84
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025-2026 Open Home Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Matter.js Status codes mapped to readable names.
|
|
9
|
+
* @see MatterSpecification.v142.Core § 8.10.1
|
|
10
|
+
*/
|
|
11
|
+
export const MatterStatusNames: Record<number, string> = {
|
|
12
|
+
0: "Success",
|
|
13
|
+
1: "Failure",
|
|
14
|
+
125: "InvalidSubscription",
|
|
15
|
+
126: "UnsupportedAccess",
|
|
16
|
+
127: "UnsupportedEndpoint",
|
|
17
|
+
128: "InvalidAction",
|
|
18
|
+
129: "UnsupportedCommand",
|
|
19
|
+
133: "InvalidCommand",
|
|
20
|
+
134: "UnsupportedAttribute",
|
|
21
|
+
135: "ConstraintError",
|
|
22
|
+
136: "UnsupportedWrite",
|
|
23
|
+
137: "ResourceExhausted",
|
|
24
|
+
139: "NotFound",
|
|
25
|
+
140: "UnreportableAttribute",
|
|
26
|
+
141: "InvalidDataType",
|
|
27
|
+
143: "UnsupportedRead",
|
|
28
|
+
146: "DataVersionMismatch",
|
|
29
|
+
148: "Timeout",
|
|
30
|
+
155: "UnsupportedNode",
|
|
31
|
+
156: "Busy",
|
|
32
|
+
157: "AccessRestricted",
|
|
33
|
+
195: "UnsupportedCluster",
|
|
34
|
+
197: "NoUpstreamSubscription",
|
|
35
|
+
198: "NeedsTimedInteraction",
|
|
36
|
+
199: "UnsupportedEvent",
|
|
37
|
+
200: "PathsExhausted",
|
|
38
|
+
201: "TimedRequestMismatch",
|
|
39
|
+
202: "FailsafeRequired",
|
|
40
|
+
203: "InvalidInState",
|
|
41
|
+
204: "NoCommandResponse",
|
|
42
|
+
205: "TermsAndConditionsChanged",
|
|
43
|
+
206: "MaintenanceRequired",
|
|
44
|
+
207: "DynamicConstraintError",
|
|
45
|
+
208: "AlreadyExists",
|
|
46
|
+
209: "InvalidTransportType",
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** Get readable name for a Matter status code */
|
|
50
|
+
export function getMatterStatusName(status: number): string {
|
|
51
|
+
return MatterStatusNames[status] ?? `Unknown(${status})`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Result type for Matter operations with status details */
|
|
55
|
+
export interface MatterOperationResult {
|
|
56
|
+
success: boolean;
|
|
57
|
+
status: number;
|
|
58
|
+
statusName: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Outcome type for batch operations */
|
|
62
|
+
export type BatchOutcome = "all_success" | "all_failed" | "partial";
|
|
63
|
+
|
|
64
|
+
/** Result type for batch Matter operations (multiple entries) */
|
|
65
|
+
export interface MatterBatchResult {
|
|
66
|
+
/** Overall outcome: all succeeded, all failed, or partial */
|
|
67
|
+
outcome: BatchOutcome;
|
|
68
|
+
/** Number of successful operations (status === 0) */
|
|
69
|
+
successCount: number;
|
|
70
|
+
/** Number of failed operations (status !== 0) */
|
|
71
|
+
failureCount: number;
|
|
72
|
+
/** Count of failures per status code, e.g. { 126: 2, 135: 1 } */
|
|
73
|
+
errorCounts: Record<number, number>;
|
|
74
|
+
/** Human-readable summary message for display */
|
|
75
|
+
message: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Create a successful operation result */
|
|
79
|
+
export function successResult(): MatterOperationResult {
|
|
80
|
+
return { success: true, status: 0, statusName: "Success" };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Create a failed operation result from a status code */
|
|
84
|
+
export function failureResult(status: number): MatterOperationResult {
|
|
85
|
+
return { success: false, status, statusName: getMatterStatusName(status) };
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Create an operation result from a status code (success if 0) */
|
|
89
|
+
export function resultFromStatus(status: number): MatterOperationResult {
|
|
90
|
+
const statusName = getMatterStatusName(status);
|
|
91
|
+
return { success: status === 0, status, statusName };
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Analyze multiple operation results and produce a batch result summary.
|
|
96
|
+
* @param results Array of objects with a `status` property (0 = success).
|
|
97
|
+
* If null, undefined, or empty, this is treated as a failed/unknown batch.
|
|
98
|
+
* @returns MatterBatchResult with outcome, counts, and human-readable message
|
|
99
|
+
*/
|
|
100
|
+
export function analyzeBatchResults(results: Array<{ status: number }> | null | undefined): MatterBatchResult {
|
|
101
|
+
if (!results || results.length === 0) {
|
|
102
|
+
return {
|
|
103
|
+
outcome: "all_failed",
|
|
104
|
+
successCount: 0,
|
|
105
|
+
failureCount: 0,
|
|
106
|
+
errorCounts: {},
|
|
107
|
+
message: "No response/results returned",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
let successCount = 0;
|
|
112
|
+
let failureCount = 0;
|
|
113
|
+
const errorCounts: Record<number, number> = {};
|
|
114
|
+
|
|
115
|
+
for (const result of results) {
|
|
116
|
+
if (result.status === 0) {
|
|
117
|
+
successCount++;
|
|
118
|
+
} else {
|
|
119
|
+
failureCount++;
|
|
120
|
+
errorCounts[result.status] = (errorCounts[result.status] ?? 0) + 1;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
let outcome: BatchOutcome;
|
|
125
|
+
if (failureCount === 0) {
|
|
126
|
+
outcome = "all_success";
|
|
127
|
+
} else if (successCount === 0) {
|
|
128
|
+
outcome = "all_failed";
|
|
129
|
+
} else {
|
|
130
|
+
outcome = "partial";
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const message = formatBatchMessage(outcome, successCount, failureCount, errorCounts);
|
|
134
|
+
|
|
135
|
+
return { outcome, successCount, failureCount, errorCounts, message };
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Format a human-readable message for batch results */
|
|
139
|
+
function formatBatchMessage(
|
|
140
|
+
outcome: BatchOutcome,
|
|
141
|
+
successCount: number,
|
|
142
|
+
failureCount: number,
|
|
143
|
+
errorCounts: Record<number, number>,
|
|
144
|
+
): string {
|
|
145
|
+
const entryWord = (count: number) => (count === 1 ? "entry" : "entries");
|
|
146
|
+
|
|
147
|
+
if (outcome === "all_success") {
|
|
148
|
+
return "Write successful";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Format error breakdown: "2x UnsupportedAccess (126), 1x ConstraintError (135)"
|
|
152
|
+
const errorParts = Object.entries(errorCounts)
|
|
153
|
+
.map(([code, count]) => {
|
|
154
|
+
const statusCode = parseInt(code, 10);
|
|
155
|
+
return `${count}x ${getMatterStatusName(statusCode)} (${code})`;
|
|
156
|
+
})
|
|
157
|
+
.join(", ");
|
|
158
|
+
|
|
159
|
+
if (outcome === "all_failed") {
|
|
160
|
+
return `All ${failureCount} ${entryWord(failureCount)} failed: ${errorParts}`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// partial
|
|
164
|
+
return `Partial failure: ${successCount} ${entryWord(successCount)} succeeded, ${failureCount} failed (${errorParts}). Please verify.`;
|
|
165
|
+
}
|