From 32097ec0eb9b97a3f5a4ba58d45f6ba2fa33fb7a Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Wed, 17 Jul 2024 00:38:58 +0200 Subject: [PATCH] Add update button to debug UI (#806) --- dashboard/src/client/models/model.ts | 1 - dashboard/src/client/models/node.ts | 8 ++ .../src/pages/components/node-details.ts | 79 ++++++++++++++----- 3 files changed, 67 insertions(+), 21 deletions(-) diff --git a/dashboard/src/client/models/model.ts b/dashboard/src/client/models/model.ts index a791c3fe..2c04fe66 100644 --- a/dashboard/src/client/models/model.ts +++ b/dashboard/src/client/models/model.ts @@ -236,6 +236,5 @@ export interface MatterFabricData { } - export type NotificationType = "success" | "info" | "warning" | "error"; export type NodePingResult = Record; diff --git a/dashboard/src/client/models/node.ts b/dashboard/src/client/models/node.ts index d57eac00..89e6af13 100644 --- a/dashboard/src/client/models/node.ts +++ b/dashboard/src/client/models/node.ts @@ -38,6 +38,14 @@ export class MatterNode { return this.attributes["0/40/15"]; } + get updateState(): number | undefined { + return this.attributes["0/42/2"]; + } + + get updateStateProgress(): number | undefined { + return this.attributes["0/42/3"]; + } + update(data: Record): MatterNode { return new MatterNode({ ...this.data, ...data }); } diff --git a/dashboard/src/pages/components/node-details.ts b/dashboard/src/pages/components/node-details.ts index 9102d329..0f40ae8a 100644 --- a/dashboard/src/pages/components/node-details.ts +++ b/dashboard/src/pages/components/node-details.ts @@ -5,9 +5,9 @@ import "@material/web/divider/divider"; import "@material/web/iconbutton/icon-button"; import "@material/web/list/list"; import "@material/web/list/list-item"; -import { mdiChatProcessing, mdiTrashCan } from "@mdi/js"; +import { mdiChatProcessing, mdiTrashCan, mdiUpdate } from "@mdi/js"; import { LitElement, css, html, nothing } from "lit"; -import { customElement, property } from "lit/decorators.js"; +import { customElement, property, state } from "lit/decorators.js"; import { MatterClient } from "../../client/client"; import { DeviceType } from "../../client/models/descriptions"; import { MatterNode } from "../../client/models/node"; @@ -37,6 +37,9 @@ export class NodeDetails extends LitElement { @property() public node?: MatterNode; + @state() + private _updateInitiated: boolean = false; + protected render() { if (!this.node) return html``; return html` @@ -44,19 +47,18 @@ export class NodeDetails extends LitElement {
Node ${this.node.node_id} ${this.node.nodeLabel} - ${ - this.node.available - ? nothing - : html`OFFLINE` - } + ${this.node.available + ? nothing + : html`OFFLINE` + }
- VendorName:
${this.node.vendorName} + VendorName: ${this.node.vendorName}
- productName:
${this.node.productName} + productName: ${this.node.productName}
Commissioned: ${this.node.date_commissioned} @@ -70,23 +72,25 @@ export class NodeDetails extends LitElement {
Serialnumber: ${this.node.serialNumber}
- ${ - this.node.is_bridge - ? "" - : html`
+ ${this.node.is_bridge + ? "" + : html`
All device types: ${getNodeDeviceTypes(this.node) - .map((deviceType) => { - return deviceType.label; - }) - .join(" / ")} + .map((deviceType) => { + return deviceType.label; + }) + .join(" / ")}
` - } + } - Interview node - Remove node + Interview + ${this.node.updateStateProgress != null || this._updateInitiated ? html` + Update (${this.node.updateStateProgress || 0}%)` + : html`Update`} + Remove `; @@ -139,6 +143,41 @@ export class NodeDetails extends LitElement { } } + private async _searchUpdate() { + const nodeUpdate = await this.client.checkNodeUpdate(this.node!.node_id); + if (!nodeUpdate) { + showAlertDialog({ + title: "No update available", + text: "No update available for this node", + }); + return; + } + if ( + !(await showPromptDialog({ + title: "Firmware update available", + text: `Found a firmware update for this node on ${nodeUpdate.update_source}. + Do you want to update this node to version ${nodeUpdate.software_version_string}? + Note that updating firmware is at your own risk and may cause the device to + malfunction or needs additional handling such as power cycling it and/or recommisisoning it. + Use with care.\n${nodeUpdate.firmware_information}`, + confirmText: "Start Update", + })) + ) { + return; + } + try { + this._updateInitiated = true; + await this.client.updateNode(this.node!.node_id, nodeUpdate.software_version); + } catch (err: any) { + showAlertDialog({ + title: "Failed to update node", + text: err.message, + }); + } finally { + this._updateInitiated = false + } + } + static styles = css` .btn { --md-outlined-button-container-shape: 0px;