Skip to content

Commit c09db74

Browse files
authored
Handle lost connection in the dashboard (#837)
1 parent 74bfa66 commit c09db74

File tree

4 files changed

+59
-50
lines changed

4 files changed

+59
-50
lines changed

dashboard/src/client/client.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,10 @@ export class MatterClient {
181181
if (this.connection.connected) {
182182
return;
183183
}
184-
await this.connection.connect((msg) => this._handleIncomingMessage(msg));
184+
await this.connection.connect(
185+
(msg) => this._handleIncomingMessage(msg),
186+
() => this.fireEvent("connection_lost")
187+
);
185188
}
186189

187190
disconnect(clearStorage = true) {

dashboard/src/client/connection.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class Connection {
1313
return this.socket?.readyState === WebSocket.OPEN;
1414
}
1515

16-
async connect(onMessage: (msg: Record<string, any>) => void) {
16+
async connect(onMessage: (msg: Record<string, any>) => void, onConnectionLost: () => void) {
1717
if (this.socket) {
1818
throw new Error("Already connected");
1919
}
@@ -31,7 +31,7 @@ export class Connection {
3131
console.log(
3232
`WebSocket Closed: Code=${event.code}, Reason=${event.reason}`
3333
);
34-
reject(new Error("Connection Closed"));
34+
onConnectionLost();
3535
};
3636

3737
this.socket.onerror = (error) => {

dashboard/src/client/models/descriptions.ts

+44-44
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const device_types: Record<number, DeviceType> = {
2828
"clusters": [
2929
66,
3030
67,
31-
28,
32-
68
31+
68,
32+
28
3333
]
3434
},
3535
"22": {
@@ -96,8 +96,8 @@ export const device_types: Record<number, DeviceType> = {
9696
"id": 14,
9797
"label": "Aggregator",
9898
"clusters": [
99-
37,
100-
29
99+
29,
100+
37
101101
]
102102
},
103103
"19": {
@@ -190,14 +190,14 @@ export const device_types: Record<number, DeviceType> = {
190190
"label": "Pump",
191191
"clusters": [
192192
512,
193-
98,
193+
1026,
194194
3,
195-
4,
196195
1027,
196+
4,
197197
6,
198198
1028,
199+
98,
199200
8,
200-
1026,
201201
29,
202202
30
203203
]
@@ -300,8 +300,8 @@ export const device_types: Record<number, DeviceType> = {
300300
"id": 773,
301301
"label": "Pressure Sensor",
302302
"clusters": [
303-
1027,
304303
3,
304+
1027,
305305
29
306306
]
307307
},
@@ -318,9 +318,9 @@ export const device_types: Record<number, DeviceType> = {
318318
"id": 775,
319319
"label": "Humidity Sensor",
320320
"clusters": [
321-
29,
321+
1029,
322322
3,
323-
1029
323+
29
324324
]
325325
},
326326
"2128": {
@@ -355,9 +355,9 @@ export const device_types: Record<number, DeviceType> = {
355355
"label": "Window Covering",
356356
"clusters": [
357357
258,
358+
98,
358359
3,
359360
4,
360-
98,
361361
29
362362
]
363363
},
@@ -374,10 +374,10 @@ export const device_types: Record<number, DeviceType> = {
374374
"id": 768,
375375
"label": "Heating/Cooling Unit",
376376
"clusters": [
377-
98,
377+
514,
378378
3,
379379
4,
380-
514,
380+
98,
381381
6,
382382
8,
383383
29,
@@ -391,8 +391,8 @@ export const device_types: Record<number, DeviceType> = {
391391
513,
392392
98,
393393
3,
394-
4,
395394
516,
395+
4,
396396
56,
397397
29,
398398
30
@@ -415,14 +415,14 @@ export const device_types: Record<number, DeviceType> = {
415415
1283,
416416
1284,
417417
1285,
418+
1286,
418419
6,
419420
1287,
420-
1288,
421421
1289,
422-
1290,
422+
1288,
423423
1291,
424424
1292,
425-
1286,
425+
1290,
426426
1294,
427427
29
428428
]
@@ -435,10 +435,10 @@ export const device_types: Record<number, DeviceType> = {
435435
1284,
436436
1285,
437437
6,
438+
1286,
438439
1287,
439-
1288,
440440
1289,
441-
1286,
441+
1288,
442442
1291,
443443
29
444444
]
@@ -450,17 +450,17 @@ export const device_types: Record<number, DeviceType> = {
450450
1283,
451451
1284,
452452
1285,
453+
1286,
453454
6,
454455
1287,
455-
8,
456456
1289,
457-
1290,
457+
1288,
458458
1291,
459459
1292,
460460
1293,
461461
1294,
462-
1288,
463-
1286,
462+
8,
463+
1290,
464464
29,
465465
30
466466
]
@@ -472,16 +472,16 @@ export const device_types: Record<number, DeviceType> = {
472472
1283,
473473
1284,
474474
1285,
475+
1286,
475476
6,
476477
1287,
477-
8,
478478
1289,
479-
1290,
479+
1288,
480480
1291,
481481
1292,
482-
1288,
482+
8,
483483
1294,
484-
1286,
484+
1290,
485485
29,
486486
30
487487
]
@@ -526,14 +526,14 @@ export const device_types: Record<number, DeviceType> = {
526526
"label": "Room Air Conditioner",
527527
"clusters": [
528528
513,
529-
98,
529+
514,
530530
3,
531+
516,
531532
4,
532-
1029,
533533
6,
534-
514,
535-
516,
536534
1026,
535+
98,
536+
1029,
537537
29
538538
]
539539
},
@@ -573,10 +573,10 @@ export const device_types: Record<number, DeviceType> = {
573573
1066,
574574
1067,
575575
1068,
576+
1036,
576577
1037,
577-
1069,
578578
1071,
579-
1036,
579+
1069,
580580
1070,
581581
1043,
582582
1045,
@@ -591,10 +591,10 @@ export const device_types: Record<number, DeviceType> = {
591591
96,
592592
3,
593593
6,
594-
29,
594+
93,
595595
86,
596596
89,
597-
93
597+
29
598598
]
599599
},
600600
"123": {
@@ -692,9 +692,9 @@ export const device_types: Record<number, DeviceType> = {
692692
"label": "Water Freeze Detector",
693693
"clusters": [
694694
128,
695+
29,
695696
3,
696-
69,
697-
29
697+
69
698698
]
699699
},
700700
"66": {
@@ -711,19 +711,19 @@ export const device_types: Record<number, DeviceType> = {
711711
"label": "Water Leak Detector",
712712
"clusters": [
713713
128,
714+
29,
714715
3,
715-
69,
716-
29
716+
69
717717
]
718718
},
719719
"68": {
720720
"id": 68,
721721
"label": "Rain Sensor",
722722
"clusters": [
723723
128,
724+
29,
724725
3,
725-
69,
726-
29
726+
69
727727
]
728728
},
729729
"4293984272": {
@@ -740,11 +740,11 @@ export const device_types: Record<number, DeviceType> = {
740740
768,
741741
257,
742742
98,
743-
259,
744-
4,
745743
3,
746-
6,
744+
4,
747745
1026,
746+
6,
747+
259,
748748
8,
749749
29,
750750
30

dashboard/src/pages/matter-dashboard-app.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ class MatterDashboardApp extends LitElement {
2727
public client!: MatterClient;
2828

2929
@state()
30-
private _state: "connecting" | "connected" | "error" = "connecting";
30+
private _state: "connecting" | "connected" | "error" | "disconnected" = "connecting";
3131

3232
private _error: string | undefined;
3333

34-
private provider = new ContextProvider(this, {context: clientContext, initialValue: this.client});
34+
private provider = new ContextProvider(this, { context: clientContext, initialValue: this.client });
3535

3636
protected firstUpdated(
3737
_changedProperties: PropertyValueMap<any> | Map<PropertyKey, unknown>
@@ -47,12 +47,15 @@ class MatterDashboardApp extends LitElement {
4747
this.client.addEventListener("server_info_updated", () => {
4848
this.provider.setValue(clone(this.client));
4949
});
50+
this.client.addEventListener("connection_lost", () => {
51+
this._state = "disconnected";
52+
});
5053
},
5154
(err: MatterError) => {
5255
this._state = "error";
5356
this._error = err.message;
5457
}
55-
);
58+
)
5659

5760
// Handle history changes
5861
const updateRoute = () => {
@@ -70,6 +73,9 @@ class MatterDashboardApp extends LitElement {
7073
if (this._state === "connecting") {
7174
return html`<p>Connecting...</p>`;
7275
}
76+
if (this._state === "disconnected") {
77+
return html`<p>Connection lost</p>`;
78+
}
7379
if (this._state === "error") {
7480
return html`
7581
<p>Error: ${this._error}</p>

0 commit comments

Comments
 (0)