matterbridge-example-dynamic-platform 1.1.4 → 1.1.5-dev.1

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/platform.js CHANGED
@@ -1,5 +1,5 @@
1
- import { AirQuality, AirQualityCluster, BooleanStateCluster, BooleanStateConfiguration, CarbonDioxideConcentrationMeasurement, CarbonMonoxideConcentrationMeasurement, ColorControl, ColorControlCluster, DoorLock, DoorLockCluster, FanControl, FanControlCluster, FlowMeasurement, FlowMeasurementCluster, FormaldehydeConcentrationMeasurement, LevelControlCluster, MatterbridgeEndpoint, NitrogenDioxideConcentrationMeasurement, OnOffCluster, OzoneConcentrationMeasurement, Pm10ConcentrationMeasurement, Pm1ConcentrationMeasurement, Pm25ConcentrationMeasurement, RadonConcentrationMeasurement, RelativeHumidityMeasurement, RelativeHumidityMeasurementCluster, SmokeCoAlarm, SmokeCoAlarmCluster, TemperatureMeasurement, TemperatureMeasurementCluster, Thermostat, ThermostatCluster, TotalVolatileOrganicCompoundsConcentrationMeasurement, WindowCovering, WindowCoveringCluster, airConditioner, airQualitySensor, bridgedNode, colorTemperatureLight, coverDevice, dimmableLight, doorLockDevice, fanDevice, flowSensor, humiditySensor, onOffLight, onOffOutlet, onOffSwitch, powerSource, rainSensor, smokeCoAlarm, temperatureSensor, thermostatDevice, waterFreezeDetector, waterLeakDetector, LocationTag, airPurifier, pumpDevice, waterValve, } from 'matterbridge';
2
- import { /* MatterbridgeEndpoint as */ MatterbridgeDevice, MatterbridgeDynamicPlatform } from 'matterbridge';
1
+ import { AirQuality, AirQualityCluster, BooleanStateCluster, CarbonDioxideConcentrationMeasurement, CarbonMonoxideConcentrationMeasurement, ColorControl, ColorControlCluster, DoorLock, DoorLockCluster, FanControl, FanControlCluster, FlowMeasurementCluster, FormaldehydeConcentrationMeasurement, LevelControlCluster, NitrogenDioxideConcentrationMeasurement, OnOffCluster, OzoneConcentrationMeasurement, Pm10ConcentrationMeasurement, Pm1ConcentrationMeasurement, Pm25ConcentrationMeasurement, RadonConcentrationMeasurement, RelativeHumidityMeasurement, RelativeHumidityMeasurementCluster, SmokeCoAlarm, SmokeCoAlarmCluster, TemperatureMeasurement, TemperatureMeasurementCluster, Thermostat, ThermostatCluster, TotalVolatileOrganicCompoundsConcentrationMeasurement, WindowCovering, WindowCoveringCluster, airConditioner, airQualitySensor, bridgedNode, colorTemperatureLight, coverDevice, dimmableLight, doorLockDevice, fanDevice, flowSensor, humiditySensor, onOffLight, onOffOutlet, onOffSwitch, powerSource, rainSensor, smokeCoAlarm, temperatureSensor, thermostatDevice, waterFreezeDetector, waterLeakDetector, LocationTag, airPurifier, pumpDevice, waterValve, } from 'matterbridge';
2
+ import { MatterbridgeEndpoint, MatterbridgeDynamicPlatform } from 'matterbridge';
3
3
  import { isValidBoolean, isValidNumber } from 'matterbridge/utils';
4
4
  export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatform {
5
5
  switch;
@@ -40,33 +40,21 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
40
40
  airConditionerInterval;
41
41
  bridgedDevices = new Map();
42
42
  fanModeLookup = ['Off', 'Low', 'Medium', 'High', 'On', 'Auto', 'Smart'];
43
- async createMutableDevice(definition, options = {}, debug = false) {
44
- let device;
45
- if (this.matterbridge.edge === true)
46
- device = new MatterbridgeEndpoint(definition, options, debug);
47
- else
48
- device = new MatterbridgeDevice(definition, options, debug);
49
- return device;
50
- }
51
43
  constructor(matterbridge, log, config) {
52
44
  super(matterbridge, log, config);
53
- // Verify that Matterbridge is the correct version
54
- if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('1.6.7')) {
55
- throw new Error(`This plugin requires Matterbridge version >= "1.6.7". Please update Matterbridge from ${this.matterbridge.matterbridgeVersion} to the latest version in the frontend.`);
45
+ if (this.verifyMatterbridgeVersion === undefined || typeof this.verifyMatterbridgeVersion !== 'function' || !this.verifyMatterbridgeVersion('2.1.0')) {
46
+ throw new Error(`This plugin requires Matterbridge version >= "2.1.0". Please update Matterbridge from ${this.matterbridge.matterbridgeVersion} to the latest version in the frontend.`);
56
47
  }
57
48
  this.log.info('Initializing platform:', this.config.name);
58
49
  }
59
50
  async onStart(reason) {
60
51
  this.log.info('onStart called with reason:', reason ?? 'none');
61
- // Create a switch device
62
- this.switch = await this.createMutableDevice([onOffSwitch, bridgedNode], { uniqueStorageKey: 'Switch' }, this.config.debug);
52
+ this.switch = new MatterbridgeEndpoint([onOffSwitch, bridgedNode, powerSource], { uniqueStorageKey: 'Switch' }, this.config.debug);
63
53
  this.switch.log.logName = 'Switch';
64
54
  this.switch.createDefaultIdentifyClusterServer();
65
55
  this.switch.createDefaultGroupsClusterServer();
66
- this.switch.createDefaultScenesClusterServer();
67
56
  this.switch.createDefaultBridgedDeviceBasicInformationClusterServer('Switch', '0x23452164', 0xfff1, 'Matterbridge', 'Matterbridge Switch', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
68
57
  this.switch.createDefaultOnOffClusterServer();
69
- this.switch.addDeviceType(powerSource);
70
58
  this.switch.createDefaultPowerSourceRechargeableBatteryClusterServer(70);
71
59
  await this.registerDevice(this.switch);
72
60
  this.bridgedDevices.set(this.switch.deviceName ?? '', this.switch);
@@ -74,22 +62,19 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
74
62
  this.log.info(`Command identify called identifyTime:${identifyTime}`);
75
63
  });
76
64
  this.switch.addCommandHandler('on', async () => {
77
- await this.switch?.setAttribute(OnOffCluster.id, 'onOff', true, this.switch.log, this.switch);
65
+ await this.switch?.setAttribute(OnOffCluster.id, 'onOff', true, this.switch.log);
78
66
  this.switch?.log.info('Command on called');
79
67
  });
80
68
  this.switch.addCommandHandler('off', async () => {
81
- await this.switch?.setAttribute(OnOffCluster.id, 'onOff', false, this.switch.log, this.switch);
69
+ await this.switch?.setAttribute(OnOffCluster.id, 'onOff', false, this.switch.log);
82
70
  this.switch?.log.info('Command off called');
83
71
  });
84
- // Create a on off light device
85
- this.lightOnOff = await this.createMutableDevice([onOffLight, bridgedNode], { uniqueStorageKey: 'Light (on/off)' }, this.config.debug);
72
+ this.lightOnOff = new MatterbridgeEndpoint([onOffLight, bridgedNode, powerSource], { uniqueStorageKey: 'Light (on/off)' }, this.config.debug);
86
73
  this.lightOnOff.log.logName = 'Light (on/off)';
87
74
  this.lightOnOff.createDefaultIdentifyClusterServer();
88
75
  this.lightOnOff.createDefaultGroupsClusterServer();
89
- this.lightOnOff.createDefaultScenesClusterServer();
90
76
  this.lightOnOff.createDefaultBridgedDeviceBasicInformationClusterServer('Light (on/off)', '0x2342375564', 0xfff1, 'Matterbridge', 'Matterbridge Light on/off', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
91
77
  this.lightOnOff.createDefaultOnOffClusterServer();
92
- this.lightOnOff.addDeviceType(powerSource);
93
78
  this.lightOnOff.createDefaultPowerSourceWiredClusterServer();
94
79
  await this.registerDevice(this.lightOnOff);
95
80
  this.bridgedDevices.set(this.lightOnOff.deviceName ?? '', this.lightOnOff);
@@ -97,23 +82,20 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
97
82
  this.lightOnOff?.log.info(`Command identify called identifyTime:${identifyTime}`);
98
83
  });
99
84
  this.lightOnOff.addCommandHandler('on', async () => {
100
- await this.light?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightOnOff?.log, this.lightOnOff);
85
+ await this.lightOnOff?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightOnOff?.log);
101
86
  this.lightOnOff?.log.info('Command on called');
102
87
  });
103
88
  this.lightOnOff.addCommandHandler('off', async () => {
104
- await this.light?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightOnOff?.log, this.lightOnOff);
89
+ await this.lightOnOff?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightOnOff?.log);
105
90
  this.lightOnOff?.log.info('Command off called');
106
91
  });
107
- // Create a dimmer device
108
- this.dimmer = await this.createMutableDevice([dimmableLight, bridgedNode], { uniqueStorageKey: 'Dimmer' }, this.config.debug);
92
+ this.dimmer = new MatterbridgeEndpoint([dimmableLight, bridgedNode, powerSource], { uniqueStorageKey: 'Dimmer' }, this.config.debug);
109
93
  this.dimmer.log.logName = 'Dimmer';
110
94
  this.dimmer.createDefaultIdentifyClusterServer();
111
95
  this.dimmer.createDefaultGroupsClusterServer();
112
- this.dimmer.createDefaultScenesClusterServer();
113
96
  this.dimmer.createDefaultBridgedDeviceBasicInformationClusterServer('Dimmer', '0x234554564', 0xfff1, 'Matterbridge', 'Matterbridge Dimmer', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
114
97
  this.dimmer.createDefaultOnOffClusterServer();
115
98
  this.dimmer.createDefaultLevelControlClusterServer();
116
- this.dimmer.addDeviceType(powerSource);
117
99
  this.dimmer.createDefaultPowerSourceReplaceableBatteryClusterServer(70);
118
100
  await this.registerDevice(this.dimmer);
119
101
  this.bridgedDevices.set(this.dimmer.deviceName ?? '', this.dimmer);
@@ -121,32 +103,29 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
121
103
  this.dimmer?.log.info(`Command identify called identifyTime:${identifyTime}`);
122
104
  });
