@matter-server/dashboard 1.4.0-alpha.0-20260802-ac0d816 → 1.4.0
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 +77 -993
- package/dist/esm/client/models/descriptions.js.map +1 -1
- package/dist/esm/components/avsum-ptz-strip.d.ts.map +1 -1
- package/dist/esm/components/dialog-box/dialog-box.d.ts.map +1 -1
- package/dist/esm/components/dialogs/acl/node-acl-add-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/binding/node-binding-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/commission-node-dialog/commission-node-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/commission-node-dialog/commission-node-thread.d.ts.map +1 -1
- package/dist/esm/components/dialogs/commission-node-dialog/commission-node-wifi.d.ts.map +1 -1
- package/dist/esm/components/dialogs/dev/attribute-write-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/dev/command-invoke-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/fabric-label-dialog/fabric-label-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/node-label-dialog/node-label-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/settings/log-level-dialog.d.ts.map +1 -1
- package/dist/esm/components/dialogs/settings/log-level-section.d.ts.map +1 -1
- package/dist/esm/components/dialogs/settings/settings-dialog.d.ts.map +1 -1
- package/dist/esm/components/ha-svg-icon.d.ts.map +1 -1
- package/dist/esm/components/webrtc-stream-view.d.ts.map +1 -1
- package/dist/esm/pages/camera-overlay.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/access-control-commands.d.ts +1 -0
- package/dist/esm/pages/cluster-commands/clusters/access-control-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/access-control-commands.js +1 -1
- package/dist/esm/pages/cluster-commands/clusters/access-control-commands.js.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/avsum-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/basic-information-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/binding-commands.d.ts +6 -0
- package/dist/esm/pages/cluster-commands/clusters/binding-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/binding-commands.js +1 -1
- package/dist/esm/pages/cluster-commands/clusters/binding-commands.js.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/chime-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/closure-control-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/commodity-tariff-commands.d.ts +23 -0
- package/dist/esm/pages/cluster-commands/clusters/commodity-tariff-commands.d.ts.map +1 -0
- package/dist/esm/pages/cluster-commands/clusters/commodity-tariff-commands.js +191 -0
- package/dist/esm/pages/cluster-commands/clusters/commodity-tariff-commands.js.map +6 -0
- package/dist/esm/pages/cluster-commands/clusters/icd-management-commands.d.ts +6 -0
- package/dist/esm/pages/cluster-commands/clusters/icd-management-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/icd-management-commands.js +1 -1
- package/dist/esm/pages/cluster-commands/clusters/icd-management-commands.js.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/level-control-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/meter-identification-commands.d.ts +20 -0
- package/dist/esm/pages/cluster-commands/clusters/meter-identification-commands.d.ts.map +1 -0
- package/dist/esm/pages/cluster-commands/clusters/meter-identification-commands.js +81 -0
- package/dist/esm/pages/cluster-commands/clusters/meter-identification-commands.js.map +6 -0
- package/dist/esm/pages/cluster-commands/clusters/on-off-commands.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.d.ts +26 -0
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.d.ts.map +1 -0
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.js +490 -0
- package/dist/esm/pages/cluster-commands/clusters/thermostat-commands.js.map +6 -0
- package/dist/esm/pages/cluster-commands/index.d.ts +4 -1
- package/dist/esm/pages/cluster-commands/index.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/index.js +11 -2
- package/dist/esm/pages/cluster-commands/index.js.map +1 -1
- package/dist/esm/pages/cluster-commands/registry.d.ts +21 -1
- package/dist/esm/pages/cluster-commands/registry.d.ts.map +1 -1
- package/dist/esm/pages/cluster-commands/registry.js +8 -4
- package/dist/esm/pages/cluster-commands/registry.js.map +1 -1
- package/dist/esm/pages/components/node-details.d.ts +4 -0
- package/dist/esm/pages/components/node-details.d.ts.map +1 -1
- package/dist/esm/pages/components/node-details.js +66 -1
- package/dist/esm/pages/components/node-details.js.map +1 -1
- package/dist/esm/pages/matter-cluster-view.d.ts +4 -0
- package/dist/esm/pages/matter-cluster-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-cluster-view.js +6 -3
- package/dist/esm/pages/matter-cluster-view.js.map +1 -1
- package/dist/esm/pages/matter-dashboard-app.d.ts.map +1 -1
- package/dist/esm/pages/matter-endpoint-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-network-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-node-view.d.ts.map +1 -1
- package/dist/esm/pages/matter-server-view.d.ts.map +1 -1
- package/dist/esm/pages/network/device-panel.d.ts.map +1 -1
- package/dist/esm/pages/network/network-details.d.ts.map +1 -1
- package/dist/esm/pages/network/thread-graph.d.ts.map +1 -1
- package/dist/esm/pages/network/update-connections-dialog.d.ts.map +1 -1
- package/dist/esm/pages/network/wifi-graph.d.ts.map +1 -1
- package/dist/esm/util/attribute-shapes.d.ts +12 -0
- package/dist/esm/util/attribute-shapes.d.ts.map +1 -1
- package/dist/esm/util/attribute-shapes.js +26 -1
- package/dist/esm/util/attribute-shapes.js.map +1 -1
- package/dist/esm/util/commodity-tariff.d.ts +84 -0
- package/dist/esm/util/commodity-tariff.d.ts.map +1 -0
- package/dist/esm/util/commodity-tariff.js +255 -0
- package/dist/esm/util/commodity-tariff.js.map +6 -0
- package/dist/esm/util/fire_event.d.ts.map +1 -1
- package/dist/esm/util/meter-identification.d.ts +22 -0
- package/dist/esm/util/meter-identification.d.ts.map +1 -0
- package/dist/esm/util/meter-identification.js +60 -0
- package/dist/esm/util/meter-identification.js.map +6 -0
- package/dist/esm/util/thermostat-schedule.d.ts +93 -0
- package/dist/esm/util/thermostat-schedule.d.ts.map +1 -0
- package/dist/esm/util/thermostat-schedule.js +253 -0
- package/dist/esm/util/thermostat-schedule.js.map +6 -0
- package/dist/web/index.html +6 -0
- package/dist/web/js/{attribute-write-dialog-lNuCZ3k9.js → attribute-write-dialog-Dj2vnLR_.js} +1 -1
- package/dist/web/js/{command-invoke-dialog-BsvOYKuy.js → command-invoke-dialog-DJY2HePu.js} +1 -1
- package/dist/web/js/{commission-node-dialog-BHdEFbdo.js → commission-node-dialog-BAzJcdYg.js} +5 -5
- package/dist/web/js/{commission-node-existing-DHnKVo6U.js → commission-node-existing-DDtYs7R-.js} +1 -1
- package/dist/web/js/{commission-node-thread-Cj3toV8W.js → commission-node-thread-Bf0XhUqn.js} +1 -1
- package/dist/web/js/{commission-node-wifi-BdAS2Vof.js → commission-node-wifi-DL4q7kzh.js} +1 -1
- package/dist/web/js/{dialog-box-DQV4kYxU.js → dialog-box-BquhCceT.js} +1 -1
- package/dist/web/js/{fabric-label-dialog-Be5bxfzQ.js → fabric-label-dialog-iLm9DGea.js} +1 -1
- package/dist/web/js/main.js +37 -1
- package/dist/web/js/{matter-dashboard-app-B186DbKC.js → matter-dashboard-app-RcyNZLl_.js} +1616 -1215
- package/dist/web/js/{node-acl-add-dialog-D4ZLnora.js → node-acl-add-dialog-CyWYXa6M.js} +1 -1
- package/dist/web/js/{node-binding-dialog-MGTLF9MJ.js → node-binding-dialog-BjQ0KYzx.js} +1 -1
- package/dist/web/js/{node-label-dialog-DgbTIGwf.js → node-label-dialog-BNUn3Joo.js} +1 -1
- package/dist/web/js/{settings-dialog-BQJbHl4j.js → settings-dialog-DvAq6gKo.js} +1 -1
- package/package.json +6 -6
- package/src/client/models/descriptions.ts +77 -993
- package/src/pages/cluster-commands/clusters/access-control-commands.ts +1 -1
- package/src/pages/cluster-commands/clusters/binding-commands.ts +1 -1
- package/src/pages/cluster-commands/clusters/commodity-tariff-commands.ts +224 -0
- package/src/pages/cluster-commands/clusters/icd-management-commands.ts +2 -1
- package/src/pages/cluster-commands/clusters/meter-identification-commands.ts +111 -0
- package/src/pages/cluster-commands/clusters/thermostat-commands.ts +538 -0
- package/src/pages/cluster-commands/index.ts +10 -1
- package/src/pages/cluster-commands/registry.ts +27 -4
- package/src/pages/components/node-details.ts +82 -2
- package/src/pages/matter-cluster-view.ts +6 -6
- package/src/util/attribute-shapes.ts +34 -0
- package/src/util/commodity-tariff.ts +431 -0
- package/src/util/meter-identification.ts +86 -0
- package/src/util/thermostat-schedule.ts +359 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025-2026 Open Home Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { tagField as field, toNumber, toText } from "./attribute-shapes.js";
|
|
8
|
+
|
|
9
|
+
export const METER_IDENTIFICATION_CLUSTER_ID = 2822;
|
|
10
|
+
|
|
11
|
+
const ATTR_METER_TYPE = 0;
|
|
12
|
+
const ATTR_POINT_OF_DELIVERY = 1;
|
|
13
|
+
const ATTR_METER_SERIAL_NUMBER = 2;
|
|
14
|
+
const ATTR_PROTOCOL_VERSION = 3;
|
|
15
|
+
const ATTR_POWER_THRESHOLD = 4;
|
|
16
|
+
const ATTR_FEATURE_MAP = 0xfffc;
|
|
17
|
+
|
|
18
|
+
const METER_TYPE_NAMES: Record<number, string> = {
|
|
19
|
+
0: "Utility",
|
|
20
|
+
1: "Private",
|
|
21
|
+
2: "Generic",
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const POWER_THRESHOLD_SOURCE_NAMES: Record<number, string> = {
|
|
25
|
+
0: "Contract",
|
|
26
|
+
1: "Legal regulator",
|
|
27
|
+
2: "Meter equipment limit",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/** MeterIdentification FeatureMap bits per Matter 1.6 §2.13.4. */
|
|
31
|
+
const POWER_THRESHOLD_FEATURE_BIT = 0b1;
|
|
32
|
+
|
|
33
|
+
export interface PowerThresholdInfo {
|
|
34
|
+
powerThresholdW?: number;
|
|
35
|
+
apparentPowerThresholdVA?: number;
|
|
36
|
+
source?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface MeterIdentificationInfo {
|
|
40
|
+
supported: boolean;
|
|
41
|
+
meterType?: string;
|
|
42
|
+
pointOfDelivery?: string;
|
|
43
|
+
meterSerialNumber?: string;
|
|
44
|
+
protocolVersion?: string;
|
|
45
|
+
powerThresholdSupported: boolean;
|
|
46
|
+
powerThreshold?: PowerThresholdInfo;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function attr(attributes: Record<string, unknown>, endpoint: number, attributeId: number): unknown {
|
|
50
|
+
return attributes[`${endpoint}/${METER_IDENTIFICATION_CLUSTER_ID}/${attributeId}`];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function enumName(value: unknown, names: Record<number, string>): string | undefined {
|
|
54
|
+
const raw = toNumber(value);
|
|
55
|
+
if (raw === undefined) return undefined;
|
|
56
|
+
return names[raw] ?? `Unknown (${raw})`;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function decodePowerThreshold(value: unknown): PowerThresholdInfo | undefined {
|
|
60
|
+
const powerThreshold = toNumber(field(value, 0));
|
|
61
|
+
const apparentPowerThreshold = toNumber(field(value, 1));
|
|
62
|
+
const source = enumName(field(value, 2), POWER_THRESHOLD_SOURCE_NAMES);
|
|
63
|
+
if (powerThreshold === undefined && apparentPowerThreshold === undefined && source === undefined) return undefined;
|
|
64
|
+
return {
|
|
65
|
+
powerThresholdW: powerThreshold !== undefined ? powerThreshold / 1000 : undefined,
|
|
66
|
+
apparentPowerThresholdVA: apparentPowerThreshold !== undefined ? apparentPowerThreshold / 1000 : undefined,
|
|
67
|
+
source,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function meterIdentificationInfo(
|
|
72
|
+
attributes: Record<string, unknown>,
|
|
73
|
+
endpoint: number,
|
|
74
|
+
): MeterIdentificationInfo {
|
|
75
|
+
const featureMap = attr(attributes, endpoint, ATTR_FEATURE_MAP);
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
supported: featureMap !== undefined,
|
|
79
|
+
meterType: enumName(attr(attributes, endpoint, ATTR_METER_TYPE), METER_TYPE_NAMES),
|
|
80
|
+
pointOfDelivery: toText(attr(attributes, endpoint, ATTR_POINT_OF_DELIVERY)),
|
|
81
|
+
meterSerialNumber: toText(attr(attributes, endpoint, ATTR_METER_SERIAL_NUMBER)),
|
|
82
|
+
protocolVersion: toText(attr(attributes, endpoint, ATTR_PROTOCOL_VERSION)),
|
|
83
|
+
powerThresholdSupported: ((toNumber(featureMap) ?? 0) & POWER_THRESHOLD_FEATURE_BIT) !== 0,
|
|
84
|
+
powerThreshold: decodePowerThreshold(attr(attributes, endpoint, ATTR_POWER_THRESHOLD)),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2025-2026 Open Home Foundation
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { MatterNode } from "@matter-server/ws-client";
|
|
8
|
+
import { clusters } from "../client/models/descriptions.js";
|
|
9
|
+
import { asObject, pickArray, pickBoolean, pickNumber, pickString } from "./attribute-shapes.js";
|
|
10
|
+
import { computeActiveClusterFeatures } from "./cluster-features.js";
|
|
11
|
+
|
|
12
|
+
/** Thermostat cluster (Matter spec §4.3). */
|
|
13
|
+
export const THERMOSTAT_CLUSTER_ID = 513; // 0x0201
|
|
14
|
+
|
|
15
|
+
const ATTR_PRESETS = 0x50;
|
|
16
|
+
const ATTR_SCHEDULES = 0x51;
|
|
17
|
+
const ATTR_ACTIVE_SCHEDULE_HANDLE = 0x4f;
|
|
18
|
+
const ATTR_FEATURE_MAP = 0xfffc;
|
|
19
|
+
|
|
20
|
+
/** Days in display order (Mon..Sun) mapped to their ScheduleDayOfWeekBitmap bit (Sunday=0 .. Saturday=6). */
|
|
21
|
+
const DAY_BIT = [1, 2, 3, 4, 5, 6, 0];
|
|
22
|
+
export const DAY_LABELS = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
|
|
23
|
+
|
|
24
|
+
const SYSTEM_MODE_LABELS: Record<number, string> = {
|
|
25
|
+
0: "Off",
|
|
26
|
+
1: "Auto",
|
|
27
|
+
3: "Cool",
|
|
28
|
+
4: "Heat",
|
|
29
|
+
5: "Emergency Heat",
|
|
30
|
+
6: "Precooling",
|
|
31
|
+
7: "Fan Only",
|
|
32
|
+
8: "Dry",
|
|
33
|
+
9: "Sleep",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export interface ThermostatScheduleTransition {
|
|
37
|
+
dayOfWeek: number;
|
|
38
|
+
transitionTimeMin: number;
|
|
39
|
+
presetHandle: string | null;
|
|
40
|
+
systemMode: number | null;
|
|
41
|
+
coolingSetpoint: number | null;
|
|
42
|
+
heatingSetpoint: number | null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface ThermostatSchedule {
|
|
46
|
+
handle: string;
|
|
47
|
+
systemMode: number;
|
|
48
|
+
name: string | null;
|
|
49
|
+
presetHandle: string | null;
|
|
50
|
+
transitions: ThermostatScheduleTransition[];
|
|
51
|
+
builtIn: boolean | null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ThermostatPreset {
|
|
55
|
+
handle: string;
|
|
56
|
+
name: string | null;
|
|
57
|
+
coolingSetpoint: number | null;
|
|
58
|
+
heatingSetpoint: number | null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface DaySegment {
|
|
62
|
+
startMin: number;
|
|
63
|
+
endMin: number;
|
|
64
|
+
heatingSetpoint: number | null;
|
|
65
|
+
coolingSetpoint: number | null;
|
|
66
|
+
presetHandle: string | null;
|
|
67
|
+
systemMode: number | null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function readAttr(node: MatterNode, endpoint: number, attrId: number): unknown {
|
|
71
|
+
return node.attributes[`${endpoint}/${THERMOSTAT_CLUSTER_ID}/${attrId}`];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Struct attributes reach the dashboard through convertMatterToWebSocketTagBased, so fields are keyed
|
|
75
|
+
// by numeric field tag only — never by name, unlike the invoke/event converters.
|
|
76
|
+
function decodeTransition(raw: unknown): ThermostatScheduleTransition | null {
|
|
77
|
+
const obj = asObject(raw);
|
|
78
|
+
if (!obj) return null;
|
|
79
|
+
const dayOfWeek = pickNumber(obj, "0");
|
|
80
|
+
const transitionTimeMin = pickNumber(obj, "1");
|
|
81
|
+
if (
|
|
82
|
+
dayOfWeek === null ||
|
|
83
|
+
transitionTimeMin === null ||
|
|
84
|
+
!Number.isInteger(dayOfWeek) ||
|
|
85
|
+
dayOfWeek < 0 ||
|
|
86
|
+
dayOfWeek > 0x7f ||
|
|
87
|
+
!Number.isInteger(transitionTimeMin) ||
|
|
88
|
+
transitionTimeMin < 0 ||
|
|
89
|
+
transitionTimeMin >= 1440
|
|
90
|
+
) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
dayOfWeek,
|
|
95
|
+
transitionTimeMin,
|
|
96
|
+
presetHandle: pickString(obj, "2"),
|
|
97
|
+
systemMode: pickNumber(obj, "3"),
|
|
98
|
+
coolingSetpoint: pickNumber(obj, "4"),
|
|
99
|
+
heatingSetpoint: pickNumber(obj, "5"),
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function decodeSchedule(raw: unknown): ThermostatSchedule | null {
|
|
104
|
+
const obj = asObject(raw);
|
|
105
|
+
if (!obj) return null;
|
|
106
|
+
const handle = pickString(obj, "0");
|
|
107
|
+
const systemMode = pickNumber(obj, "1");
|
|
108
|
+
if (handle === null || systemMode === null) return null;
|
|
109
|
+
const transitions = pickArray(obj, "4")
|
|
110
|
+
.map(decodeTransition)
|
|
111
|
+
.filter((t): t is ThermostatScheduleTransition => t !== null);
|
|
112
|
+
return {
|
|
113
|
+
handle,
|
|
114
|
+
systemMode,
|
|
115
|
+
name: pickString(obj, "2"),
|
|
116
|
+
presetHandle: pickString(obj, "3"),
|
|
117
|
+
transitions,
|
|
118
|
+
builtIn: pickBoolean(obj, "5"),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function decodePreset(raw: unknown): ThermostatPreset | null {
|
|
123
|
+
const obj = asObject(raw);
|
|
124
|
+
if (!obj) return null;
|
|
125
|
+
const handle = pickString(obj, "0");
|
|
126
|
+
if (handle === null) return null;
|
|
127
|
+
return {
|
|
128
|
+
handle,
|
|
129
|
+
name: pickString(obj, "2"),
|
|
130
|
+
coolingSetpoint: pickNumber(obj, "3"),
|
|
131
|
+
heatingSetpoint: pickNumber(obj, "4"),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Whether the Thermostat cluster's FeatureMap includes MatterScheduleConfiguration (MSCH). */
|
|
136
|
+
export function isMSCHActive(node: MatterNode, endpoint: number): boolean {
|
|
137
|
+
const knownFeatures = Object.values(clusters[THERMOSTAT_CLUSTER_ID]?.features ?? {});
|
|
138
|
+
const featureMapValue = node.attributes[`${endpoint}/${THERMOSTAT_CLUSTER_ID}/${ATTR_FEATURE_MAP}`];
|
|
139
|
+
if (featureMapValue === undefined) return false;
|
|
140
|
+
return computeActiveClusterFeatures(featureMapValue, knownFeatures).some(feature => feature.code === "MSCH");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function readActiveScheduleHandle(node: MatterNode, endpoint: number): string | null {
|
|
144
|
+
const v = readAttr(node, endpoint, ATTR_ACTIVE_SCHEDULE_HANDLE);
|
|
145
|
+
return typeof v === "string" ? v : null;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** Decoded Schedules, or undefined when the attribute is not in the node's attribute cache. */
|
|
149
|
+
export function readSchedules(node: MatterNode, endpoint: number): ThermostatSchedule[] | undefined {
|
|
150
|
+
const raw = readAttr(node, endpoint, ATTR_SCHEDULES);
|
|
151
|
+
if (!Array.isArray(raw)) return undefined;
|
|
152
|
+
return raw.map(decodeSchedule).filter((s): s is ThermostatSchedule => s !== null);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Best-effort: only meaningful when the Presets (PRES) feature is supported, but harmless to read regardless. */
|
|
156
|
+
export function readPresets(node: MatterNode, endpoint: number): ThermostatPreset[] {
|
|
157
|
+
const raw = readAttr(node, endpoint, ATTR_PRESETS);
|
|
158
|
+
if (!Array.isArray(raw)) return [];
|
|
159
|
+
return raw.map(decodePreset).filter((p): p is ThermostatPreset => p !== null);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
interface ModeLabelSource {
|
|
163
|
+
presetHandle: string | null;
|
|
164
|
+
systemMode: number | null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Resolves a transition's (or day segment's) human label: matching preset name, else SystemMode, else a generic fallback. */
|
|
168
|
+
export function resolveTransitionLabel(transition: ModeLabelSource, presets: ThermostatPreset[]): string {
|
|
169
|
+
if (transition.presetHandle) {
|
|
170
|
+
const preset = presets.find(p => p.handle === transition.presetHandle);
|
|
171
|
+
if (preset?.name) return preset.name;
|
|
172
|
+
}
|
|
173
|
+
if (transition.systemMode !== null) {
|
|
174
|
+
return SYSTEM_MODE_LABELS[transition.systemMode] ?? `Mode ${transition.systemMode}`;
|
|
175
|
+
}
|
|
176
|
+
return "Setpoint";
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Resolves each transition's effective preset and setpoints by the §4.3.10.27 order of precedence: an own
|
|
181
|
+
* PresetHandle wins, else the transition's own setpoints, and only a transition providing neither falls
|
|
182
|
+
* through to the schedule's default PresetHandle. SystemMode always defaults to the schedule's (§4.3.10.26.2).
|
|
183
|
+
*/
|
|
184
|
+
export function resolveScheduleDefaults(schedule: ThermostatSchedule, presets: ThermostatPreset[]): ThermostatSchedule {
|
|
185
|
+
return {
|
|
186
|
+
...schedule,
|
|
187
|
+
transitions: schedule.transitions.map(t => {
|
|
188
|
+
const reportsSetpoint = t.heatingSetpoint !== null || t.coolingSetpoint !== null;
|
|
189
|
+
const presetHandle = t.presetHandle ?? (reportsSetpoint ? null : schedule.presetHandle);
|
|
190
|
+
const preset = presetHandle !== null ? presets.find(p => p.handle === presetHandle) : undefined;
|
|
191
|
+
return {
|
|
192
|
+
...t,
|
|
193
|
+
presetHandle,
|
|
194
|
+
systemMode: t.systemMode ?? schedule.systemMode,
|
|
195
|
+
coolingSetpoint: preset?.coolingSetpoint ?? t.coolingSetpoint,
|
|
196
|
+
heatingSetpoint: preset?.heatingSetpoint ?? t.heatingSetpoint,
|
|
197
|
+
};
|
|
198
|
+
}),
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Display-order (Mon..Sun) day indices a ScheduleDayOfWeekBitmap claims. */
|
|
203
|
+
function claimedDays(dayOfWeek: number): number[] {
|
|
204
|
+
return DAY_BIT.map((bit, day) => ((dayOfWeek & (1 << bit)) !== 0 ? day : -1)).filter(day => day >= 0);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** First claimed day in Mon..Sun display order; 7 when the bitmap claims none, so unclaimed rows sort last. */
|
|
208
|
+
export function firstClaimedDay(dayOfWeek: number): number {
|
|
209
|
+
return claimedDays(dayOfWeek)[0] ?? 7;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Mon..Sun day labels for a ScheduleDayOfWeekBitmap, consecutive runs compressed (e.g. "Mon–Wed, Fri"). */
|
|
213
|
+
export function formatDayOfWeek(dayOfWeek: number): string {
|
|
214
|
+
const days = claimedDays(dayOfWeek);
|
|
215
|
+
if (days.length === 0) return "—";
|
|
216
|
+
if (days.length === DAY_LABELS.length) return "Every day";
|
|
217
|
+
const parts = new Array<string>();
|
|
218
|
+
for (let start = 0; start < days.length;) {
|
|
219
|
+
let end = start;
|
|
220
|
+
while (end + 1 < days.length && days[end + 1] === days[end] + 1) end++;
|
|
221
|
+
if (end - start >= 2) {
|
|
222
|
+
parts.push(`${DAY_LABELS[days[start]]}–${DAY_LABELS[days[end]]}`);
|
|
223
|
+
} else {
|
|
224
|
+
for (let i = start; i <= end; i++) parts.push(DAY_LABELS[days[i]]);
|
|
225
|
+
}
|
|
226
|
+
start = end + 1;
|
|
227
|
+
}
|
|
228
|
+
return parts.join(", ");
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Row order for the transitions list: by first claimed day in Mon..Sun display order, then by time. */
|
|
232
|
+
export function compareTransitionsForDisplay(a: ThermostatScheduleTransition, b: ThermostatScheduleTransition): number {
|
|
233
|
+
return firstClaimedDay(a.dayOfWeek) - firstClaimedDay(b.dayOfWeek) || a.transitionTimeMin - b.transitionTimeMin;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
function transitionsForDay(schedule: ThermostatSchedule, day: number): ThermostatScheduleTransition[] {
|
|
237
|
+
const bit = DAY_BIT[day];
|
|
238
|
+
return schedule.transitions
|
|
239
|
+
.filter(t => (t.dayOfWeek & (1 << bit)) !== 0)
|
|
240
|
+
.sort((a, b) => a.transitionTimeMin - b.transitionTimeMin);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function segmentOf(t: ThermostatScheduleTransition, startMin: number, endMin: number): DaySegment {
|
|
244
|
+
return {
|
|
245
|
+
startMin,
|
|
246
|
+
endMin,
|
|
247
|
+
heatingSetpoint: t.heatingSetpoint,
|
|
248
|
+
coolingSetpoint: t.coolingSetpoint,
|
|
249
|
+
presetHandle: t.presetHandle,
|
|
250
|
+
systemMode: t.systemMode,
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function findCarryOverTransition(schedule: ThermostatSchedule, day: number): ThermostatScheduleTransition | undefined {
|
|
255
|
+
for (let back = 1; back < DAY_LABELS.length; back++) {
|
|
256
|
+
const previous = transitionsForDay(schedule, (day + DAY_LABELS.length - back) % DAY_LABELS.length);
|
|
257
|
+
if (previous.length > 0) return previous[previous.length - 1];
|
|
258
|
+
}
|
|
259
|
+
return undefined;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Ordered, gap-free setpoint segments covering one day (0-1440 min) of a schedule. Per cluster
|
|
264
|
+
* §4.3.10.26.5 the band before the day's first transition carries the last transition of the most
|
|
265
|
+
* recent earlier day the schedule covers.
|
|
266
|
+
*/
|
|
267
|
+
export function buildDaySegments(schedule: ThermostatSchedule, day: number): DaySegment[] {
|
|
268
|
+
const dayTransitions = transitionsForDay(schedule, day);
|
|
269
|
+
const segments = new Array<DaySegment>();
|
|
270
|
+
if (dayTransitions.length === 0) return segments;
|
|
271
|
+
|
|
272
|
+
const first = dayTransitions[0];
|
|
273
|
+
if (first.transitionTimeMin > 0) {
|
|
274
|
+
const carried = findCarryOverTransition(schedule, day) ?? dayTransitions[dayTransitions.length - 1];
|
|
275
|
+
segments.push(segmentOf(carried, 0, first.transitionTimeMin));
|
|
276
|
+
}
|
|
277
|
+
for (let i = 0; i < dayTransitions.length; i++) {
|
|
278
|
+
const t = dayTransitions[i];
|
|
279
|
+
segments.push(
|
|
280
|
+
segmentOf(
|
|
281
|
+
t,
|
|
282
|
+
t.transitionTimeMin,
|
|
283
|
+
i + 1 < dayTransitions.length ? dayTransitions[i + 1].transitionTimeMin : 1440,
|
|
284
|
+
),
|
|
285
|
+
);
|
|
286
|
+
}
|
|
287
|
+
return segments;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Matter "temperature" values are int16 hundredths of a degree Celsius. */
|
|
291
|
+
export function formatSetpoint(centidegrees: number | undefined | null): string | undefined {
|
|
292
|
+
if (centidegrees === undefined || centidegrees === null) return undefined;
|
|
293
|
+
return `${(centidegrees / 100).toFixed(1)}°C`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function formatMinutes(min: number): string {
|
|
297
|
+
return `${String(Math.floor(min / 60)).padStart(2, "0")}:${String(min % 60).padStart(2, "0")}`;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Hover text for a grid segment: its time span, label, and any setpoints — for a native `title` tooltip. */
|
|
301
|
+
export function formatSegmentTooltip(seg: DaySegment, presets: ThermostatPreset[]): string {
|
|
302
|
+
const lines = [
|
|
303
|
+
`${formatMinutes(seg.startMin)}–${formatMinutes(seg.endMin)} · ${resolveTransitionLabel(seg, presets)}`,
|
|
304
|
+
];
|
|
305
|
+
if (seg.heatingSetpoint !== null) lines.push(`Heat ${formatSetpoint(seg.heatingSetpoint)}`);
|
|
306
|
+
if (seg.coolingSetpoint !== null) lines.push(`Cool ${formatSetpoint(seg.coolingSetpoint)}`);
|
|
307
|
+
return lines.join("\n");
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
export type ScheduleColorMode = "heat" | "cool";
|
|
311
|
+
|
|
312
|
+
interface SetpointPair {
|
|
313
|
+
heatingSetpoint: number | null;
|
|
314
|
+
coolingSetpoint: number | null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** The setpoint driving a segment's color, falling back to the other mode's when the selected one is absent. */
|
|
318
|
+
export function pickSetpointForMode(seg: SetpointPair, mode: ScheduleColorMode): number | null {
|
|
319
|
+
return mode === "heat"
|
|
320
|
+
? (seg.heatingSetpoint ?? seg.coolingSetpoint)
|
|
321
|
+
: (seg.coolingSetpoint ?? seg.heatingSetpoint);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Heat and cool setpoints occupy disjoint value bands, so the range covers only the selected mode's setpoints. */
|
|
325
|
+
export function computeSetpointRange(
|
|
326
|
+
schedule: ThermostatSchedule,
|
|
327
|
+
mode: ScheduleColorMode,
|
|
328
|
+
): { min: number; max: number } | undefined {
|
|
329
|
+
const values = schedule.transitions.map(t => pickSetpointForMode(t, mode)).filter((v): v is number => v !== null);
|
|
330
|
+
if (values.length === 0) return undefined;
|
|
331
|
+
return { min: Math.min(...values), max: Math.max(...values) };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/** Clamped 0-100 position of `value` within [min, max], for driving a cold->hot color-mix gradient. */
|
|
335
|
+
export function setpointColorMixPercent(value: number, min: number, max: number): number {
|
|
336
|
+
if (max <= min) return 50;
|
|
337
|
+
return Math.min(100, Math.max(0, ((value - min) / (max - min)) * 100));
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function decodeHandleBytes(base64: string): Uint8Array {
|
|
341
|
+
const binary = atob(base64);
|
|
342
|
+
const bytes = new Uint8Array(binary.length);
|
|
343
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
344
|
+
return bytes;
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/** Short hex label for a base64-encoded schedule/preset handle (e.g. a single-byte handle -> "0x01"). */
|
|
348
|
+
export function formatHandleShort(handle: string | null): string {
|
|
349
|
+
if (!handle) return "";
|
|
350
|
+
try {
|
|
351
|
+
const bytes = decodeHandleBytes(handle);
|
|
352
|
+
return `0x${Array.from(bytes)
|
|
353
|
+
.map(b => b.toString(16).padStart(2, "0"))
|
|
354
|
+
.join("")
|
|
355
|
+
.toUpperCase()}`;
|
|
356
|
+
} catch {
|
|
357
|
+
return handle.slice(0, 8);
|
|
358
|
+
}
|
|
359
|
+
}
|