matterbridge-example-dynamic-platform 1.1.8 → 1.2.0-edge.10
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/CHANGELOG.md +61 -14
- package/README.md +8 -2
- package/bmc-button.svg +22 -0
- package/dist/appliances.js +530 -0
- package/dist/platform.js +588 -251
- package/dist/robot.js +215 -0
- package/matterbridge-example-dynamic-platform.config.json +2 -0
- package/matterbridge-example-dynamic-platform.schema.json +27 -2
- package/matterbridge.svg +50 -0
- package/npm-shrinkwrap.json +2 -2
- package/package.json +2 -1
- package/tsconfig.jest.json +8 -0
@@ -0,0 +1,530 @@
|
|
1
|
+
import { MatterbridgeEndpoint, MatterbridgeServer, MatterbridgeOnOffServer, RefrigeratorTag, PositionTag, laundryWasher, laundryDryer, dishwasher, refrigerator, temperatureControlledCabinetCooler, oven, temperatureControlledCabinetHeater, microwaveOven, extractorHood, cooktop, cookSurface, } from 'matterbridge';
|
2
|
+
import { ClusterBehavior } from 'matterbridge/matter';
|
3
|
+
import { OperationalState, TemperatureControl, DishwasherMode, LaundryWasherControls, LaundryWasherMode, LaundryDryerControls, OvenMode, ModeBase, RefrigeratorAndTemperatureControlledCabinetMode, MicrowaveOvenMode, MicrowaveOvenControl, OvenCavityOperationalState, } from 'matterbridge/matter/clusters';
|
4
|
+
import { DishwasherAlarmServer, LaundryDryerControlsServer, LaundryWasherControlsServer, MicrowaveOvenControlBehavior, MicrowaveOvenModeServer, OperationalStateBehavior, TemperatureControlBehavior, } from 'matterbridge/matter/behaviors';
|
5
|
+
export class Appliances extends MatterbridgeEndpoint {
|
6
|
+
constructor(deviceType, name, serial) {
|
7
|
+
super(deviceType, { uniqueStorageKey: `${name}-${serial}` }, true);
|
8
|
+
if (deviceType.code === laundryWasher.code) {
|
9
|
+
this.createDefaultIdentifyClusterServer();
|
10
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Laundry Washer');
|
11
|
+
this.createDeadFrontOnOffClusterServer();
|
12
|
+
this.createLevelTemperatureControlClusterServer(3, ['Cold', '30°', '40°', '60°', '80°']);
|
13
|
+
this.createDefaultLaundryWasherModeClusterServer();
|
14
|
+
this.createSpinLaundryWasherControlsClusterServer(3, ['400', '800', '1200', '1600']);
|
15
|
+
this.createDefaultOperationalStateClusterServer(OperationalState.OperationalStateEnum.Stopped);
|
16
|
+
}
|
17
|
+
else if (deviceType.code === laundryDryer.code) {
|
18
|
+
this.createDefaultIdentifyClusterServer();
|
19
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Laundry Dryer');
|
20
|
+
this.createDeadFrontOnOffClusterServer();
|
21
|
+
this.createLevelTemperatureControlClusterServer(3, ['Cold', '30°', '40°', '60°', '80°']);
|
22
|
+
this.createDefaultLaundryWasherModeClusterServer();
|
23
|
+
this.createDefaultLaundryDryerControlsClusterServer(1);
|
24
|
+
this.createDefaultOperationalStateClusterServer(OperationalState.OperationalStateEnum.Stopped);
|
25
|
+
}
|
26
|
+
else if (deviceType.code === dishwasher.code) {
|
27
|
+
this.createDefaultIdentifyClusterServer();
|
28
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Dishwasher');
|
29
|
+
this.createDeadFrontOnOffClusterServer();
|
30
|
+
this.createLevelTemperatureControlClusterServer(1, ['Cold', '30°', '40°', '60°']);
|
31
|
+
this.createDefaultDishwasherModeClusterServer();
|
32
|
+
this.createDefaultDishwasherAlarmClusterServer();
|
33
|
+
this.createDefaultOperationalStateClusterServer(OperationalState.OperationalStateEnum.Stopped);
|
34
|
+
}
|
35
|
+
else if (deviceType.name === refrigerator.name) {
|
36
|
+
this.createDefaultIdentifyClusterServer();
|
37
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Refrigerator');
|
38
|
+
const refrigerator = this.addChildDeviceType('Refrigerator', temperatureControlledCabinetCooler, { tagList: [{ mfgCode: null, namespaceId: RefrigeratorTag.Refrigerator.namespaceId, tag: RefrigeratorTag.Refrigerator.tag, label: RefrigeratorTag.Refrigerator.label }] }, true);
|
39
|
+
refrigerator.log.logName = `Refrigerator (cabinet Refrigerator)`;
|
40
|
+
refrigerator.createDefaultIdentifyClusterServer();
|
41
|
+
Appliances.createLevelTemperatureControlClusterServer(refrigerator, 2, ['Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5']);
|
42
|
+
refrigerator.createDefaultTemperatureMeasurementClusterServer(1000);
|
43
|
+
Appliances.createDefaultRefrigeratorAndTemperatureControlledCabinetModeClusterServer(refrigerator, 1);
|
44
|
+
const freezer = this.addChildDeviceType('Freezer', temperatureControlledCabinetCooler, { tagList: [{ mfgCode: null, namespaceId: RefrigeratorTag.Freezer.namespaceId, tag: RefrigeratorTag.Freezer.tag, label: RefrigeratorTag.Freezer.label }] }, true);
|
45
|
+
freezer.log.logName = `Refrigerator (cabinet Freezer)`;
|
46
|
+
freezer.createDefaultIdentifyClusterServer();
|
47
|
+
Appliances.createLevelTemperatureControlClusterServer(freezer, 2, ['Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5']);
|
48
|
+
freezer.createDefaultTemperatureMeasurementClusterServer(-2000);
|
49
|
+
Appliances.createDefaultRefrigeratorAndTemperatureControlledCabinetModeClusterServer(freezer, 1);
|
50
|
+
}
|
51
|
+
else if (deviceType.name === oven.name) {
|
52
|
+
this.createDefaultIdentifyClusterServer();
|
53
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Oven');
|
54
|
+
const cabinettop = this.addChildDeviceType('Oven (top)', temperatureControlledCabinetHeater, { tagList: [{ mfgCode: null, namespaceId: PositionTag.Top.namespaceId, tag: PositionTag.Top.tag, label: PositionTag.Top.label }] }, true);
|
55
|
+
cabinettop.log.logName = `Oven (top)`;
|
56
|
+
cabinettop.createDefaultIdentifyClusterServer();
|
57
|
+
Appliances.createLevelTemperatureControlClusterServer(cabinettop, 2, ['Defrost', '180°', '200°', '250°', '300°']);
|
58
|
+
cabinettop.createDefaultTemperatureMeasurementClusterServer(20000);
|
59
|
+
Appliances.createDefaultOvenModeClusterServer(cabinettop, 1);
|
60
|
+
const cabinetbottom = this.addChildDeviceType('Oven (bottom)', temperatureControlledCabinetHeater, { tagList: [{ mfgCode: null, namespaceId: PositionTag.Bottom.namespaceId, tag: PositionTag.Bottom.tag, label: PositionTag.Bottom.label }] }, true);
|
61
|
+
cabinetbottom.log.logName = `Oven (bottom)`;
|
62
|
+
cabinetbottom.createDefaultIdentifyClusterServer();
|
63
|
+
Appliances.createLevelTemperatureControlClusterServer(cabinetbottom, 2, ['Defrost', '180°', '200°', '250°', '300°']);
|
64
|
+
cabinetbottom.createDefaultTemperatureMeasurementClusterServer(30000);
|
65
|
+
Appliances.createDefaultOvenModeClusterServer(cabinetbottom, 1);
|
66
|
+
}
|
67
|
+
else if (deviceType.name === microwaveOven.name) {
|
68
|
+
this.createDefaultIdentifyClusterServer();
|
69
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Microwave Oven');
|
70
|
+
this.createDefaultOperationalStateClusterServer(OperationalState.OperationalStateEnum.Stopped);
|
71
|
+
this.createDefaultMicrowaveOvenModeClusterServer();
|
72
|
+
this.createDefaultMicrowaveOvenControlClusterServer();
|
73
|
+
}
|
74
|
+
else if (deviceType.name === extractorHood.name) {
|
75
|
+
this.createDefaultIdentifyClusterServer();
|
76
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Extractor Hood');
|
77
|
+
this.createBaseFanControlClusterServer();
|
78
|
+
this.createDefaultHepaFilterMonitoringClusterServer();
|
79
|
+
this.createDefaultActivatedCarbonFilterMonitoringClusterServer();
|
80
|
+
}
|
81
|
+
else if (deviceType.name === cooktop.name) {
|
82
|
+
this.createDefaultIdentifyClusterServer();
|
83
|
+
this.createDefaultBasicInformationClusterServer(name, serial, 0xfff1, 'Matterbridge', 0x8000, 'Cooktop');
|
84
|
+
this.createOffOnlyOnOffClusterServer(true);
|
85
|
+
const cookSurface1 = this.addChildDeviceType('Surface 1', cookSurface, { tagList: [{ mfgCode: null, namespaceId: PositionTag.Left.namespaceId, tag: PositionTag.Left.tag, label: PositionTag.Left.label }] }, true);
|
86
|
+
cookSurface1.log.logName = `Cook surface (right)`;
|
87
|
+
cookSurface1.createDefaultIdentifyClusterServer();
|
88
|
+
Appliances.createLevelTemperatureControlClusterServer(cookSurface1, 2, ['Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5']);
|
89
|
+
cookSurface1.createDefaultTemperatureMeasurementClusterServer(10000);
|
90
|
+
cookSurface1.createOffOnlyOnOffClusterServer(true);
|
91
|
+
const cookSurface2 = this.addChildDeviceType('Surface 2', cookSurface, { tagList: [{ mfgCode: null, namespaceId: PositionTag.Right.namespaceId, tag: PositionTag.Right.tag, label: PositionTag.Right.label }] }, true);
|
92
|
+
cookSurface2.log.logName = `Cook surface (left)`;
|
93
|
+
cookSurface2.createDefaultIdentifyClusterServer();
|
94
|
+
Appliances.createLevelTemperatureControlClusterServer(cookSurface2, 3, ['Level 1', 'Level 2', 'Level 3', 'Level 4', 'Level 5']);
|
95
|
+
cookSurface2.createDefaultTemperatureMeasurementClusterServer(12000);
|
96
|
+
cookSurface2.createOffOnlyOnOffClusterServer(true);
|
97
|
+
this.eventsOf(MatterbridgeOnOffServer).onOff$Changed.on(async (value) => {
|
98
|
+
if (!value) {
|
99
|
+
this.log.notice('Turning off all cook surfaces');
|
100
|
+
await cookSurface1.setStateOf(MatterbridgeOnOffServer, { onOff: false });
|
101
|
+
await cookSurface2.setStateOf(MatterbridgeOnOffServer, { onOff: false });
|
102
|
+
}
|
103
|
+
});
|
104
|
+
}
|
105
|
+
}
|
106
|
+
createDefaultOperationalStateClusterServer(operationalState = OperationalState.OperationalStateEnum.Stopped) {
|
107
|
+
this.behaviors.require(MatterbridgeOperationalStateServer, {
|
108
|
+
phaseList: [],
|
109
|
+
currentPhase: null,
|
110
|
+
operationalStateList: [
|
111
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Stopped, operationalStateLabel: 'Stopped' },
|
112
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Running, operationalStateLabel: 'Running' },
|
113
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Paused, operationalStateLabel: 'Paused' },
|
114
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Error, operationalStateLabel: 'Error' },
|
115
|
+
],
|
116
|
+
operationalState,
|
117
|
+
operationalError: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
118
|
+
});
|
119
|
+
return this;
|
120
|
+
}
|
121
|
+
createDefaultOvenCavityOperationalStateClusterServer(operationalState = OperationalState.OperationalStateEnum.Stopped) {
|
122
|
+
this.behaviors.require(OvenCavityOperationalStateServer, {
|
123
|
+
phaseList: [],
|
124
|
+
currentPhase: null,
|
125
|
+
operationalStateList: [
|
126
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Stopped, operationalStateLabel: 'Stopped' },
|
127
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Running, operationalStateLabel: 'Running' },
|
128
|
+
{ operationalStateId: OperationalState.OperationalStateEnum.Error, operationalStateLabel: 'Error' },
|
129
|
+
],
|
130
|
+
operationalState,
|
131
|
+
operationalError: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
132
|
+
});
|
133
|
+
return this;
|
134
|
+
}
|
135
|
+
static createDefaultRefrigeratorAndTemperatureControlledCabinetModeClusterServer(endpoint, currentMode) {
|
136
|
+
endpoint.behaviors.require(RefrigeratorAndTemperatureControlledCabinetModeServer, {
|
137
|
+
supportedModes: [
|
138
|
+
{ label: 'Auto', mode: 0, modeTags: [{ value: RefrigeratorAndTemperatureControlledCabinetMode.ModeTag.Auto }] },
|
139
|
+
{ label: 'RapidCool', mode: 1, modeTags: [{ value: RefrigeratorAndTemperatureControlledCabinetMode.ModeTag.RapidCool }] },
|
140
|
+
{ label: 'RapidFreeze', mode: 2, modeTags: [{ value: RefrigeratorAndTemperatureControlledCabinetMode.ModeTag.RapidFreeze }] },
|
141
|
+
],
|
142
|
+
currentMode,
|
143
|
+
});
|
144
|
+
return endpoint;
|
145
|
+
}
|
146
|
+
static createDefaultOvenModeClusterServer(endpoint, currentMode) {
|
147
|
+
endpoint.behaviors.require(OvenModeServer, {
|
148
|
+
supportedModes: [
|
149
|
+
{ label: 'Bake', mode: 1, modeTags: [{ value: OvenMode.ModeTag.Bake }] },
|
150
|
+
{ label: 'Convection', mode: 2, modeTags: [{ value: OvenMode.ModeTag.Convection }] },
|
151
|
+
{ label: 'Grill', mode: 3, modeTags: [{ value: OvenMode.ModeTag.Grill }] },
|
152
|
+
{ label: 'Roast', mode: 4, modeTags: [{ value: OvenMode.ModeTag.Roast }] },
|
153
|
+
{ label: 'Clean', mode: 5, modeTags: [{ value: OvenMode.ModeTag.Clean }] },
|
154
|
+
{ label: 'Convection Bake', mode: 6, modeTags: [{ value: OvenMode.ModeTag.ConvectionBake }] },
|
155
|
+
{ label: 'Convection Roast', mode: 7, modeTags: [{ value: OvenMode.ModeTag.ConvectionRoast }] },
|
156
|
+
{ label: 'Warming', mode: 8, modeTags: [{ value: OvenMode.ModeTag.Warming }] },
|
157
|
+
{ label: 'Proofing', mode: 9, modeTags: [{ value: OvenMode.ModeTag.Proofing }] },
|
158
|
+
{ label: 'Steam', mode: 10, modeTags: [{ value: OvenMode.ModeTag.Steam }] },
|
159
|
+
],
|
160
|
+
currentMode,
|
161
|
+
});
|
162
|
+
return endpoint;
|
163
|
+
}
|
164
|
+
createDefaultDishwasherModeClusterServer(currentMode) {
|
165
|
+
this.behaviors.require(DishwasherModeServer, {
|
166
|
+
supportedModes: [
|
167
|
+
{ label: 'Light', mode: 1, modeTags: [{ value: DishwasherMode.ModeTag.Light }] },
|
168
|
+
{ label: 'Normal', mode: 2, modeTags: [{ value: DishwasherMode.ModeTag.Normal }] },
|
169
|
+
{ label: 'Heavy', mode: 3, modeTags: [{ value: DishwasherMode.ModeTag.Heavy }] },
|
170
|
+
],
|
171
|
+
currentMode,
|
172
|
+
});
|
173
|
+
return this;
|
174
|
+
}
|
175
|
+
createDefaultLaundryWasherModeClusterServer(currentMode) {
|
176
|
+
this.behaviors.require(LaundryWasherModeServer, {
|
177
|
+
supportedModes: [
|
178
|
+
{ label: 'Delicate', mode: 1, modeTags: [{ value: LaundryWasherMode.ModeTag.Delicate }] },
|
179
|
+
{ label: 'Normal', mode: 2, modeTags: [{ value: LaundryWasherMode.ModeTag.Normal }] },
|
180
|
+
{ label: 'Heavy', mode: 3, modeTags: [{ value: LaundryWasherMode.ModeTag.Heavy }] },
|
181
|
+
{ label: 'Whites', mode: 4, modeTags: [{ value: LaundryWasherMode.ModeTag.Whites }] },
|
182
|
+
],
|
183
|
+
currentMode,
|
184
|
+
});
|
185
|
+
return this;
|
186
|
+
}
|
187
|
+
createDefaultMicrowaveOvenModeClusterServer(currentMode, supportedModes) {
|
188
|
+
this.behaviors.require(MicrowaveOvenModeServer, {
|
189
|
+
supportedModes: supportedModes ?? [
|
190
|
+
{ label: 'Auto', mode: 1, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Auto }] },
|
191
|
+
{ label: 'Quick', mode: 2, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Quick }] },
|
192
|
+
{ label: 'Quiet', mode: 3, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Quiet }] },
|
193
|
+
{ label: 'Min', mode: 4, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Min }] },
|
194
|
+
{ label: 'Max', mode: 5, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Max }] },
|
195
|
+
{ label: 'Normal', mode: 6, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Normal }] },
|
196
|
+
{ label: 'Defrost', mode: 7, modeTags: [{ value: MicrowaveOvenMode.ModeTag.Defrost }] },
|
197
|
+
],
|
198
|
+
currentMode: currentMode ?? 1,
|
199
|
+
});
|
200
|
+
return this;
|
201
|
+
}
|
202
|
+
createDefaultMicrowaveOvenControlClusterServer(selectedWattIndex = 5, supportedWatts = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000], cookTime = 60, maxCookTime = 3600) {
|
203
|
+
this.behaviors.require(MatterbridgeMicrowaveOvenControlServer.with(MicrowaveOvenControl.Feature.PowerInWatts), {
|
204
|
+
supportedWatts,
|
205
|
+
selectedWattIndex,
|
206
|
+
cookTime,
|
207
|
+
maxCookTime,
|
208
|
+
});
|
209
|
+
return this;
|
210
|
+
}
|
211
|
+
createSpinLaundryWasherControlsClusterServer(spinSpeedCurrent, spinSpeeds) {
|
212
|
+
this.behaviors.require(LaundryWasherControlsServer.with(LaundryWasherControls.Feature.Spin), {
|
213
|
+
spinSpeeds: spinSpeeds ?? ['400', '800', '1200', '1600'],
|
214
|
+
spinSpeedCurrent,
|
215
|
+
});
|
216
|
+
return this;
|
217
|
+
}
|
218
|
+
createRinseLaundryWasherControlsClusterServer(numberOfRinses, supportedRinses) {
|
219
|
+
this.behaviors.require(LaundryWasherControlsServer.with(LaundryWasherControls.Feature.Rinse), {
|
220
|
+
supportedRinses: supportedRinses ?? [
|
221
|
+
LaundryWasherControls.NumberOfRinses.None,
|
222
|
+
LaundryWasherControls.NumberOfRinses.Normal,
|
223
|
+
LaundryWasherControls.NumberOfRinses.Extra,
|
224
|
+
LaundryWasherControls.NumberOfRinses.Max,
|
225
|
+
],
|
226
|
+
numberOfRinses,
|
227
|
+
});
|
228
|
+
return this;
|
229
|
+
}
|
230
|
+
createDefaultLaundryDryerControlsClusterServer(selectedDrynessLevel, supportedDrynessLevels) {
|
231
|
+
this.behaviors.require(LaundryDryerControlsServer, {
|
232
|
+
supportedDrynessLevels: supportedDrynessLevels ?? [
|
233
|
+
LaundryDryerControls.DrynessLevel.Low,
|
234
|
+
LaundryDryerControls.DrynessLevel.Normal,
|
235
|
+
LaundryDryerControls.DrynessLevel.Extra,
|
236
|
+
LaundryDryerControls.DrynessLevel.Max,
|
237
|
+
],
|
238
|
+
selectedDrynessLevel,
|
239
|
+
});
|
240
|
+
return this;
|
241
|
+
}
|
242
|
+
createDefaultDishwasherAlarmClusterServer() {
|
243
|
+
this.behaviors.require(DishwasherAlarmServer, {
|
244
|
+
mask: { inflowError: true, drainError: true, doorError: true, tempTooLow: true, tempTooHigh: true, waterLevelError: true },
|
245
|
+
state: { inflowError: false, drainError: false, doorError: false, tempTooLow: false, tempTooHigh: false, waterLevelError: false },
|
246
|
+
supported: { inflowError: true, drainError: true, doorError: true, tempTooLow: true, tempTooHigh: true, waterLevelError: true },
|
247
|
+
});
|
248
|
+
return this;
|
249
|
+
}
|
250
|
+
createLevelTemperatureControlClusterServer(selectedTemperatureLevel = 1, supportedTemperatureLevels = ['Cold', 'Warm', 'Hot']) {
|
251
|
+
this.behaviors.require(MatterbridgeLevelTemperatureControlServer.with(TemperatureControl.Feature.TemperatureLevel), {
|
252
|
+
selectedTemperatureLevel,
|
253
|
+
supportedTemperatureLevels,
|
254
|
+
});
|
255
|
+
return this;
|
256
|
+
}
|
257
|
+
static createLevelTemperatureControlClusterServer(endpoint, selectedTemperatureLevel = 1, supportedTemperatureLevels = ['Cold', 'Warm', 'Hot']) {
|
258
|
+
endpoint.behaviors.require(MatterbridgeLevelTemperatureControlServer.with(TemperatureControl.Feature.TemperatureLevel), {
|
259
|
+
selectedTemperatureLevel,
|
260
|
+
supportedTemperatureLevels,
|
261
|
+
});
|
262
|
+
return endpoint;
|
263
|
+
}
|
264
|
+
createNumberTemperatureControlClusterServer(temperatureSetpoint, minTemperature, maxTemperature, step = 1) {
|
265
|
+
this.behaviors.require(MatterbridgeNumberTemperatureControlServer.with(TemperatureControl.Feature.TemperatureNumber, TemperatureControl.Feature.TemperatureStep), {
|
266
|
+
temperatureSetpoint,
|
267
|
+
minTemperature,
|
268
|
+
maxTemperature,
|
269
|
+
step,
|
270
|
+
});
|
271
|
+
return this;
|
272
|
+
}
|
273
|
+
static createNumberTemperatureControlClusterServer(endpoint, temperatureSetpoint, minTemperature, maxTemperature, step = 1) {
|
274
|
+
endpoint.behaviors.require(MatterbridgeNumberTemperatureControlServer.with(TemperatureControl.Feature.TemperatureNumber, TemperatureControl.Feature.TemperatureStep), {
|
275
|
+
temperatureSetpoint,
|
276
|
+
minTemperature,
|
277
|
+
maxTemperature,
|
278
|
+
step,
|
279
|
+
});
|
280
|
+
return endpoint;
|
281
|
+
}
|
282
|
+
}
|
283
|
+
class MatterbridgeOperationalStateServer extends OperationalStateBehavior {
|
284
|
+
initialize() {
|
285
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
286
|
+
device.log.info('MatterbridgeOperationalStateServer initialized: setting operational state to Stopped');
|
287
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
|
288
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
289
|
+
}
|
290
|
+
pause() {
|
291
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
292
|
+
device.log.info('MatterbridgeOperationalStateServer: pause called setting operational state to Paused');
|
293
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Paused;
|
294
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
295
|
+
return {
|
296
|
+
commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
297
|
+
};
|
298
|
+
}
|
299
|
+
stop() {
|
300
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
301
|
+
device.log.info('MatterbridgeOperationalStateServer: stop called setting operational state to Stopped');
|
302
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
|
303
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
304
|
+
return {
|
305
|
+
commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
306
|
+
};
|
307
|
+
}
|
308
|
+
start() {
|
309
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
310
|
+
device.log.info('MatterbridgeOperationalStateServer: start called setting operational state to Running');
|
311
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Running;
|
312
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
313
|
+
return {
|
314
|
+
commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
315
|
+
};
|
316
|
+
}
|
317
|
+
resume() {
|
318
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
319
|
+
device.log.info('MatterbridgeOperationalStateServer: resume called setting operational state to Running');
|
320
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Running;
|
321
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
322
|
+
return {
|
323
|
+
commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
324
|
+
};
|
325
|
+
}
|
326
|
+
}
|
327
|
+
class MatterbridgeLevelTemperatureControlServer extends TemperatureControlBehavior.with(TemperatureControl.Feature.TemperatureLevel) {
|
328
|
+
initialize() {
|
329
|
+
if (this.state.supportedTemperatureLevels.length >= 2) {
|
330
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
331
|
+
device.log.info('MatterbridgeLevelTemperatureControlServer initialized');
|
332
|
+
}
|
333
|
+
}
|
334
|
+
setTemperature(request) {
|
335
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
336
|
+
if (request.targetTemperatureLevel !== undefined && request.targetTemperatureLevel >= 0 && request.targetTemperatureLevel < this.state.supportedTemperatureLevels.length) {
|
337
|
+
device.log.info(`MatterbridgeLevelTemperatureControlServer: setTemperature called setting selectedTemperatureLevel to ${request.targetTemperatureLevel}: ${this.state.supportedTemperatureLevels[request.targetTemperatureLevel]}`);
|
338
|
+
this.state.selectedTemperatureLevel = request.targetTemperatureLevel;
|
339
|
+
}
|
340
|
+
else {
|
341
|
+
device.log.error(`MatterbridgeLevelTemperatureControlServer: setTemperature called with invalid targetTemperatureLevel ${request.targetTemperatureLevel}`);
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}
|
345
|
+
class MatterbridgeNumberTemperatureControlServer extends TemperatureControlBehavior.with(TemperatureControl.Feature.TemperatureNumber) {
|
346
|
+
initialize() {
|
347
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
348
|
+
device.log.info('MatterbridgeNumberTemperatureControlServer initialized');
|
349
|
+
}
|
350
|
+
setTemperature(request) {
|
351
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
352
|
+
if (request.targetTemperature !== undefined && request.targetTemperature >= this.state.minTemperature && request.targetTemperature <= this.state.maxTemperature) {
|
353
|
+
device.log.info(`MatterbridgeNumberTemperatureControlServer: setTemperature called setting temperatureSetpoint to ${request.targetTemperature}`);
|
354
|
+
this.state.temperatureSetpoint = request.targetTemperature;
|
355
|
+
}
|
356
|
+
else {
|
357
|
+
device.log.error(`MatterbridgeNumberTemperatureControlServer: setTemperature called with invalid targetTemperature ${request.targetTemperature}`);
|
358
|
+
}
|
359
|
+
}
|
360
|
+
}
|
361
|
+
class MatterbridgeMicrowaveOvenControlServer extends MicrowaveOvenControlBehavior.with(MicrowaveOvenControl.Feature.PowerInWatts) {
|
362
|
+
initialize() {
|
363
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
364
|
+
device.log.info('MatterbridgeMicrowaveOvenControlServer initialized');
|
365
|
+
}
|
366
|
+
setCookingParameters(request) {
|
367
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
368
|
+
if (request.cookMode !== undefined) {
|
369
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: setCookingParameters called setting cookMode to ${request.cookMode}`);
|
370
|
+
this.endpoint.setStateOf(MicrowaveOvenModeServer, { currentMode: request.cookMode });
|
371
|
+
}
|
372
|
+
else {
|
373
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: setCookingParameters called with no cookMode so set to Normal`);
|
374
|
+
this.endpoint.setStateOf(MicrowaveOvenModeServer, { currentMode: 6 });
|
375
|
+
}
|
376
|
+
if (request.cookTime !== undefined && request.cookTime >= 0 && request.cookTime <= this.state.maxCookTime) {
|
377
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: setCookingParameters called setting cookTime to ${request.cookTime}`);
|
378
|
+
this.state.cookTime = request.cookTime;
|
379
|
+
}
|
380
|
+
else {
|
381
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: setCookingParameters called with no cookTime so set to 30sec.`);
|
382
|
+
this.state.cookTime = 30;
|
383
|
+
}
|
384
|
+
if (request.wattSettingIndex !== undefined && request.wattSettingIndex >= 0 && request.wattSettingIndex < this.state.supportedWatts.length) {
|
385
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: setCookingParameters called setting selectedWattIndex to ${request.wattSettingIndex}`);
|
386
|
+
this.state.selectedWattIndex = request.wattSettingIndex;
|
387
|
+
}
|
388
|
+
else {
|
389
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: setCookingParameters called with no wattSettingIndex so set to the highest Watt setting for the selected CookMode`);
|
390
|
+
this.state.selectedWattIndex = this.state.supportedWatts.length - 1;
|
391
|
+
}
|
392
|
+
}
|
393
|
+
addMoreTime(request) {
|
394
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
395
|
+
if (request.timeToAdd !== undefined && request.timeToAdd >= 0) {
|
396
|
+
device.log.info(`MatterbridgeMicrowaveOvenControlServer: addMoreTime called setting cookTime to ${this.state.cookTime + request.timeToAdd}`);
|
397
|
+
this.state.cookTime += request.timeToAdd;
|
398
|
+
}
|
399
|
+
else {
|
400
|
+
device.log.error(`MatterbridgeMicrowaveOvenControlServer: addMoreTime called with invalid cookTime ${request.timeToAdd}`);
|
401
|
+
}
|
402
|
+
}
|
403
|
+
}
|
404
|
+
export const OvenCavityOperationalStateBehavior = ClusterBehavior.withInterface().for(OvenCavityOperationalState.Cluster);
|
405
|
+
export class OvenCavityOperationalStateServer extends OvenCavityOperationalStateBehavior {
|
406
|
+
initialize() {
|
407
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
408
|
+
device.log.info('OvenCavityOperationalStateServer initialized: setting operational state to Stopped and operational error to No error');
|
409
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
|
410
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
411
|
+
}
|
412
|
+
stop() {
|
413
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
414
|
+
device.log.info('OvenCavityOperationalStateServer: stop called setting operational state to Stopped and operational error to No error');
|
415
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Stopped;
|
416
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
417
|
+
return {
|
418
|
+
commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
419
|
+
};
|
420
|
+
}
|
421
|
+
start() {
|
422
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
423
|
+
device.log.info('OvenCavityOperationalStateServer: start called setting operational state to Running and operational error to No error');
|
424
|
+
this.state.operationalState = OperationalState.OperationalStateEnum.Running;
|
425
|
+
this.state.operationalError = { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' };
|
426
|
+
return {
|
427
|
+
commandResponseState: { errorStateId: OperationalState.ErrorState.NoError, errorStateLabel: 'No error', errorStateDetails: 'Fully operational' },
|
428
|
+
};
|
429
|
+
}
|
430
|
+
}
|
431
|
+
export const RefrigeratorAndTemperatureControlledCabinetModeBehavior = ClusterBehavior.withInterface().for(RefrigeratorAndTemperatureControlledCabinetMode.Cluster);
|
432
|
+
class RefrigeratorAndTemperatureControlledCabinetModeServer extends RefrigeratorAndTemperatureControlledCabinetModeBehavior {
|
433
|
+
initialize() {
|
434
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
435
|
+
device.log.info('MatterbridgeRefrigeratorAndTemperatureControlledCabinetModeServer initialized: setting currentMode to 1');
|
436
|
+
this.state.currentMode = 1;
|
437
|
+
}
|
438
|
+
changeToMode(request) {
|
439
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
440
|
+
const supportedMode = this.state.supportedModes.find((supportedMode) => supportedMode.mode === request.newMode);
|
441
|
+
if (supportedMode) {
|
442
|
+
device.log.info(`MatterbridgeRefrigeratorAndTemperatureControlledCabinetModeServer: changeToMode called with mode ${supportedMode.mode} = ${supportedMode.label}`);
|
443
|
+
this.state.currentMode = request.newMode;
|
444
|
+
return { status: ModeBase.ModeChangeStatus.Success, statusText: 'Success' };
|
445
|
+
}
|
446
|
+
else {
|
447
|
+
device.log.info(`MatterbridgeRefrigeratorAndTemperatureControlledCabinetModeServer: changeToMode called with invalid mode ${request.newMode}`);
|
448
|
+
return { status: ModeBase.ModeChangeStatus.InvalidInMode, statusText: 'Invalid mode' };
|
449
|
+
}
|
450
|
+
}
|
451
|
+
}
|
452
|
+
export const OvenModeBehavior = ClusterBehavior.withInterface().for(OvenMode.Cluster);
|
453
|
+
class OvenModeServer extends OvenModeBehavior {
|
454
|
+
initialize() {
|
455
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
456
|
+
device.log.info('OvenModeServer initialized: setting currentMode to 3');
|
457
|
+
this.state.currentMode = 3;
|
458
|
+
}
|
459
|
+
changeToMode(request) {
|
460
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
461
|
+
const supportedMode = this.state.supportedModes.find((supportedMode) => supportedMode.mode === request.newMode);
|
462
|
+
if (supportedMode) {
|
463
|
+
device.log.info(`OvenModeServer: changeToMode called with mode ${supportedMode.mode} = ${supportedMode.label}`);
|
464
|
+
this.state.currentMode = request.newMode;
|
465
|
+
return { status: ModeBase.ModeChangeStatus.Success, statusText: 'Success' };
|
466
|
+
}
|
467
|
+
else {
|
468
|
+
device.log.info(`OvenModeServer: changeToMode called with invalid mode ${request.newMode}`);
|
469
|
+
return { status: ModeBase.ModeChangeStatus.InvalidInMode, statusText: 'Invalid mode' };
|
470
|
+
}
|
471
|
+
}
|
472
|
+
}
|
473
|
+
export const DishwasherModeBehavior = ClusterBehavior.withInterface().for(DishwasherMode.Cluster);
|
474
|
+
class DishwasherModeServer extends DishwasherModeBehavior {
|
475
|
+
initialize() {
|
476
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
477
|
+
device.log.info('DishwasherModeServer initialized: setting currentMode to 3');
|
478
|
+
this.state.currentMode = 2;
|
479
|
+
this.reactTo(this.agent.get(MatterbridgeOnOffServer).events.onOff$Changed, this.handleOnOffChange);
|
480
|
+
}
|
481
|
+
handleOnOffChange(onOff) {
|
482
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
483
|
+
if (onOff === false) {
|
484
|
+
device.log.info('***OnOffServer changed to OFF: setting Dead Front state to Manufacturer Specific');
|
485
|
+
this.state.currentMode = 2;
|
486
|
+
}
|
487
|
+
}
|
488
|
+
changeToMode(request) {
|
489
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
490
|
+
const supportedMode = this.state.supportedModes.find((supportedMode) => supportedMode.mode === request.newMode);
|
491
|
+
if (supportedMode) {
|
492
|
+
device.log.info(`DishwasherModeServer: changeToMode called with mode ${supportedMode.mode} = ${supportedMode.label}`);
|
493
|
+
this.state.currentMode = request.newMode;
|
494
|
+
return { status: ModeBase.ModeChangeStatus.Success, statusText: 'Success' };
|
495
|
+
}
|
496
|
+
else {
|
497
|
+
device.log.error(`DishwasherModeServer: changeToMode called with invalid mode ${request.newMode}`);
|
498
|
+
return { status: ModeBase.ModeChangeStatus.InvalidInMode, statusText: 'Invalid mode' };
|
499
|
+
}
|
500
|
+
}
|
501
|
+
}
|
502
|
+
export const LaundryWasherModeBehavior = ClusterBehavior.withInterface().for(LaundryWasherMode.Cluster);
|
503
|
+
class LaundryWasherModeServer extends LaundryWasherModeBehavior {
|
504
|
+
initialize() {
|
505
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
506
|
+
device.log.info('LaundryWasherModeServer initialized: setting currentMode to 3');
|
507
|
+
this.state.currentMode = 2;
|
508
|
+
this.reactTo(this.agent.get(MatterbridgeOnOffServer).events.onOff$Changed, this.handleOnOffChange);
|
509
|
+
}
|
510
|
+
handleOnOffChange(onOff) {
|
511
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
512
|
+
if (onOff === false) {
|
513
|
+
device.log.notice('OnOffServer changed to OFF: setting Dead Front state to Manufacturer Specific');
|
514
|
+
this.state.currentMode = 2;
|
515
|
+
}
|
516
|
+
}
|
517
|
+
changeToMode(request) {
|
518
|
+
const device = this.endpoint.stateOf(MatterbridgeServer).deviceCommand;
|
519
|
+
const supportedMode = this.state.supportedModes.find((supportedMode) => supportedMode.mode === request.newMode);
|
520
|
+
if (supportedMode) {
|
521
|
+
device.log.info(`LaundryWasherModeServer: changeToMode called with mode ${supportedMode.mode} = ${supportedMode.label}`);
|
522
|
+
this.state.currentMode = request.newMode;
|
523
|
+
return { status: ModeBase.ModeChangeStatus.Success, statusText: 'Success' };
|
524
|
+
}
|
525
|
+
else {
|
526
|
+
device.log.error(`LaundryWasherModeServer: changeToMode called with invalid mode ${request.newMode}`);
|
527
|
+
return { status: ModeBase.ModeChangeStatus.InvalidInMode, statusText: 'Invalid mode' };
|
528
|
+
}
|
529
|
+
}
|
530
|
+
}
|