123
105
  this.dimmer.addCommandHandler('on', async () => {
124
- await this.dimmer?.setAttribute(OnOffCluster.id, 'onOff', true, this.dimmer.log, this.dimmer);
106
+ await this.dimmer?.setAttribute(OnOffCluster.id, 'onOff', true, this.dimmer.log);
125
107
  this.dimmer?.log.info('Command on called');
126
108
  });
127
109
  this.dimmer.addCommandHandler('off', async () => {
128
- await this.dimmer?.setAttribute(OnOffCluster.id, 'onOff', false, this.dimmer.log, this.dimmer);
110
+ await this.dimmer?.setAttribute(OnOffCluster.id, 'onOff', false, this.dimmer.log);
129
111
  this.dimmer?.log.info('Command off called');
130
112
  });
131
113
  this.dimmer.addCommandHandler('moveToLevel', async ({ request: { level } }) => {
132
- await this.dimmer?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.dimmer.log, this.dimmer);
114
+ await this.dimmer?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.dimmer.log);
133
115
  this.dimmer?.log.debug(`Command moveToLevel called request: ${level}`);
134
116
  });
135
117
  this.dimmer.addCommandHandler('moveToLevelWithOnOff', async ({ request: { level } }) => {
136
- await this.dimmer?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.dimmer.log, this.dimmer);
118
+ await this.dimmer?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.dimmer.log);
137
119
  this.dimmer?.log.debug(`Command moveToLevelWithOnOff called request: ${level}`);
138
120
  });
139
- // Create a light device
140
- this.light = await this.createMutableDevice([colorTemperatureLight, bridgedNode], { uniqueStorageKey: 'Light (XY, HS and CT)' }, this.config.debug);
121
+ this.light = new MatterbridgeEndpoint([colorTemperatureLight, bridgedNode, powerSource], { uniqueStorageKey: 'Light (XY, HS and CT)' }, this.config.debug);
141
122
  this.light.log.logName = 'Light (XY, HS and CT)';
142
123
  this.light.createDefaultIdentifyClusterServer();
143
124
  this.light.createDefaultGroupsClusterServer();
144
- this.light.createDefaultScenesClusterServer();
145
125
  this.light.createDefaultBridgedDeviceBasicInformationClusterServer('Light (XY, HS and CT)', '0x23480564', 0xfff1, 'Matterbridge', 'Matterbridge Light', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
146
126
  this.light.createDefaultOnOffClusterServer();
147
127
  this.light.createDefaultLevelControlClusterServer();
148
128
  this.light.createDefaultColorControlClusterServer();
149
- this.light.addDeviceType(powerSource);
150
129
  this.light.createDefaultPowerSourceReplaceableBatteryClusterServer(70);
151
130
  await this.registerDevice(this.light);
152
131
  this.bridgedDevices.set(this.light.deviceName ?? '', this.light);
@@ -154,55 +133,51 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
154
133
  this.light?.log.info(`Command identify called identifyTime:${identifyTime}`);
155
134
  });
156
135
  this.light.addCommandHandler('on', async () => {
157
- await this.light?.setAttribute(OnOffCluster.id, 'onOff', true, this.light?.log, this.light);
136
+ await this.light?.setAttribute(OnOffCluster.id, 'onOff', true, this.light?.log);
158
137
  this.light?.log.info('Command on called');
159
138
  });
160
139
  this.light.addCommandHandler('off', async () => {
161
- await this.light?.setAttribute(OnOffCluster.id, 'onOff', false, this.light?.log, this.light);
140
+ await this.light?.setAttribute(OnOffCluster.id, 'onOff', false, this.light?.log);
162
141
  this.light?.log.info('Command off called');
163
142
  });
164
143
  this.light.addCommandHandler('moveToLevel', async ({ request: { level } }) => {
165
- await this.light?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.light?.log, this.light);
144
+ await this.light?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.light?.log);
166
145
  this.light?.log.debug(`Command moveToLevel called request: ${level}`);
167
146
  });
168
147
  this.light.addCommandHandler('moveToLevelWithOnOff', async ({ request: { level } }) => {
169
- await this.light?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.light?.log, this.light);
148
+ await this.light?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.light?.log);
170
149
  this.light?.log.debug(`Command moveToLevelWithOnOff called request: ${level}`);
171
150
  });
172
151
  this.light.addCommandHandler('moveToColor', async ({ request: { colorX, colorY } }) => {
173
- await this.light?.setAttribute(ColorControlCluster.id, 'currentX', colorX, this.light?.log, this.light);
174
- await this.light?.setAttribute(ColorControlCluster.id, 'currentY', colorY, this.light?.log, this.light);
152
+ await this.light?.setAttribute(ColorControlCluster.id, 'currentX', colorX, this.light?.log);
153
+ await this.light?.setAttribute(ColorControlCluster.id, 'currentY', colorY, this.light?.log);
175
154
  this.light?.log.debug(`Command moveToColor called request: X ${colorX / 65536} Y ${colorY / 65536}`);
176
155
  });
177
- this.light.addCommandHandler('moveToHueAndSaturation', async ({ request: { hue, saturation }, attributes: { currentHue, currentSaturation } }) => {
178
- await this.light?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.light?.log, this.light);
179
- await this.light?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.light?.log, this.light);
180
- this.light?.log.debug(`Command moveToHueAndSaturation called request: hue ${hue} saturation ${saturation} attributes: hue ${currentHue?.getLocal()} saturation ${currentSaturation?.getLocal()}`);
156
+ this.light.addCommandHandler('moveToHueAndSaturation', async ({ request: { hue, saturation } }) => {
157
+ await this.light?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.light?.log);
158
+ await this.light?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.light?.log);
159
+ this.light?.log.debug(`Command moveToHueAndSaturation called request: hue ${hue} saturation ${saturation}`);
181
160
  });
182
- this.light.addCommandHandler('moveToHue', async ({ request: { hue }, attributes: { currentHue, currentSaturation } }) => {
183
- await this.light?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.light?.log, this.light);
184
- this.light?.log.debug(`Command moveToHue called request: hue ${hue} attributes: hue ${currentHue?.getLocal()} saturation ${currentSaturation?.getLocal()}`);
161
+ this.light.addCommandHandler('moveToHue', async ({ request: { hue } }) => {
162
+ await this.light?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.light?.log);
163
+ this.light?.log.debug(`Command moveToHue called request: hue ${hue}`);
185
164
  });
186
- this.light.addCommandHandler('moveToSaturation', async ({ request: { saturation }, attributes: { currentHue, currentSaturation } }) => {
187
- await this.light?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.light?.log, this.light);
188
- this.light?.log.debug(`Command moveToSaturation called request: saturation ${saturation} attributes: hue ${currentHue?.getLocal()} saturation ${currentSaturation?.getLocal()}`);
165
+ this.light.addCommandHandler('moveToSaturation', async ({ request: { saturation } }) => {
166
+ await this.light?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.light?.log);
167
+ this.light?.log.debug(`Command moveToSaturation called request: saturation ${saturation}}`);
189
168
  });
190
- this.light.addCommandHandler('moveToColorTemperature', async ({ request, attributes }) => {
191
- await this.light?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', request.colorTemperatureMireds, this.light?.log, this.light);
192
- this.light?.log.debug(`Command moveToColorTemperature called request: ${request.colorTemperatureMireds} attributes: ${attributes.colorTemperatureMireds?.getLocal()}`);
169
+ this.light.addCommandHandler('moveToColorTemperature', async ({ request: { colorTemperatureMireds } }) => {
170
+ await this.light?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', colorTemperatureMireds, this.light?.log);
171
+ this.light?.log.debug(`Command moveToColorTemperature called request: ${colorTemperatureMireds}`);
193
172
  });
194
- // Create a light device with HS color control
195
- this.lightHS = await this.createMutableDevice([colorTemperatureLight, bridgedNode], { uniqueStorageKey: 'Light (HS, CT)' }, this.config.debug);
173
+ this.lightHS = new MatterbridgeEndpoint([colorTemperatureLight, bridgedNode, powerSource], { uniqueStorageKey: 'Light (HS, CT)' }, this.config.debug);
196
174
  this.lightHS.log.logName = 'Light (HS, CT)';
197
175
  this.lightHS.createDefaultIdentifyClusterServer();
198
176
  this.lightHS.createDefaultGroupsClusterServer();
199
- this.lightHS.createDefaultScenesClusterServer();
200
177
  this.lightHS.createDefaultBridgedDeviceBasicInformationClusterServer('Light (HS, CT)', '0x25097564', 0xfff1, 'Matterbridge', 'Matterbridge Light', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
201
178
  this.lightHS.createDefaultOnOffClusterServer();
202
179
  this.lightHS.createDefaultLevelControlClusterServer();
203
180
  this.lightHS.createHsColorControlClusterServer();
204
- // await this.lightHS.configureColorControlCluster(true, false, false, ColorControl.ColorMode.CurrentHueAndCurrentSaturation);
205
- this.lightHS.addDeviceType(powerSource);
206
181
  this.lightHS.createDefaultPowerSourceWiredClusterServer();
207
182
  await this.registerDevice(this.lightHS);
208
183
  this.bridgedDevices.set(this.lightHS.deviceName ?? '', this.lightHS);
@@ -210,49 +185,45 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
210
185
  this.lightHS?.log.info(`Command identify called identifyTime:${identifyTime}`);
211
186
  });
212
187
  this.lightHS.addCommandHandler('on', async () => {
213
- await this.lightHS?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightHS?.log, this.lightHS);
188
+ await this.lightHS?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightHS?.log);
214
189
  this.lightHS?.log.info('Command on called');
215
190
  });
216
191
  this.lightHS.addCommandHandler('off', async () => {
217
- await this.lightHS?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightHS?.log, this.lightHS);
192
+ await this.lightHS?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightHS?.log);
218
193
  this.lightHS?.log.info('Command off called');
219
194
  });
