@matter-server/dashboard 1.5.2 → 1.5.3
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/dist/esm/client/models/descriptions.d.ts.map +1 -1
- package/dist/esm/client/models/descriptions.js +380 -0
- package/dist/esm/client/models/descriptions.js.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.d.ts +27 -0
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.js +428 -7
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.js.map +1 -1
- package/dist/esm/util/thermostat-preset-edit.d.ts +68 -0
- package/dist/esm/util/thermostat-preset-edit.d.ts.map +1 -0
- package/dist/esm/util/thermostat-preset-edit.js +174 -0
- package/dist/esm/util/thermostat-preset-edit.js.map +6 -0
- package/dist/esm/util/thermostat-schedule.d.ts +4 -0
- package/dist/esm/util/thermostat-schedule.d.ts.map +1 -1
- package/dist/esm/util/thermostat-schedule.js +5 -1
- package/dist/esm/util/thermostat-schedule.js.map +1 -1
- package/dist/web/js/{attribute-write-dialog-BYIrK0s9.js → attribute-write-dialog-C-KBqyuJ.js} +1 -1
- package/dist/web/js/{command-invoke-dialog-sgrlMSYh.js → command-invoke-dialog-C4HMf49Q.js} +1 -1
- package/dist/web/js/{commission-node-dialog-C7n9Vdcz.js → commission-node-dialog-Driu7kGn.js} +5 -5
- package/dist/web/js/{commission-node-existing-DfTkRkfm.js → commission-node-existing-Dth2CY1e.js} +1 -1
- package/dist/web/js/{commission-node-thread-B4_kOd4o.js → commission-node-thread-CnixX2gX.js} +1 -1
- package/dist/web/js/{commission-node-wifi-B37hLRjk.js → commission-node-wifi-8im5zNEv.js} +1 -1
- package/dist/web/js/{dialog-box-CRK6qCOH.js → dialog-box-Daj8_--D.js} +1 -1
- package/dist/web/js/{fabric-label-dialog-CtRCSYxX.js → fabric-label-dialog-Bk6lPNvk.js} +1 -1
- package/dist/web/js/main.js +1 -1
- package/dist/web/js/{matter-dashboard-app-DkWZ4ibd.js → matter-dashboard-app-BdO9wWRC.js} +907 -18
- package/dist/web/js/{node-acl-add-dialog-BSKJrvir.js → node-acl-add-dialog-OeLLubXq.js} +1 -1
- package/dist/web/js/{node-binding-dialog-DmhjB76G.js → node-binding-dialog-DQ9R0KrP.js} +1 -1
- package/dist/web/js/{node-label-dialog-DmrPo80W.js → node-label-dialog-IVEQrmsg.js} +1 -1
- package/dist/web/js/{settings-dialog-DxeXrD5U.js → settings-dialog-gcsO83Jl.js} +1 -1
- package/package.json +3 -3
- package/src/client/models/descriptions.ts +380 -0
- package/src/pages/cluster-commands/clusters/thermostat-commands.ts +486 -7
- package/src/util/thermostat-preset-edit.ts +289 -0
- package/src/util/thermostat-schedule.ts +6 -2
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025-2026 Open Home Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { MatterClient, MatterNode } from "@matter-server/ws-client";
|
|
8
|
+
import { asObject, pickArray, pickNumber } from "./attribute-shapes.js";
|
|
9
|
+
import { getMatterStatusName, requireAttributeWriteSuccess } from "./matter-status.js";
|
|
10
|
+
import {
|
|
11
|
+
decodePresets,
|
|
12
|
+
readThermostatAttribute,
|
|
13
|
+
THERMOSTAT_CLUSTER_ID,
|
|
14
|
+
type ThermostatPreset,
|
|
15
|
+
type ThermostatSchedule,
|
|
16
|
+
} from "./thermostat-schedule.js";
|
|
17
|
+
|
|
18
|
+
const ATTR_PRESET_TYPES = 0x48;
|
|
19
|
+
const ATTR_NUMBER_OF_PRESETS = 0x4a;
|
|
20
|
+
const ATTR_PRESETS = 0x50;
|
|
21
|
+
|
|
22
|
+
/** PresetTypeFeaturesBitmap (Matter spec §4.3.10.3): bit 1 says a preset of this scenario may carry a Name. */
|
|
23
|
+
const PRESET_TYPE_SUPPORTS_NAMES = 0x2;
|
|
24
|
+
|
|
25
|
+
/** PresetScenarioEnum UserDefined (§4.3.10.17): a preset of this scenario must carry a Name. */
|
|
26
|
+
const PRESET_SCENARIO_USER_DEFINED = 254;
|
|
27
|
+
|
|
28
|
+
/** How long the device holds our pending Presets write before discarding it (AtomicRequest Timeout, ms). */
|
|
29
|
+
const ATOMIC_WRITE_TIMEOUT_MS = 5_000;
|
|
30
|
+
|
|
31
|
+
/** Shortest window the device may grant that still fits the read, the timed write and the commit (ms). */
|
|
32
|
+
const MIN_ATOMIC_WRITE_TIMEOUT_MS = 2_000;
|
|
33
|
+
|
|
34
|
+
/** Timed-interaction window for the Presets write itself (TimedRequest to WriteRequest, ms). */
|
|
35
|
+
const TIMED_WRITE_TIMEOUT_MS = 3_000;
|
|
36
|
+
|
|
37
|
+
enum AtomicRequestType {
|
|
38
|
+
BeginWrite = 0,
|
|
39
|
+
CommitWrite = 1,
|
|
40
|
+
RollbackWrite = 2,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface ThermostatPresetType {
|
|
44
|
+
scenario: number;
|
|
45
|
+
numberOfPresets: number;
|
|
46
|
+
supportsNames: boolean;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function decodePresetType(raw: unknown): ThermostatPresetType | null {
|
|
50
|
+
const obj = asObject(raw);
|
|
51
|
+
if (!obj) return null;
|
|
52
|
+
const scenario = pickNumber(obj, "0");
|
|
53
|
+
const numberOfPresets = pickNumber(obj, "1");
|
|
54
|
+
if (scenario === null || numberOfPresets === null) return null;
|
|
55
|
+
const features = pickNumber(obj, "2") ?? 0;
|
|
56
|
+
return { scenario, numberOfPresets, supportsNames: (features & PRESET_TYPE_SUPPORTS_NAMES) !== 0 };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Decoded PresetTypes (the scenarios this device supports, and how many presets of each), or undefined if not cached. */
|
|
60
|
+
export function readPresetTypes(node: MatterNode, endpoint: number): ThermostatPresetType[] | undefined {
|
|
61
|
+
const raw = readThermostatAttribute(node, endpoint, ATTR_PRESET_TYPES);
|
|
62
|
+
if (!Array.isArray(raw)) return undefined;
|
|
63
|
+
return raw.map(decodePresetType).filter((t): t is ThermostatPresetType => t !== null);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Whether a preset of `scenario` may carry a Name; false when the scenario is unknown or PresetTypes isn't cached. */
|
|
67
|
+
export function presetTypeSupportsNames(presetTypes: ThermostatPresetType[], scenario: number | null): boolean {
|
|
68
|
+
return presetTypes.some(t => t.scenario === scenario && t.supportsNames);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** NumberOfPresets: how many presets the device holds in total, across all scenarios; null if not cached. */
|
|
72
|
+
export function readNumberOfPresets(node: MatterNode, endpoint: number): number | null {
|
|
73
|
+
const raw = readThermostatAttribute(node, endpoint, ATTR_NUMBER_OF_PRESETS);
|
|
74
|
+
return typeof raw === "number" ? raw : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** A preset as the edit UI builds it, before it is placed into the full Presets array the device expects. */
|
|
78
|
+
export interface ThermostatPresetEdit {
|
|
79
|
+
presetHandle: string | null;
|
|
80
|
+
presetScenario: number;
|
|
81
|
+
name: string | null;
|
|
82
|
+
coolingSetpoint: number | null;
|
|
83
|
+
heatingSetpoint: number | null;
|
|
84
|
+
builtIn: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A decoded preset as the edit UI starts from it; an unknown scenario falls back to 0. */
|
|
88
|
+
export function toPresetEdit(preset: ThermostatPreset): ThermostatPresetEdit {
|
|
89
|
+
return {
|
|
90
|
+
presetHandle: preset.handle,
|
|
91
|
+
presetScenario: preset.scenario ?? 0,
|
|
92
|
+
name: preset.name,
|
|
93
|
+
coolingSetpoint: preset.coolingSetpoint,
|
|
94
|
+
heatingSetpoint: preset.heatingSetpoint,
|
|
95
|
+
builtIn: preset.builtIn === true,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Applies the edit form's text inputs to `preset`. A blank or unparsable setpoint keeps the preset's value, and the
|
|
101
|
+
* name is only taken when the preset's scenario supports names: the device rejects a Name on any other preset.
|
|
102
|
+
*/
|
|
103
|
+
export function applyPresetEdit(
|
|
104
|
+
preset: ThermostatPreset,
|
|
105
|
+
presetTypes: ThermostatPresetType[],
|
|
106
|
+
input: { name: string; heating: string; cooling: string },
|
|
107
|
+
): ThermostatPresetEdit {
|
|
108
|
+
const name = input.name.trim();
|
|
109
|
+
return {
|
|
110
|
+
...toPresetEdit(preset),
|
|
111
|
+
name: presetTypeSupportsNames(presetTypes, preset.scenario) ? name || null : preset.name,
|
|
112
|
+
heatingSetpoint: parseSetpointInput(input.heating, preset.heatingSetpoint),
|
|
113
|
+
coolingSetpoint: parseSetpointInput(input.cooling, preset.coolingSetpoint),
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Why `name` cannot be used for a preset of `scenario`, or null if it can. Names must be unique per scenario, a
|
|
119
|
+
* missing name included (§4.3.10.23.3), and a UserDefined preset needs one. `exceptHandle` is the preset being edited.
|
|
120
|
+
*/
|
|
121
|
+
export function presetNameConflict(
|
|
122
|
+
presets: ThermostatPreset[],
|
|
123
|
+
scenario: number,
|
|
124
|
+
name: string | null,
|
|
125
|
+
exceptHandle: string | null,
|
|
126
|
+
): string | null {
|
|
127
|
+
if (scenario === PRESET_SCENARIO_USER_DEFINED && name === null) return "A user-defined preset needs a name";
|
|
128
|
+
const taken = presets.some(p => p.handle !== exceptHandle && p.scenario === scenario && p.name === name);
|
|
129
|
+
if (!taken) return null;
|
|
130
|
+
return name === null
|
|
131
|
+
? "Another preset of this scenario already has no name"
|
|
132
|
+
: `Another preset of this scenario is already named "${name}"`;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Whether a schedule transition refers to the preset; the device refuses to remove such a preset (§4.3.11.50). */
|
|
136
|
+
export function isPresetUsedBySchedule(schedules: ThermostatSchedule[], presetHandle: string): boolean {
|
|
137
|
+
return schedules.some(s => s.transitions.some(t => t.presetHandle === presetHandle));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Tag-keyed PresetStruct as `write_attribute` expects it. A null setpoint is omitted (the field isn't nullable), and
|
|
142
|
+
* so is a null Name: the CHIP SDK treats an explicit null Name as set and rejects it for a scenario without names.
|
|
143
|
+
*/
|
|
144
|
+
function toPresetStruct(preset: ThermostatPresetEdit): Record<string, unknown> {
|
|
145
|
+
const struct: Record<string, unknown> = {
|
|
146
|
+
"0": preset.presetHandle,
|
|
147
|
+
"1": preset.presetScenario,
|
|
148
|
+
"5": preset.builtIn,
|
|
149
|
+
};
|
|
150
|
+
if (preset.name !== null) struct["2"] = preset.name;
|
|
151
|
+
if (preset.coolingSetpoint !== null) struct["3"] = preset.coolingSetpoint;
|
|
152
|
+
if (preset.heatingSetpoint !== null) struct["4"] = preset.heatingSetpoint;
|
|
153
|
+
return struct;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** `°C` text to the cluster's int16 centidegrees; blank or unparsable input keeps `fallbackCentidegrees`. */
|
|
157
|
+
export function parseSetpointInput(text: string, fallbackCentidegrees: number | null): number | null {
|
|
158
|
+
const parsed = Number.parseFloat(text);
|
|
159
|
+
return Number.isFinite(parsed) ? Math.round(parsed * 100) : fallbackCentidegrees;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Centidegrees to `°C` input text at full precision, so saving an untouched field writes back the same value. */
|
|
163
|
+
export function formatSetpointInput(centidegrees: number | null): string {
|
|
164
|
+
return centidegrees === null ? "" : String(centidegrees / 100);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
interface AtomicAttributeStatus {
|
|
168
|
+
attributeId: number;
|
|
169
|
+
statusCode: number;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
interface AtomicResponse {
|
|
173
|
+
statusCode: number;
|
|
174
|
+
attributeStatus: AtomicAttributeStatus[];
|
|
175
|
+
/** Effective timeout in ms; present only on a BeginWrite response (§7.15.7.3). */
|
|
176
|
+
timeout: number | null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Command responses are name-keyed (convertMatterToWebSocketNameBased), unlike tag-keyed attribute values. */
|
|
180
|
+
function decodeAtomicResponse(raw: unknown): AtomicResponse {
|
|
181
|
+
const obj = asObject(raw);
|
|
182
|
+
const statusCode = obj ? pickNumber(obj, "statusCode") : null;
|
|
183
|
+
if (!obj || statusCode === null) throw new Error("The device answered AtomicRequest without a status");
|
|
184
|
+
const attributeStatus = pickArray(obj, "attributeStatus")
|
|
185
|
+
.map(entry => {
|
|
186
|
+
const status = asObject(entry);
|
|
187
|
+
const attributeId = status ? pickNumber(status, "attributeId") : null;
|
|
188
|
+
const code = status ? pickNumber(status, "statusCode") : null;
|
|
189
|
+
return attributeId === null || code === null ? null : { attributeId, statusCode: code };
|
|
190
|
+
})
|
|
191
|
+
.filter((s): s is AtomicAttributeStatus => s !== null);
|
|
192
|
+
return { statusCode, attributeStatus, timeout: pickNumber(obj, "timeout") };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function atomicRequest(
|
|
196
|
+
client: MatterClient,
|
|
197
|
+
nodeId: number | bigint,
|
|
198
|
+
endpoint: number,
|
|
199
|
+
requestType: AtomicRequestType,
|
|
200
|
+
attributeRequests: number[],
|
|
201
|
+
timeout?: number,
|
|
202
|
+
): Promise<AtomicResponse> {
|
|
203
|
+
return decodeAtomicResponse(
|
|
204
|
+
await client.deviceCommand(nodeId, endpoint, THERMOSTAT_CLUSTER_ID, "AtomicRequest", {
|
|
205
|
+
requestType,
|
|
206
|
+
attributeRequests,
|
|
207
|
+
timeout,
|
|
208
|
+
}),
|
|
209
|
+
);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function describeAtomicFailure(response: AtomicResponse): string {
|
|
213
|
+
const code = response.attributeStatus.find(s => s.statusCode !== 0)?.statusCode ?? response.statusCode;
|
|
214
|
+
return `${getMatterStatusName(code)} (${code})`;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* Replaces the device's Presets list with the list `buildNext` derives from the device's current one. The result is
|
|
219
|
+
* the full intended list, not a diff: per §4.3.11.50 a handle missing from it is a removal (rejected if that preset is
|
|
220
|
+
* built-in, active or used by a schedule transition) and `presetHandle: null` is an addition.
|
|
221
|
+
*
|
|
222
|
+
* Presets may only be written inside the cluster's atomic-write handshake (§7.15.3). The current list is read from the
|
|
223
|
+
* device inside that window, as the §7.15.1 flow describes: another client's BeginWrite gets BUSY while we hold the
|
|
224
|
+
* window (§7.15.6.4.1), and a change by command after our read may fail our commit (§7.15.3) instead of being
|
|
225
|
+
* overwritten. The write is sent timed so the controller does not put the pending list into its cache; the committed
|
|
226
|
+
* list arrives with the next report.
|
|
227
|
+
*
|
|
228
|
+
* A window shorter than {@link MIN_ATOMIC_WRITE_TIMEOUT_MS} is rolled back without writing (§7.15.1 step 1.2). A
|
|
229
|
+
* failed CommitWrite response already discards the pending write on the device (§7.15.6.4.2); any other failure after
|
|
230
|
+
* BeginWrite, including one thrown by `buildNext`, is followed by a RollbackWrite.
|
|
231
|
+
*/
|
|
232
|
+
export async function writeThermostatPresets(
|
|
233
|
+
client: MatterClient,
|
|
234
|
+
nodeId: number | bigint,
|
|
235
|
+
endpoint: number,
|
|
236
|
+
buildNext: (current: ThermostatPreset[]) => ThermostatPresetEdit[],
|
|
237
|
+
): Promise<void> {
|
|
238
|
+
const begin = await atomicRequest(
|
|
239
|
+
client,
|
|
240
|
+
nodeId,
|
|
241
|
+
endpoint,
|
|
242
|
+
AtomicRequestType.BeginWrite,
|
|
243
|
+
[ATTR_PRESETS],
|
|
244
|
+
ATOMIC_WRITE_TIMEOUT_MS,
|
|
245
|
+
);
|
|
246
|
+
if (begin.statusCode !== 0) {
|
|
247
|
+
throw new Error(`Could not start editing presets: ${describeAtomicFailure(begin)}`);
|
|
248
|
+
}
|
|
249
|
+
// §7.15.6.4.1: the device may add attributes that share a resource with Presets; commit and rollback name them all.
|
|
250
|
+
const atomicAttributes =
|
|
251
|
+
begin.attributeStatus.length > 0 ? begin.attributeStatus.map(s => s.attributeId) : [ATTR_PRESETS];
|
|
252
|
+
|
|
253
|
+
const path = presetsPath(endpoint);
|
|
254
|
+
let commit: AtomicResponse;
|
|
255
|
+
try {
|
|
256
|
+
if (begin.timeout !== null && begin.timeout < MIN_ATOMIC_WRITE_TIMEOUT_MS) {
|
|
257
|
+
throw new Error(`The device allows only ${begin.timeout} ms to edit presets, too short to write them`);
|
|
258
|
+
}
|
|
259
|
+
const current = decodePresets((await client.readAttribute(nodeId, path, undefined, true))[path]);
|
|
260
|
+
if (current === undefined) throw new Error("The device did not report its presets");
|
|
261
|
+
const writeResults = await client.writeAttribute(nodeId, path, buildNext(current).map(toPresetStruct), {
|
|
262
|
+
timedRequestTimeoutMs: TIMED_WRITE_TIMEOUT_MS,
|
|
263
|
+
});
|
|
264
|
+
requireAttributeWriteSuccess(writeResults, "Writing presets failed");
|
|
265
|
+
commit = await atomicRequest(client, nodeId, endpoint, AtomicRequestType.CommitWrite, atomicAttributes);
|
|
266
|
+
} catch (error) {
|
|
267
|
+
await atomicRequest(client, nodeId, endpoint, AtomicRequestType.RollbackWrite, atomicAttributes).catch(
|
|
268
|
+
(rollbackError: unknown) => console.error("Could not roll back a failed preset write", rollbackError),
|
|
269
|
+
);
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
if (commit.statusCode !== 0) {
|
|
273
|
+
throw new Error(`Could not commit preset changes: ${describeAtomicFailure(commit)}`);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
function presetsPath(endpoint: number): string {
|
|
278
|
+
return `${endpoint}/${THERMOSTAT_CLUSTER_ID}/${ATTR_PRESETS}`;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/** Sets the thermostat's active preset (SetActivePresetRequest, §4.3.12.3); `presetHandle: null` clears it. */
|
|
282
|
+
export async function setActivePreset(
|
|
283
|
+
client: MatterClient,
|
|
284
|
+
nodeId: number | bigint,
|
|
285
|
+
endpoint: number,
|
|
286
|
+
presetHandle: string | null,
|
|
287
|
+
): Promise<void> {
|
|
288
|
+
await client.deviceCommand(nodeId, endpoint, THERMOSTAT_CLUSTER_ID, "SetActivePresetRequest", { presetHandle });
|
|
289
|
+
}
|
|
@@ -138,7 +138,7 @@ function decodePreset(raw: unknown): ThermostatPreset | null {
|
|
|
138
138
|
}
|
|
139
139
|
|
|
140
140
|
/** PresetScenarioEnum labels (Matter spec §4.3.10.17). */
|
|
141
|
-
const PRESET_SCENARIO_LABELS: Record<number, string> = {
|
|
141
|
+
export const PRESET_SCENARIO_LABELS: Record<number, string> = {
|
|
142
142
|
1: "Occupied",
|
|
143
143
|
2: "Unoccupied",
|
|
144
144
|
3: "Sleep",
|
|
@@ -182,7 +182,11 @@ export function readSchedules(node: MatterNode, endpoint: number): ThermostatSch
|
|
|
182
182
|
|
|
183
183
|
/** Decoded Presets, or undefined when the attribute is not in the node's attribute cache. */
|
|
184
184
|
export function readPresets(node: MatterNode, endpoint: number): ThermostatPreset[] | undefined {
|
|
185
|
-
|
|
185
|
+
return decodePresets(readThermostatAttribute(node, endpoint, ATTR_PRESETS));
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Decodes a tag-keyed Presets attribute value; undefined when it is not a list. */
|
|
189
|
+
export function decodePresets(raw: unknown): ThermostatPreset[] | undefined {
|
|
186
190
|
if (!Array.isArray(raw)) return undefined;
|
|
187
191
|
return raw.map(decodePreset).filter((p): p is ThermostatPreset => p !== null);
|
|
188
192
|
}
|