220
- this.lightHS.addCommandHandler('moveToLevel', async ({ request: { level }, attributes: { currentLevel } }) => {
221
- await this.lightHS?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightHS?.log, this.lightHS);
222
- this.lightHS?.log.debug(`Command moveToLevel called request: ${level} attributes: ${currentLevel?.getLocal()}`);
195
+ this.lightHS.addCommandHandler('moveToLevel', async ({ request: { level } }) => {
196
+ await this.lightHS?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightHS?.log);
197
+ this.lightHS?.log.debug(`Command moveToLevel called request: ${level}`);
223
198
  });
224
- this.lightHS.addCommandHandler('moveToLevelWithOnOff', async ({ request: { level }, attributes: { currentLevel } }) => {
225
- await this.lightHS?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightHS?.log, this.lightHS);
226
- this.lightHS?.log.debug(`Command moveToLevelWithOnOff called request: ${level} attributes: ${currentLevel?.getLocal()}`);
199
+ this.lightHS.addCommandHandler('moveToLevelWithOnOff', async ({ request: { level } }) => {
200
+ await this.lightHS?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightHS?.log);
201
+ this.lightHS?.log.debug(`Command moveToLevelWithOnOff called request: ${level}`);
227
202
  });
228
- this.lightHS.addCommandHandler('moveToHueAndSaturation', async ({ request: { hue, saturation }, attributes: { currentHue, currentSaturation } }) => {
229
- await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.lightHS?.log, this.lightHS);
230
- await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.lightHS?.log, this.lightHS);
231
- this.lightHS?.log.debug(`Command moveToHueAndSaturation called request: hue ${hue} saturation ${saturation} attributes: hue ${currentHue?.getLocal()} saturation ${currentSaturation?.getLocal()}`);
203
+ this.lightHS.addCommandHandler('moveToHueAndSaturation', async ({ request: { hue, saturation } }) => {
204
+ await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.lightHS?.log);
205
+ await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.lightHS?.log);
206
+ this.lightHS?.log.debug(`Command moveToHueAndSaturation called request: hue ${hue} saturation ${saturation}}`);
232
207
  });
233
- this.lightHS.addCommandHandler('moveToHue', async ({ request: { hue }, attributes: { currentHue, currentSaturation } }) => {
234
- await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.lightHS?.log, this.lightHS);
235
- this.lightHS?.log.debug(`Command moveToHue called request: hue ${hue} attributes: hue ${currentHue?.getLocal()} saturation ${currentSaturation?.getLocal()}`);
208
+ this.lightHS.addCommandHandler('moveToHue', async ({ request: { hue } }) => {
209
+ await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentHue', hue, this.lightHS?.log);
210
+ this.lightHS?.log.debug(`Command moveToHue called request: hue ${hue}`);
236
211
  });
237
- this.lightHS.addCommandHandler('moveToSaturation', async ({ request: { saturation }, attributes: { currentHue, currentSaturation } }) => {
238
- await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.lightHS?.log, this.lightHS);
239
- this.lightHS?.log.debug(`Command moveToSaturation called request: saturation ${saturation} attributes: hue ${currentHue?.getLocal()} saturation ${currentSaturation?.getLocal()}`);
212
+ this.lightHS.addCommandHandler('moveToSaturation', async ({ request: { saturation } }) => {
213
+ await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentSaturation', saturation, this.lightHS?.log);
214
+ this.lightHS?.log.debug(`Command moveToSaturation called request: saturation ${saturation}`);
240
215
  });
241
- this.lightHS.addCommandHandler('moveToColorTemperature', async ({ request, attributes }) => {
242
- await this.light?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', request.colorTemperatureMireds, this.light?.log, this.light);
243
- this.light?.log.debug(`Command moveToColorTemperature called request: ${request.colorTemperatureMireds} attributes: ${attributes.colorTemperatureMireds?.getLocal()}`);
216
+ this.lightHS.addCommandHandler('moveToColorTemperature', async ({ request: colorTemperatureMireds }) => {
217
+ this.lightHS?.log.debug(`Command moveToColorTemperature called request: ${colorTemperatureMireds}`);
244
218
  });
245
- // Create a light device with XY color control
246
- this.lightXY = await this.createMutableDevice([colorTemperatureLight, bridgedNode], { uniqueStorageKey: 'Light (XY, CT)' }, this.config.debug);
219
+ this.lightXY = new MatterbridgeEndpoint([colorTemperatureLight, bridgedNode, powerSource], { uniqueStorageKey: 'Light (XY, CT)' }, this.config.debug);
247
220
  this.lightXY.log.logName = 'Light (XY, CT)';
248
221
  this.lightXY.createDefaultIdentifyClusterServer();
249
222
  this.lightXY.createDefaultGroupsClusterServer();
250
- this.lightXY.createDefaultScenesClusterServer();
251
223
  this.lightXY.createDefaultBridgedDeviceBasicInformationClusterServer('Light (XY, CT)', '0x23497564', 0xfff1, 'Matterbridge', 'Matterbridge Light', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
252
224
  this.lightXY.createDefaultOnOffClusterServer();
253
225
  this.lightXY.createDefaultLevelControlClusterServer();
254
226
  this.lightXY.createXyColorControlClusterServer();
255
- this.lightXY.addDeviceType(powerSource);
256
227
  this.lightXY.createDefaultPowerSourceWiredClusterServer();
257
228
  await this.registerDevice(this.lightXY);
258
229
  this.bridgedDevices.set(this.lightXY.deviceName ?? '', this.lightXY);
@@ -260,42 +231,38 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
260
231
  this.lightXY?.log.info(`Command identify called identifyTime:${identifyTime}`);
261
232
  });
262
233
  this.lightXY.addCommandHandler('on', async () => {
263
- await this.lightXY?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightXY?.log, this.lightXY);
234
+ await this.lightXY?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightXY?.log);
264
235
  this.lightXY?.log.info('Command on called');
265
236
  });
266
237
  this.lightXY.addCommandHandler('off', async () => {
267
- await this.lightXY?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightXY?.log, this.lightXY);
238
+ await this.lightXY?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightXY?.log);
268
239
  this.lightXY?.log.info('Command off called');
269
240
  });
270
241
  this.lightXY.addCommandHandler('moveToLevel', async ({ request: { level } }) => {
271
- await this.lightXY?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightXY?.log, this.lightXY);
242
+ await this.lightXY?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightXY?.log);
272
243
  this.lightXY?.log.debug(`Command moveToLevel called request: ${level}`);
273
244
  });
274
245
  this.lightXY.addCommandHandler('moveToLevelWithOnOff', async ({ request: { level } }) => {
275
- await this.lightXY?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightXY?.log, this.lightXY);
246
+ await this.lightXY?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightXY?.log);
276
247
  this.lightXY?.log.debug(`Command moveToLevelWithOnOff called request: ${level}`);
277
248
  });
278
249
  this.lightXY.addCommandHandler('moveToColor', async ({ request: { colorX, colorY } }) => {
279
- await this.lightXY?.setAttribute(ColorControlCluster.id, 'currentX', colorX, this.light?.log, this.light);
280
- await this.lightXY?.setAttribute(ColorControlCluster.id, 'currentY', colorY, this.light?.log, this.light);
250
+ await this.lightXY?.setAttribute(ColorControlCluster.id, 'currentX', colorX, this.lightXY?.log);
251
+ await this.lightXY?.setAttribute(ColorControlCluster.id, 'currentY', colorY, this.lightXY?.log);
281
252
  this.lightXY?.log.debug(`Command moveToColor called request: X ${colorX / 65536} Y ${colorY / 65536}`);
282
253
  });
283
- this.lightXY.addCommandHandler('moveToColorTemperature', async ({ request, attributes }) => {
284
- await this.light?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', request.colorTemperatureMireds, this.light?.log, this.light);
285
- this.light?.log.debug(`Command moveToColorTemperature called request: ${request.colorTemperatureMireds} attributes: ${attributes.colorTemperatureMireds?.getLocal()}`);
254
+ this.lightXY.addCommandHandler('moveToColorTemperature', async ({ request: { colorTemperatureMireds } }) => {
255
+ await this.lightXY?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', colorTemperatureMireds, this.lightXY?.log);
256
+ this.lightXY?.log.debug(`Command moveToColorTemperature called request: ${colorTemperatureMireds}`);
286
257
  });
287
- // Create a light device with CT color control
288
- this.lightCT = await this.createMutableDevice([colorTemperatureLight, bridgedNode], { uniqueStorageKey: 'Light (CT)' }, this.config.debug);
258
+ this.lightCT = new MatterbridgeEndpoint([colorTemperatureLight, bridgedNode, powerSource], { uniqueStorageKey: 'Light (CT)' }, this.config.debug);
289
259
  this.lightCT.log.logName = 'Light (CT)';
290
260
  this.lightCT.createDefaultIdentifyClusterServer();
291
261
  this.lightCT.createDefaultGroupsClusterServer();
292
- this.lightCT.createDefaultScenesClusterServer();
293
262
  this.lightCT.createDefaultBridgedDeviceBasicInformationClusterServer('Light (CT)', '0x23480749', 0xfff1, 'Matterbridge', 'Matterbridge Light', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
294
263
  this.lightCT.createDefaultOnOffClusterServer();
295
264
  this.lightCT.createDefaultLevelControlClusterServer();
296
265
  this.lightCT.createCtColorControlClusterServer();
297
- // await this.lightCT.configureColorControlCluster(false, false, true, ColorControl.ColorMode.ColorTemperatureMireds);
298
- this.lightCT.addDeviceType(powerSource);
299
266
  this.lightCT.createDefaultPowerSourceReplaceableBatteryClusterServer(70);
300
267
  await this.registerDevice(this.lightCT);
301
268
  this.bridgedDevices.set(this.lightCT.deviceName ?? '', this.lightCT);
@@ -303,34 +270,31 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
303
270
  this.lightCT?.log.info(`Command identify called identifyTime:${identifyTime}`);
304
271
  });
305
272
  this.lightCT.addCommandHandler('on', async () => {
306
- await this.lightCT?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightCT?.log, this.lightCT);
273
+ await this.lightCT?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightCT?.log);
307
274
  this.lightCT?.log.info('Command on called');
308
275
  });
309
276
  this.lightCT.addCommandHandler('off', async () => {
310
- await this.lightCT?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightCT?.log, this.lightCT);
277
+ await this.lightCT?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightCT?.log);
311
278
  this.lightCT?.log.info('Command off called');
312
279
  });
313
280
  this.lightCT.addCommandHandler('moveToLevel', async ({ request: { level } }) => {
314
- await this.lightCT?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightCT?.log, this.lightCT);
281
+ await this.lightCT?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightCT?.log);
315
282
  this.lightCT?.log.debug(`Command moveToLevel called request: ${level}`);
316
283
  });
317
284
  this.lightCT.addCommandHandler('moveToLevelWithOnOff', async ({ request: { level } }) => {
318
- await this.lightCT?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightCT?.log, this.lightCT);
285
+ await this.lightCT?.setAttribute(LevelControlCluster.id, 'currentLevel', level, this.lightCT?.log);
319
286
  this.lightCT?.log.debug(`Command moveToLevelWithOnOff called request: ${level}`);
320
287
  });
321
- this.lightCT.addCommandHandler('moveToColorTemperature', async ({ request }) => {
322
- await this.lightCT?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', request.colorTemperatureMireds, this.lightCT?.log, this.lightCT);
323
- this.lightCT?.log.debug(`Command moveToColorTemperature called request: ${request.colorTemperatureMireds}`);
288
+ this.lightCT.addCommandHandler('moveToColorTemperature', async ({ request: { colorTemperatureMireds } }) => {
289
+ await this.lightCT?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', colorTemperatureMireds, this.lightCT?.log);
290
+ this.lightCT?.log.debug(`Command moveToColorTemperature called request: ${colorTemperatureMireds}`);
324
291
  });
325
- // Create an outlet device
326
- this.outlet = await this.createMutableDevice([onOffOutlet, bridgedNode], { uniqueStorageKey: 'Outlet' }, this.config.debug);
292
+ this.outlet = new MatterbridgeEndpoint([onOffOutlet, bridgedNode, powerSource], { uniqueStorageKey: 'Outlet' }, this.config.debug);
327
293
  this.outlet.log.logName = 'Outlet';
328
294
  this.outlet.createDefaultIdentifyClusterServer();
329
295
  this.outlet.createDefaultGroupsClusterServer();
330
- this.outlet.createDefaultScenesClusterServer();
331
296
  this.outlet.createDefaultBridgedDeviceBasicInformationClusterServer('Outlet', '0x29252164', 0xfff1, 'Matterbridge', 'Matterbridge Outlet', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
332
297
  this.outlet.createDefaultOnOffClusterServer();
333
- this.outlet.addDeviceType(powerSource);
334
298
  this.outlet.createDefaultPowerSourceWiredClusterServer();
335
299
  await this.registerDevice(this.outlet);
336
300
  this.bridgedDevices.set(this.outlet.deviceName ?? '', this.outlet);
@@ -338,23 +302,19 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
338
302
  this.outlet?.log.info(`Command identify called identifyTime:${identifyTime}`);
339
303
  });
340
304
  this.outlet.addCommandHandler('on', async () => {
341
- await this.outlet?.setAttribute(OnOffCluster.id, 'onOff', true, this.outlet?.log, this.outlet);
305
+ await this.outlet?.setAttribute(OnOffCluster.id, 'onOff', true, this.outlet?.log);
342
306
  this.outlet?.log.info('Command on called');
343
307
  });
344
308
  this.outlet.addCommandHandler('off', async () => {
345
- await this.outlet?.setAttribute(OnOffCluster.id, 'onOff', false, this.outlet?.log, this.outlet);
309
+ await this.outlet?.setAttribute(OnOffCluster.id, 'onOff', false, this.outlet?.log);
346
310
  this.outlet?.log.info('Command off called');
347
311
  });
348
- // Create a window covering device
349
- // Matter uses 10000 = fully closed 0 = fully opened
350
- this.cover = await this.createMutableDevice([coverDevice, bridgedNode], { uniqueStorageKey: 'Cover' }, this.config.debug);
312
+ this.cover = new MatterbridgeEndpoint([coverDevice, bridgedNode, powerSource], { uniqueStorageKey: 'Cover' }, this.config.debug);
351
313
  this.cover.log.logName = 'Cover';
352
314
  this.cover.createDefaultIdentifyClusterServer();
353
315
  this.cover.createDefaultGroupsClusterServer();
354
- this.cover.createDefaultScenesClusterServer();
355
316
  this.cover.createDefaultBridgedDeviceBasicInformationClusterServer('Cover', '0x01020564', 0xfff1, 'Matterbridge', 'Matterbridge Cover', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
356
317
  this.cover.createDefaultWindowCoveringClusterServer();
357
- this.cover.addDeviceType(powerSource);
358
318
  this.cover.createDefaultPowerSourceRechargeableBatteryClusterServer(86);
359
319
  await this.registerDevice(this.cover);
360
320
  this.bridgedDevices.set(this.cover.deviceName ?? '', this.cover);
@@ -380,13 +340,11 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
380
340
  await this.cover?.setWindowCoveringCurrentTargetStatus(liftPercent100thsValue, liftPercent100thsValue, WindowCovering.MovementStatus.Stopped);
381
341
  this.cover?.log.info(`Command goToLiftPercentage ${liftPercent100thsValue} called`);
382
342
  });
383
- // Create a lock device
384
- this.lock = await this.createMutableDevice([doorLockDevice, bridgedNode], { uniqueStorageKey: 'Lock' }, this.config.debug);
343
+ this.lock = new MatterbridgeEndpoint([doorLockDevice, bridgedNode, powerSource], { uniqueStorageKey: 'Lock' }, this.config.debug);
385
344
  this.lock.log.logName = 'Lock';
386
345
  this.lock.createDefaultIdentifyClusterServer();
387
346
  this.lock.createDefaultBridgedDeviceBasicInformationClusterServer('Lock', '0x96352164', 0xfff1, 'Matterbridge', 'Matterbridge Lock', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
388
347
  this.lock.createDefaultDoorLockClusterServer();
389
- this.lock.addDeviceType(powerSource);
390
348
  this.lock.createDefaultPowerSourceRechargeableBatteryClusterServer(30);
391
349
  await this.registerDevice(this.lock);
392
350
  this.bridgedDevices.set(this.lock.deviceName ?? '', this.lock);
@@ -394,29 +352,29 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
394
352
  this.lock?.log.info(`Command identify called identifyTime:${identifyTime}`);
395
353
  });
396
354
  this.lock.addCommandHandler('lockDoor', async () => {
397
- await this.lock?.setAttribute(DoorLockCluster.id, 'lockState', DoorLock.LockState.Locked, this.lock?.log, this.lock);
355
+ await this.lock?.setAttribute(DoorLockCluster.id, 'lockState', DoorLock.LockState.Locked, this.lock?.log);
398
356
  this.lock?.log.info('Command lockDoor called');
399
357
  });
400
358
  this.lock.addCommandHandler('unlockDoor', async () => {
401
- await this.lock?.setAttribute(DoorLockCluster.id, 'lockState', DoorLock.LockState.Unlocked, this.lock?.log, this.lock);
359
+ await this.lock?.setAttribute(DoorLockCluster.id, 'lockState', DoorLock.LockState.Unlocked, this.lock?.log);
402
360
  this.lock?.log.info('Command unlockDoor called');
403
361
  });
404
- // Create a thermostat with AutoMode device
405
- this.thermoAuto = await this.createMutableDevice([thermostatDevice, bridgedNode], { uniqueStorageKey: 'Thermostat (AutoMode)' }, this.config.debug);
362
+ this.thermoAuto = new MatterbridgeEndpoint([thermostatDevice, bridgedNode, powerSource], { uniqueStorageKey: 'Thermostat (AutoMode)' }, this.config.debug);
406
363
  this.thermoAuto.log.logName = 'Thermostat (AutoMode)';
407
364
  this.thermoAuto.createDefaultIdentifyClusterServer();
408
365
  this.thermoAuto.createDefaultGroupsClusterServer();
409
- this.thermoAuto.createDefaultScenesClusterServer();
410
366
  this.thermoAuto.createDefaultBridgedDeviceBasicInformationClusterServer('Thermostat (AutoMode)', '0x96382164A', 0xfff1, 'Matterbridge', 'Matterbridge Thermostat', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
411
367
  this.thermoAuto.createDefaultThermostatClusterServer(20, 18, 22);
412
- this.thermoAuto.addDeviceType(powerSource);
413
368
  this.thermoAuto.createDefaultPowerSourceRechargeableBatteryClusterServer(70);
414
- const flowChild = this.thermoAuto.addChildDeviceTypeWithClusterServer('Flow', [flowSensor], [FlowMeasurement.Cluster.id]);
415
- flowChild.getClusterServer(FlowMeasurement.Cluster)?.setMeasuredValueAttribute(1 * 10);
416
- const tempChild = this.thermoAuto.addChildDeviceTypeWithClusterServer('Temperature', [temperatureSensor], [TemperatureMeasurement.Cluster.id]);
417
- tempChild.getClusterServer(TemperatureMeasurement.Cluster)?.setMeasuredValueAttribute(41 * 100);
418
- const humidityChild = this.thermoAuto.addChildDeviceTypeWithClusterServer('Humidity', [humiditySensor], [RelativeHumidityMeasurement.Cluster.id]);
419
- humidityChild.getClusterServer(RelativeHumidityMeasurement.Cluster)?.setMeasuredValueAttribute(80 * 100);
369
+ const flowChild = this.thermoAuto.addChildDeviceType('Flow', flowSensor);
370
+ flowChild.createDefaultFlowMeasurementClusterServer(1 * 10);
371
+ flowChild.addRequiredClusterServers();
372
+ const tempChild = this.thermoAuto.addChildDeviceType('Temperature', temperatureSensor);
373
+ tempChild.createDefaultTemperatureMeasurementClusterServer(21 * 100);
374
+ tempChild.addRequiredClusterServers();
375
+ const humidityChild = this.thermoAuto.addChildDeviceType('Humidity', humiditySensor);
376
+ humidityChild.createDefaultRelativeHumidityMeasurementClusterServer(50 * 100);
377
+ humidityChild.addRequiredClusterServers();
420
378
  await this.registerDevice(this.thermoAuto);
421
379
  this.bridgedDevices.set(this.thermoAuto.deviceName ?? '', this.thermoAuto);
422
380
  this.thermoAuto.addCommandHandler('identify', async ({ request: { identifyTime } }) => {
@@ -442,22 +400,19 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
442
400
  this.thermoAuto.subscribeAttribute(ThermostatCluster.id, 'systemMode', async (value) => {
443
401
  const lookupSystemMode = ['Off', 'Auto', '', 'Cool', 'Heat', 'EmergencyHeat', 'Precooling', 'FanOnly', 'Dry', 'Sleep'];
444
402
  this.thermoAuto?.log.info('Subscribe systemMode called with:', lookupSystemMode[value]);
445
- }, this.thermoAuto.log, this.thermoAuto);
403
+ }, this.thermoAuto.log);
446
404
  this.thermoAuto.subscribeAttribute(ThermostatCluster.id, 'occupiedHeatingSetpoint', async (value) => {
447
405
  this.thermoAuto?.log.info('Subscribe occupiedHeatingSetpoint called with:', value / 100);
448
- }, this.thermoAuto.log, this.thermoAuto);
406
+ }, this.thermoAuto.log);
449
407
  this.thermoAuto.subscribeAttribute(ThermostatCluster.id, 'occupiedCoolingSetpoint', async (value) => {
450
408
  this.thermoAuto?.log.info('Subscribe occupiedCoolingSetpoint called with:', value / 100);
451
- }, this.thermoAuto.log, this.thermoAuto);
452
- // Create a thermostat with Heat device
453
- this.thermoHeat = await this.createMutableDevice([thermostatDevice, bridgedNode], { uniqueStorageKey: 'Thermostat (Heat)' }, this.config.debug);
409
+ }, this.thermoAuto.log);
410
+ this.thermoHeat = new MatterbridgeEndpoint([thermostatDevice, bridgedNode, powerSource], { uniqueStorageKey: 'Thermostat (Heat)' }, this.config.debug);
454
411
  this.thermoHeat.log.logName = 'Thermostat (Heat)';
455
412
  this.thermoHeat.createDefaultIdentifyClusterServer();
456
413
  this.thermoHeat.createDefaultGroupsClusterServer();
457
- this.thermoHeat.createDefaultScenesClusterServer();
458
414
  this.thermoHeat.createDefaultBridgedDeviceBasicInformationClusterServer('Thermostat (Heat)', '0x96382164H', 0xfff1, 'Matterbridge', 'Matterbridge Thermostat', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
459
415
  this.thermoHeat.createDefaultHeatingThermostatClusterServer(20, 18, 5, 35);
460
- this.thermoHeat.addDeviceType(powerSource);
461
416
  this.thermoHeat.createDefaultPowerSourceRechargeableBatteryClusterServer(70);
462
417
  const heatTempIN = this.thermoHeat.addChildDeviceType('TemperatureIN', [temperatureSensor], {
463
418
  tagList: [{ mfgCode: null, namespaceId: LocationTag.Indoor.namespaceId, tag: LocationTag.Indoor.tag, label: null }],
@@ -484,15 +439,12 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
484
439
  this.thermoHeat.subscribeAttribute(ThermostatCluster.id, 'occupiedHeatingSetpoint', async (value) => {
485
440
  this.thermoHeat?.log.info('Subscribe occupiedHeatingSetpoint called with:', value / 100);
486
441
  }, this.thermoHeat.log);
487
- // Create a thermostat with Cool device
488
- this.thermoCool = await this.createMutableDevice([thermostatDevice, bridgedNode], { uniqueStorageKey: 'Thermostat (Cool)' }, this.config.debug);
442
+ this.thermoCool = new MatterbridgeEndpoint([thermostatDevice, bridgedNode, powerSource], { uniqueStorageKey: 'Thermostat (Cool)' }, this.config.debug);
489
443
  this.thermoCool.log.logName = 'Thermostat (Cool)';
490
444
  this.thermoCool.createDefaultIdentifyClusterServer();
491
445
  this.thermoCool.createDefaultGroupsClusterServer();
492
- this.thermoCool.createDefaultScenesClusterServer();
493
446
  this.thermoCool.createDefaultBridgedDeviceBasicInformationClusterServer('Thermostat (Cool)', '0x96382164C', 0xfff1, 'Matterbridge', 'Matterbridge Thermostat', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
494
447
  this.thermoCool.createDefaultCoolingThermostatClusterServer(20, 18, 5, 35);
495
- this.thermoCool.addDeviceType(powerSource);
496
448
  this.thermoCool.createDefaultPowerSourceRechargeableBatteryClusterServer(70);
497
449
  await this.registerDevice(this.thermoCool);
498
450
  this.bridgedDevices.set(this.thermoCool.deviceName ?? '', this.thermoCool);
@@ -509,22 +461,19 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
509
461
  this.thermoCool.subscribeAttribute(ThermostatCluster.id, 'occupiedCoolingSetpoint', async (value) => {
510
462
  this.thermoCool?.log.info('Subscribe occupiedCoolingSetpoint called with:', value / 100);
511
463
  }, this.thermoCool.log);
512
- // Create a airPurifier device
513
- this.airPurifier = await this.createMutableDevice([airPurifier, temperatureSensor, humiditySensor, bridgedNode], { uniqueStorageKey: 'Air purifier' }, this.config.debug);
464
+ this.airPurifier = new MatterbridgeEndpoint([airPurifier, temperatureSensor, humiditySensor, bridgedNode, powerSource], { uniqueStorageKey: 'Air purifier' }, this.config.debug);
514
465
  this.airPurifier.log.logName = 'Air purifier';
515
466
  this.airPurifier.createDefaultBridgedDeviceBasicInformationClusterServer('Air purifier', '0x96584864AP', 0xfff1, 'Matterbridge', 'Matterbridge Air purifier', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
516
467
  this.airPurifier.createDefaultIdentifyClusterServer();
517
468
  this.airPurifier.createDefaultFanControlClusterServer();
518
469
  this.airPurifier.createDefaultTemperatureMeasurementClusterServer(20 * 100);
519
470
  this.airPurifier.createDefaultRelativeHumidityMeasurementClusterServer(50 * 100);
520
- this.airPurifier.addDeviceType(powerSource);
521
471
  this.airPurifier.createDefaultPowerSourceWiredClusterServer();
522
472
  await this.registerDevice(this.airPurifier);
523
473
  this.bridgedDevices.set(this.airPurifier.deviceName ?? '', this.airPurifier);
524
474
  this.airPurifier.addCommandHandler('identify', async ({ request: { identifyTime } }) => {
525
475
  this.airPurifier?.log.info(`Command identify called identifyTime:${identifyTime}`);
526
476
  });
527
- // Apple sends Off and High
528
477
  this.airPurifier.subscribeAttribute(FanControlCluster.id, 'fanMode', async (newValue, oldValue) => {
529
478
  this.fan?.log.info(`Fan mode changed from ${this.fanModeLookup[oldValue]} to ${this.fanModeLookup[newValue]}`);
530
479
  if (newValue === FanControl.FanMode.Off) {
@@ -551,8 +500,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
551
500
  if (isValidNumber(newValue, 0, 100))
552
501
  await this.airPurifier?.setAttribute(FanControlCluster.id, 'percentCurrent', newValue, this.airPurifier?.log);
553
502
  }, this.airPurifier.log);
554
- // Create a airConditioner device
555
- this.airConditioner = await this.createMutableDevice([airConditioner, /* fanDevice, temperatureSensor, humiditySensor,*/ bridgedNode], { uniqueStorageKey: 'Air conditioner' }, this.config.debug);
503
+ this.airConditioner = new MatterbridgeEndpoint([airConditioner, bridgedNode, powerSource], { uniqueStorageKey: 'Air conditioner' }, this.config.debug);
556
504
  this.airConditioner.log.logName = 'Air conditioner';
557
505
  this.airConditioner.createDefaultBridgedDeviceBasicInformationClusterServer('Air conditioner', '0x96382864AC', 0xfff1, 'Matterbridge', 'Matterbridge Air conditioner', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
558
506
  this.airConditioner.createDefaultIdentifyClusterServer();
@@ -561,18 +509,17 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
561
509
  this.airConditioner.createDefaultFanControlClusterServer(FanControl.FanMode.Auto);
562
510
  this.airConditioner.createDefaultTemperatureMeasurementClusterServer(20 * 100);
563
511
  this.airConditioner.createDefaultRelativeHumidityMeasurementClusterServer(50 * 100);
564
- this.airConditioner.addDeviceType(powerSource);
565
512
  this.airConditioner.createDefaultPowerSourceWiredClusterServer();
566
- this.airConditioner.addRequiredClusterServers(this.airConditioner);
513
+ this.airConditioner.addRequiredClusterServers();
567
514
  await this.registerDevice(this.airConditioner);
568
515
  this.bridgedDevices.set(this.airConditioner.deviceName ?? '', this.airConditioner);
569
516
  this.airConditioner.addCommandHandler('identify', async ({ request: { identifyTime } }) => {
570
517
  this.airConditioner?.log.info(`Command identify called identifyTime:${identifyTime}`);
571
518
  });
572
519
  this.airConditioner.addCommandHandler('on', async () => {
573
- await this.airConditioner?.setAttribute(OnOffCluster.id, 'onOff', true, this.airConditioner?.log);
574
520
  this.airConditioner?.log.info('Command on called');
575
521
  await this.airConditioner?.setAttribute(OnOffCluster.id, 'onOff', true, this.airConditioner?.log);
522
+ await this.airConditioner?.setAttribute(OnOffCluster.id, 'onOff', true, this.airConditioner?.log);
576
523
  await this.airConditioner?.setAttribute(ThermostatCluster.id, 'localTemperature', 20 * 100, this.airConditioner?.log);
577
524
  await this.airConditioner?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', 20 * 100, this.airConditioner?.log);
578
525
  await this.airConditioner?.setAttribute(RelativeHumidityMeasurementCluster.id, 'measuredValue', 50 * 100, this.airConditioner?.log);
@@ -580,22 +527,20 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
580
527
  await this.airConditioner?.setAttribute(FanControlCluster.id, 'percentSetting', 50, this.airConditioner?.log);
581
528
  });
582
529
  this.airConditioner.addCommandHandler('off', async () => {
530
+ this.airConditioner?.log.info('Command off called');
583
531
  await this.airConditioner?.setAttribute(OnOffCluster.id, 'onOff', false, this.airConditioner?.log);
584
532
  await this.airConditioner?.setAttribute(ThermostatCluster.id, 'localTemperature', null, this.airConditioner?.log);
585
533
  await this.airConditioner?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', null, this.airConditioner?.log);
586
534
  await this.airConditioner?.setAttribute(RelativeHumidityMeasurementCluster.id, 'measuredValue', null, this.airConditioner?.log);
587
535
  await this.airConditioner?.setAttribute(FanControlCluster.id, 'speedSetting', null, this.airConditioner?.log);
588
536
  await this.airConditioner?.setAttribute(FanControlCluster.id, 'percentSetting', null, this.airConditioner?.log);
589
- this.airConditioner?.log.info('Command off called');
590
537
  });
591
- // Create a pumpDevice device
592
- this.pump = await this.createMutableDevice([pumpDevice, bridgedNode], { uniqueStorageKey: 'Pump' }, this.config.debug);
538
+ this.pump = new MatterbridgeEndpoint([pumpDevice, bridgedNode, powerSource], { uniqueStorageKey: 'Pump' }, this.config.debug);
593
539
  this.pump.log.logName = 'Pump';
594
540
  this.pump.createDefaultBridgedDeviceBasicInformationClusterServer('Pump', '0x96382864PUMP', 0xfff1, 'Matterbridge', 'Matterbridge Pump', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
595
541
  this.pump.createDefaultIdentifyClusterServer();
596
542
  this.pump.createDefaultOnOffClusterServer(true);
597
543
  this.pump.createDefaultPumpConfigurationAndControlClusterServer();
598
- this.pump.addDeviceType(powerSource);
599
544
  this.pump.createDefaultPowerSourceWiredClusterServer();
600
545
  await this.registerDevice(this.pump);
601
546
  this.bridgedDevices.set(this.pump.deviceName ?? '', this.pump);
@@ -603,31 +548,28 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
603
548
  this.pump?.log.info(`Command identify called identifyTime:${identifyTime}`);
604
549
  });
605
550
  this.pump.addCommandHandler('on', async () => {
606
- await this.pump?.setAttribute(OnOffCluster.id, 'onOff', true, this.pump?.log);
607
551
  this.pump?.log.info('Command on called');
552
+ await this.pump?.setAttribute(OnOffCluster.id, 'onOff', true, this.pump?.log);
608
553
  });
609
554
  this.pump.addCommandHandler('off', async () => {
610
- await this.pump?.setAttribute(OnOffCluster.id, 'onOff', false, this.pump?.log);
611
555
  this.pump?.log.info('Command off called');
556
+ await this.pump?.setAttribute(OnOffCluster.id, 'onOff', false, this.pump?.log);
612
557
  });
613
- // Create a waterValve device
614
- this.valve = await this.createMutableDevice([waterValve, bridgedNode], { uniqueStorageKey: 'Water valve' }, this.config.debug);
558
+ this.valve = new MatterbridgeEndpoint([waterValve, bridgedNode, powerSource], { uniqueStorageKey: 'Water valve' }, this.config.debug);
615
559
  this.valve.log.logName = 'Water valve';
616
560
  this.valve.createDefaultBridgedDeviceBasicInformationClusterServer('Water valve', '0x96382864WV', 0xfff1, 'Matterbridge', 'Matterbridge Water valve', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
617
561
  this.valve.createDefaultIdentifyClusterServer();
618
562
  this.valve.createDefaultValveConfigurationAndControlClusterServer();
619
- this.valve.addDeviceType(powerSource);
620
563
  this.valve.createDefaultPowerSourceWiredClusterServer();
621
564
  await this.registerDevice(this.valve);
622
565
  this.bridgedDevices.set(this.valve.deviceName ?? '', this.valve);
623
566
  this.valve.addCommandHandler('identify', async ({ request: { identifyTime } }) => {
624
567
  this.valve?.log.info(`Command identify called identifyTime:${identifyTime}`);
625
568
  });
626
- // Create a fan device
627
- this.fan = await this.createMutableDevice([fanDevice, bridgedNode], { uniqueStorageKey: 'Fan' }, this.config.debug);
569
+ this.fan = new MatterbridgeEndpoint([fanDevice, bridgedNode], { uniqueStorageKey: 'Fan' }, this.config.debug);
628
570
  this.fan.log.logName = 'Fan';
629
571
  this.fan.createDefaultBridgedDeviceBasicInformationClusterServer('Fan', 'serial_980545631228', 0xfff1, 'Matterbridge', 'Matterbridge Fan', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
630
- this.fan.addDeviceTypeWithClusterServer([fanDevice], []);
572
+ this.fan.addRequiredClusterServers();
631
573
  await this.registerDevice(this.fan);
632
574
  this.bridgedDevices.set(this.fan.deviceName ?? '', this.fan);
633
575
  this.fan.subscribeAttribute(FanControlCluster.id, 'fanMode', async (newValue, oldValue) => {
@@ -650,7 +592,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
650
592
  else if (newValue === FanControl.FanMode.Auto) {
651
593
  await this.fan?.setAttribute(FanControlCluster.id, 'percentCurrent', 50, this.fan?.log);
652
594
  }
653
- }, this.fan.log, this.fan);
595
+ }, this.fan.log);
654
596
  this.fan.subscribeAttribute(FanControlCluster.id, 'percentSetting', async (newValue, oldValue) => {
655
597
  this.fan?.log.info(`Percent setting changed from ${oldValue} to ${newValue}`);
656
598
  if (isValidNumber(newValue, 0, 100))
@@ -661,45 +603,43 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
661
603
  if (isValidNumber(newValue, 0, 100))
662
604
  await this.fan?.setAttribute(FanControlCluster.id, 'speedCurrent', newValue, this.fan?.log);
663
605
  }, this.fan.log);
664
- /** ********************* Create a waterLeakDetector device ***********************/
665
- this.waterLeak = await this.createMutableDevice([waterLeakDetector, bridgedNode], { uniqueStorageKey: 'Water leak detector' }, this.config.debug);
606
+ this.waterLeak = new MatterbridgeEndpoint([waterLeakDetector, bridgedNode], { uniqueStorageKey: 'Water leak detector' }, this.config.debug);
666
607
  this.waterLeak.log.logName = 'Water leak detector';
667
608
  this.waterLeak.createDefaultBridgedDeviceBasicInformationClusterServer('Water leak detector', 'serial_98745631222', 0xfff1, 'Matterbridge', 'Matterbridge WaterLeakDetector', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
668
- this.waterLeak.addDeviceTypeWithClusterServer([waterLeakDetector], [BooleanStateConfiguration.Cluster.id]);
609
+ this.waterLeak.addRequiredClusterServers();
610
+ this.waterLeak.addOptionalClusterServers();
669
611
  await this.registerDevice(this.waterLeak);
670
612
  this.bridgedDevices.set(this.waterLeak.deviceName ?? '', this.waterLeak);
671
613
  await this.waterLeak.setAttribute(BooleanStateCluster.id, 'stateValue', false, this.waterLeak.log);
672
- /** ********************* Create a waterFreezeDetector device ***********************/
673
- this.waterFreeze = await this.createMutableDevice([waterFreezeDetector, bridgedNode], { uniqueStorageKey: 'Water freeze detector' }, this.config.debug);
614
+ this.waterFreeze = new MatterbridgeEndpoint([waterFreezeDetector, bridgedNode], { uniqueStorageKey: 'Water freeze detector' }, this.config.debug);
674
615
  this.waterFreeze.log.logName = 'Water freeze detector';
675
616
  this.waterFreeze.createDefaultBridgedDeviceBasicInformationClusterServer('Water freeze detector', 'serial_98745631223', 0xfff1, 'Matterbridge', 'Matterbridge WaterFreezeDetector', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
676
- this.waterFreeze.addDeviceTypeWithClusterServer([waterFreezeDetector], [BooleanStateConfiguration.Cluster.id]);
617
+ this.waterFreeze.addRequiredClusterServers();
618
+ this.waterFreeze.addOptionalClusterServers();
677
619
  await this.registerDevice(this.waterFreeze);
678
620
  this.bridgedDevices.set(this.waterFreeze.deviceName ?? '', this.waterFreeze);
679
621
  await this.waterFreeze.setAttribute(BooleanStateCluster.id, 'stateValue', false, this.waterFreeze.log);
680
- /** ********************* Create a rainSensor device ***********************/
681
- this.rain = await this.createMutableDevice([rainSensor, bridgedNode], { uniqueStorageKey: 'Rain sensor' }, this.config.debug);
622
+ this.rain = new MatterbridgeEndpoint([rainSensor, bridgedNode], { uniqueStorageKey: 'Rain sensor' }, this.config.debug);
682
623
  this.rain.log.logName = 'Rain sensor';
683
624
  this.rain.createDefaultBridgedDeviceBasicInformationClusterServer('Rain sensor', 'serial_98745631224', 0xfff1, 'Matterbridge', 'Matterbridge RainSensor', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
684
- this.rain.addDeviceTypeWithClusterServer([rainSensor], [BooleanStateConfiguration.Cluster.id]);
625
+ this.rain.createDefaultIdentifyClusterServer();
626
+ this.rain.createDefaultBooleanStateClusterServer(false);
627
+ this.rain.createDefaultBooleanStateConfigurationClusterServer();
685
628
  await this.registerDevice(this.rain);
686
629
  this.bridgedDevices.set(this.rain.deviceName ?? '', this.rain);
687
- await this.rain.setAttribute(BooleanStateCluster.id, 'stateValue', false, this.rain.log);
688
- /** ********************* Create a smokeCoAlarm device ***********************/
689
- this.smoke = await this.createMutableDevice([smokeCoAlarm, bridgedNode], { uniqueStorageKey: 'Smoke alarm sensor' }, this.config.debug);
630
+ this.smoke = new MatterbridgeEndpoint([smokeCoAlarm, bridgedNode], { uniqueStorageKey: 'Smoke alarm sensor' }, this.config.debug);
690
631
  this.smoke.log.logName = 'Smoke alarm sensor';
691
632
  this.smoke.createDefaultBridgedDeviceBasicInformationClusterServer('Smoke alarm sensor', 'serial_94745631225', 0xfff1, 'Matterbridge', 'Matterbridge SmokeCoAlarm', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
692
- this.smoke.addDeviceTypeWithClusterServer([smokeCoAlarm], [CarbonMonoxideConcentrationMeasurement.Cluster.id]);
633
+ this.smoke.createDefaultIdentifyClusterServer();
634
+ this.smoke.createDefaultSmokeCOAlarmClusterServer(SmokeCoAlarm.AlarmState.Normal, SmokeCoAlarm.AlarmState.Normal);
635
+ this.smoke.createDefaultCarbonMonoxideConcentrationMeasurementClusterServer(100);
693
636
  await this.registerDevice(this.smoke);
694
637
  this.bridgedDevices.set(this.smoke.deviceName ?? '', this.smoke);
695
- await this.smoke.setAttribute(SmokeCoAlarmCluster.id, 'smokeState', SmokeCoAlarm.AlarmState.Normal, this.smoke.log);
696
- await this.smoke.setAttribute(SmokeCoAlarmCluster.id, 'coState', SmokeCoAlarm.AlarmState.Normal, this.smoke.log);
697
- await this.smoke.setAttribute(CarbonMonoxideConcentrationMeasurement.Cluster.id, 'measuredValue', 100, this.smoke.log);
698
- // Create an airQuality device
699
- this.airQuality = await this.createMutableDevice([airQualitySensor, bridgedNode], { uniqueStorageKey: 'Air quality sensor' }, this.config.debug);
638
+ this.airQuality = new MatterbridgeEndpoint([airQualitySensor, bridgedNode], { uniqueStorageKey: 'Air quality sensor' }, this.config.debug);
700
639
  this.airQuality.log.logName = 'Air quality Sensor';
701
640
  this.airQuality.createDefaultBridgedDeviceBasicInformationClusterServer('Air quality sensor', 'serial_987484318322', 0xfff1, 'Matterbridge', 'Matterbridge Air Quality Sensor', parseInt(this.version.replace(/\D/g, '')), this.version === '' ? 'Unknown' : this.version, parseInt(this.matterbridge.matterbridgeVersion.replace(/\D/g, '')), this.matterbridge.matterbridgeVersion);
702
- this.airQuality.addDeviceTypeWithClusterServer([airQualitySensor], [
641
+ this.airQuality.addRequiredClusterServers();
642
+ this.airQuality.addClusterServers([
703
643
  TemperatureMeasurement.Cluster.id,
704
644
  RelativeHumidityMeasurement.Cluster.id,
705
645
  CarbonMonoxideConcentrationMeasurement.Cluster.id,
@@ -732,10 +672,8 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
732
672
  async onConfigure() {
733
673
  await super.onConfigure();
734
674
  this.log.info('onConfigure called');
735
- // Set switch to off
736
675
  await this.switch?.setAttribute(OnOffCluster.id, 'onOff', false, this.switch.log);
737
676
  this.switch?.log.info('Set switch initial onOff to false');
738
- // Toggle switch onOff every minute
739
677
  this.switchInterval = setInterval(async () => {
740
678
  const status = this.switch?.getAttribute(OnOffCluster.id, 'onOff', this.switch.log);
741
679
  if (isValidBoolean(status)) {
@@ -743,35 +681,29 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
743
681
  this.switch?.log.info(`Set switch onOff to ${!status}`);
744
682
  }
745
683
  }, 60 * 1000 + 100);
746
- // Set light on/off to off
747
684
  await this.lightOnOff?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightOnOff.log);
748
685
  this.lightOnOff?.log.info('Set light initial onOff to false.');
749
- // Set light on/off to off
750
686
  await this.dimmer?.setAttribute(OnOffCluster.id, 'onOff', false, this.dimmer.log);
751
687
  await this.dimmer?.setAttribute(LevelControlCluster.id, 'currentLevel', 1, this.dimmer.log);
752
688
  this.dimmer?.log.info(`Set dimmer initial onOff to false, currentLevel to 1.`);
753
- // Set light to off, level to 0 and hue to 0 and saturation to 50% (pink color)
754
689
  await this.light?.setAttribute(OnOffCluster.id, 'onOff', false, this.light.log);
755
690
  await this.light?.setAttribute(LevelControlCluster.id, 'currentLevel', 1, this.light.log);
756
691
  await this.light?.setAttribute(ColorControlCluster.id, 'currentHue', 0, this.light.log);
757
692
  await this.light?.setAttribute(ColorControlCluster.id, 'currentSaturation', 128, this.light.log);
758
693
  await this.light?.configureColorControlMode(ColorControl.ColorMode.CurrentHueAndCurrentSaturation);
759
694
  this.light?.log.info('Set light initial onOff to false, currentLevel to 1, hue to 0 and saturation to 50%.');
760
- // Set light XY to true, level to 100% and XY to red
761
695
  await this.lightXY?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightXY.log);
762
696
  await this.lightXY?.setAttribute(LevelControlCluster.id, 'currentLevel', 254, this.lightXY.log);
763
697
  await this.lightXY?.setAttribute(ColorControlCluster.id, 'currentX', 0.7006 * 65536, this.lightXY.log);
764
698
  await this.lightXY?.setAttribute(ColorControlCluster.id, 'currentY', 0.2993 * 65536, this.lightXY.log);
765
699
  await this.lightXY?.configureColorControlMode(ColorControl.ColorMode.CurrentXAndCurrentY);
766
700
  this.lightXY?.log.info('Set light XY initial onOff to true, currentLevel to 254, X to 0.7006 and Y to 0.2993.');
767
- // Set light HS to off, level to 0 and hue to 0 and saturation to 50% (pink color)
768
701
  await this.lightHS?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightHS.log);
769
702
  await this.lightHS?.setAttribute(LevelControlCluster.id, 'currentLevel', 1, this.lightHS.log);
770
703
  await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentHue', 0, this.lightHS.log);
771
704
  await this.lightHS?.setAttribute(ColorControlCluster.id, 'currentSaturation', 128, this.lightHS.log);
772
705
  await this.lightHS?.configureColorControlMode(ColorControl.ColorMode.CurrentHueAndCurrentSaturation);
773
706
  this.lightHS?.log.info('Set light HS initial onOff to false, currentLevel to 1, hue to 0 and saturation to 50%.');
774
- // Set light CT to true, level to 50% and colorTemperatureMireds to 250
775
707
  await this.lightCT?.setAttribute(OnOffCluster.id, 'onOff', true, this.lightCT.log);
776
708
  await this.lightCT?.setAttribute(LevelControlCluster.id, 'currentLevel', 128, this.lightCT.log);
777
709
  await this.lightCT?.setAttribute(ColorControlCluster.id, 'colorTemperatureMireds', 250, this.lightCT.log);
@@ -782,7 +714,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
782
714
  let level = this.light?.getAttribute(LevelControlCluster.id, 'currentLevel', this.light.log);
783
715
  if (isValidBoolean(state) && isValidNumber(level, 0, 254)) {
784
716
  level += 10;
785
- if (level >= 250) {
717
+ if (level >= 230) {
786
718
  level = 1;
787
719
  await this.lightOnOff?.setAttribute(OnOffCluster.id, 'onOff', false, this.lightOnOff.log);
788
720
  await this.dimmer?.setAttribute(OnOffCluster.id, 'onOff', false, this.dimmer.log);
@@ -814,14 +746,9 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
814
746
  this.log.info(`Set lights currentLevel to ${level}`);
815
747
  }
816
748
  }
817
- else {
818
- this.log.error(`Invalid state ${state} or level ${level}`);
819
- }
820
749
  }, 60 * 1000 + 200);
821
- // Set outlet to off
822
750
  await this.outlet?.setAttribute(OnOffCluster.id, 'onOff', false, this.outlet.log);
823
751
  this.outlet?.log.info('Set outlet initial onOff to false');
824
- // Toggle outlet onOff every minute
825
752
  this.outletInterval = setInterval(async () => {
826
753
  const state = this.outlet?.getAttribute(OnOffCluster.id, 'onOff', this.outlet.log);
827
754
  if (isValidBoolean(state)) {
@@ -829,10 +756,8 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
829
756
  this.outlet?.log.info(`Set outlet onOff to ${!state}`);
830
757
  }
831
758
  }, 60 * 1000 + 300);
832
- // Set cover to target = current position and status to stopped (current position is persisted in the cluster)
833
759
  await this.cover?.setWindowCoveringTargetAsCurrentAndStopped();
834
760
  this.cover?.log.info('Set cover initial targetPositionLiftPercent100ths = currentPositionLiftPercent100ths and operationalStatus to Stopped.');
835
- // Increment cover position every minute
836
761
  this.coverInterval = setInterval(async () => {
837
762
  let position = this.cover?.getAttribute(WindowCoveringCluster.id, 'currentPositionLiftPercent100ths', this.cover.log);
838
763
  if (isValidNumber(position, 0, 10000)) {
@@ -843,10 +768,8 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
843
768
  this.cover?.log.info(`Set cover current and target positionLiftPercent100ths to ${position} and operationalStatus to Stopped`);
844
769
  }
845
770
  }, 60 * 1000 + 400);
846
- // Set lock to Locked
847
771
  await this.lock?.setAttribute(DoorLockCluster.id, 'lockState', DoorLock.LockState.Locked, this.lock.log);
848
772
  this.lock?.log.info('Set lock initial lockState to Locked');
849
- // Toggle lock every minute
850
773
  this.lockInterval = setInterval(async () => {
851
774
  const status = this.lock?.getAttribute(DoorLockCluster.id, 'lockState', this.lock.log);
852
775
  if (isValidNumber(status, DoorLock.LockState.Locked, DoorLock.LockState.Unlocked)) {
@@ -854,18 +777,16 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
854
777
  this.lock?.log.info(`Set lock lockState to ${status === DoorLock.LockState.Locked ? 'Unlocked' : 'Locked'}`);
855
778
  }
856
779
  }, 60 * 1000 + 500);
857
- // Set local to 16°C
858
780
  await this.thermoAuto?.setAttribute(ThermostatCluster.id, 'localTemperature', 16 * 100, this.thermoAuto.log);
859
781
  await this.thermoAuto?.setAttribute(ThermostatCluster.id, 'systemMode', Thermostat.SystemMode.Auto, this.thermoAuto.log);
860
782
  this.thermoAuto?.log.info('Set thermostat initial localTemperature to 16°C and mode Auto');
861
783
  const temperature = this.thermoAuto?.getChildEndpointByName('Temperature');
862
- await this.thermoAuto?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', 16 * 100, this.thermoAuto.log, temperature);
784
+ await temperature?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', 16 * 100, this.thermoAuto?.log);
863
785
  const humidity = this.thermoAuto?.getChildEndpointByName('Humidity');
864
- await this.thermoAuto?.setAttribute(RelativeHumidityMeasurementCluster.id, 'measuredValue', 50 * 100, this.thermoAuto.log, humidity);
786
+ await humidity?.setAttribute(RelativeHumidityMeasurementCluster.id, 'measuredValue', 50 * 100, this.thermoAuto?.log);
865
787
  const flow = this.thermoAuto?.getChildEndpointByName('Flow');
866
- await this.thermoAuto?.setAttribute(FlowMeasurementCluster.id, 'measuredValue', 10, this.thermoAuto.log, flow);
788
+ await flow?.setAttribute(FlowMeasurementCluster.id, 'measuredValue', 10, this.thermoAuto?.log);
867
789
  this.thermoAuto?.log.info('Set thermostat ext temperature to 16°C, ext humidity to 50% and ext valve flow to 10');
868
- // Increment localTemperature every minute
869
790
  this.thermoInterval = setInterval(async () => {
870
791
  let temperature = this.thermoAuto?.getAttribute(ThermostatCluster.id, 'localTemperature', this.thermoAuto.log);
871
792
  if (isValidNumber(temperature, 1600, 2400)) {
@@ -877,20 +798,19 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
877
798
  const tempOut = this.thermoHeat?.getChildEndpointByName('TemperatureOUT');
878
799
  await tempOut?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', temperature - 400, this.thermoHeat?.log);
879
800
  await this.thermoCool?.setAttribute(ThermostatCluster.id, 'localTemperature', temperature, this.thermoCool.log);
880
- const temp = this.thermoAuto?.getChildEndpointByName('Temperature');
881
- await this.thermoAuto?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', temperature, this.thermoAuto.log, temp);
882
- const humidity = this.thermoAuto?.getChildEndpointByName('Humidity');
883
- await this.thermoAuto?.setAttribute(RelativeHumidityMeasurementCluster.id, 'measuredValue', 50 * 100, this.thermoAuto.log, humidity);
884
- const flow = this.thermoAuto?.getChildEndpointByName('Flow');
885
- await this.thermoAuto?.setAttribute(FlowMeasurementCluster.id, 'measuredValue', 10, this.thermoAuto.log, flow);
801
+ const temp = this.thermoCool?.getChildEndpointByName('Temperature');
802
+ await temp?.setAttribute(TemperatureMeasurementCluster.id, 'measuredValue', temperature, this.thermoCool?.log);
803
+ const humidity = this.thermoCool?.getChildEndpointByName('Humidity');
804
+ await humidity?.setAttribute(RelativeHumidityMeasurementCluster.id, 'measuredValue', 50 * 100, this.thermoCool?.log);
805
+ const flow = this.thermoCool?.getChildEndpointByName('Flow');
806
+ await flow?.setAttribute(FlowMeasurementCluster.id, 'measuredValue', 10, this.thermoCool?.log);
886
807
  this.thermoAuto?.log.info(`Set thermostat localTemperature to ${temperature / 100}°C`);
887
808
  this.thermoHeat?.log.info(`Set thermostat localTemperature to ${temperature / 100}°C`);
888
809
  this.thermoCool?.log.info(`Set thermostat localTemperature to ${temperature / 100}°C`);
889
810
  }
890
811
  }, 60 * 1000 + 600);
891
- // Set airConditioner to on
892
812
  await this.airConditioner?.setAttribute(OnOffCluster.id, 'onOff', true, this.airConditioner.log);
893
- // Increment airConditioner localTemperature every minute
813
+ await this.airConditioner?.setAttribute(ThermostatCluster.id, 'localTemperature', 2000, this.airConditioner.log);
894
814
  this.airConditionerInterval = setInterval(async () => {
895
815
  let temperature = this.airConditioner?.getAttribute(ThermostatCluster.id, 'localTemperature', this.airConditioner.log);
896
816
  if (isValidNumber(temperature, 1600, 2400)) {
@@ -901,14 +821,12 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
901
821
  this.airConditioner?.log.info(`Set airConditioner localTemperature to ${temperature / 100}°C`);
902
822
  }
903
823
  }, 60 * 1000 + 550);
904
- // Set fan to auto
905
824
  this.fan?.log.info('Set fan initial fanMode to Auto, percentCurrent and percentSetting to 50 and speedCurrent and speedSetting to 50');
906
825
  await this.fan?.setAttribute(FanControlCluster.id, 'fanMode', FanControl.FanMode.Auto, this.fan.log);
907
826
  await this.fan?.setAttribute(FanControlCluster.id, 'percentCurrent', 50, this.fan.log);
908
827
  await this.fan?.setAttribute(FanControlCluster.id, 'percentSetting', 50, this.fan.log);
909
828
  await this.fan?.setAttribute(FanControlCluster.id, 'speedCurrent', 50, this.fan.log);
910
829
  await this.fan?.setAttribute(FanControlCluster.id, 'speedSetting', 50, this.fan.log);
911
- // Increment fan percentCurrent every minute
912
830
  this.fanInterval = setInterval(async () => {
913
831
  const mode = this.fan?.getAttribute(FanControlCluster.id, 'fanMode', this.fan.log);
914
832
  let value = this.fan?.getAttribute(FanControlCluster.id, 'percentCurrent', this.fan.log);
@@ -919,9 +837,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
919
837
  this.fan?.log.info(`Set fan percentCurrent and percentSetting to ${value}`);
920
838
  }
921
839
  }, 60 * 1000 + 700);
922
- // Set waterLeak to false
923
840
  await this.waterLeak?.setAttribute(BooleanStateCluster.id, 'stateValue', false, this.waterLeak.log);
924
- // Toggle waterLeak every minute
925
841
  this.waterLeakInterval = setInterval(async () => {
926
842
  let value = this.waterLeak?.getAttribute(BooleanStateCluster.id, 'stateValue', this.waterLeak.log);
927
843
  if (isValidBoolean(value)) {
@@ -930,9 +846,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
930
846
  this.waterLeak?.log.info(`Set waterLeak stateValue to ${value}`);
931
847
  }
932
848
  }, 60 * 1000 + 800);
933
- // Set waterFreeze to false
934
849
  await this.waterFreeze?.setAttribute(BooleanStateCluster.id, 'stateValue', false, this.waterFreeze.log);
935
- // Toggle waterFreeze every minute
936
850
  this.waterFreezeInterval = setInterval(async () => {
937
851
  let value = this.waterFreeze?.getAttribute(BooleanStateCluster.id, 'stateValue', this.waterFreeze.log);
938
852
  if (isValidBoolean(value)) {
@@ -941,9 +855,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
941
855
  this.waterFreeze?.log.info(`Set waterFreeze stateValue to ${value}`);
942
856
  }
943
857
  }, 60 * 1000 + 900);
944
- // Set rain to false
945
858
  await this.rain?.setAttribute(BooleanStateCluster.id, 'stateValue', false, this.rain.log);
946
- // Toggle rain every minute
947
859
  this.rainInterval = setInterval(async () => {
948
860
  let value = this.rain?.getAttribute(BooleanStateCluster.id, 'stateValue', this.rain.log);
949
861
  if (isValidBoolean(value)) {
@@ -952,10 +864,8 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
952
864
  this.rain?.log.info(`Set rain stateValue to ${value}`);
953
865
  }
954
866
  }, 60 * 1000 + 1000);
955
- // Set smoke to Normal
956
867
  await this.smoke?.setAttribute(SmokeCoAlarmCluster.id, 'smokeState', SmokeCoAlarm.AlarmState.Normal, this.smoke.log);
957
868
  await this.smoke?.setAttribute(SmokeCoAlarmCluster.id, 'coState', SmokeCoAlarm.AlarmState.Normal, this.smoke.log);
958
- // Toggle smoke every minute
959
869
  this.smokeInterval = setInterval(async () => {
960
870
  let value = this.smoke?.getAttribute(SmokeCoAlarmCluster.id, 'smokeState', this.smoke.log);
961
871
  if (isValidNumber(value, SmokeCoAlarm.AlarmState.Normal, SmokeCoAlarm.AlarmState.Critical)) {
@@ -965,9 +875,7 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
965
875
  this.smoke?.log.info(`Set smoke smokeState and coState to ${value}`);
966
876
  }
967
877
  }, 60 * 1000 + 1100);
968
- // Set air quality to Normal
969
878
  this.airQuality?.setAttribute(AirQualityCluster.id, 'airQuality', AirQuality.AirQualityEnum.Good, this.airQuality.log);
970
- // Toggle air quality every minute
971
879
  this.airQualityInterval = setInterval(async () => {
972
880
  let value = this.airQuality?.getAttribute(AirQualityCluster.id, 'airQuality', this.airQuality?.log);
973
881
  if (isValidNumber(value, AirQuality.AirQualityEnum.Good, AirQuality.AirQualityEnum.ExtremelyPoor)) {
@@ -978,8 +886,6 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
978
886
  }, 60 * 1000 + 1100);
979
887
  }
980
888
  async onShutdown(reason) {
981
- await super.onShutdown(reason);
982
- this.log.info('onShutdown called with reason:', reason ?? 'none');
983
889
  clearInterval(this.switchInterval);
984
890
  clearInterval(this.lightInterval);
985
891
  clearInterval(this.outletInterval);
@@ -993,8 +899,9 @@ export class ExampleMatterbridgeDynamicPlatform extends MatterbridgeDynamicPlatf
993
899
  clearInterval(this.smokeInterval);
994
900
  clearInterval(this.airQualityInterval);
995
901
  clearInterval(this.airConditionerInterval);
902
+ await super.onShutdown(reason);
903
+ this.log.info('onShutdown called with reason:', reason ?? 'none');
996
904
  if (this.config.unregisterOnShutdown === true)
997
905
  await this.unregisterAllDevices();
998
906
  }
999
907
  }
1000
- //# sourceMappingURL=platform.js.map