@switchbot/homebridge-switchbot 2.8.2 → 2.9.0-beta.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.
@@ -29,38 +29,296 @@ class Others {
29
29
  .setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.setFirmwareRevision(accessory, device))
30
30
  .getCharacteristic(this.platform.Characteristic.FirmwareRevision)
31
31
  .updateValue(this.setFirmwareRevision(accessory, device));
32
- // get the Television service if it exists, otherwise create a new Television service
33
- // you can create multiple services for each accessory
34
- if (this.otherDeviceType !== 'Fan') {
35
- this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Removing Fanv2 Service`);
36
- if (this.otherDeviceType === undefined) {
37
- this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${device.other?.deviceType}`);
38
- }
39
- this.fanService = this.accessory.getService(this.platform.Service.Fanv2);
40
- accessory.removeService(this.fanService);
41
- }
42
- else if (!this.fanService && this.otherDeviceType === 'Fan') {
43
- this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Add Fanv2 Service`);
44
- (this.fanService = this.accessory.getService(this.platform.Service.Fanv2) || this.accessory.addService(this.platform.Service.Fanv2)),
32
+ // deviceType
33
+ if (this.otherDeviceType === 'switch') {
34
+ this.removeFanService(accessory);
35
+ this.removeLockService(accessory);
36
+ this.removeDoorService(accessory);
37
+ this.removeFaucetService(accessory);
38
+ this.removeOutletService(accessory);
39
+ this.removeWindowService(accessory);
40
+ this.removeGarageDoorService(accessory);
41
+ this.removeWindowCoveringService(accessory);
42
+ this.removeStatefulProgrammableSwitchService(accessory);
43
+ // Add switchService
44
+ (this.switchService = accessory.getService(this.platform.Service.Switch) || accessory.addService(this.platform.Service.Switch)),
45
+ `${accessory.displayName} Switch`;
46
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Switch`);
47
+ this.switchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
48
+ if (!this.switchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
49
+ this.switchService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
50
+ }
51
+ this.switchService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
52
+ }
53
+ else if (this.otherDeviceType === 'garagedoor') {
54
+ this.removeFanService(accessory);
55
+ this.removeLockService(accessory);
56
+ this.removeDoorService(accessory);
57
+ this.removeFaucetService(accessory);
58
+ this.removeOutletService(accessory);
59
+ this.removeSwitchService(accessory);
60
+ this.removeWindowService(accessory);
61
+ this.removeWindowCoveringService(accessory);
62
+ this.removeStatefulProgrammableSwitchService(accessory);
63
+ // Add switchService
64
+ (this.garageDoorService =
65
+ accessory.getService(this.platform.Service.GarageDoorOpener) || accessory.addService(this.platform.Service.GarageDoorOpener)),
66
+ `${accessory.displayName} Garage Door Opener`;
67
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Garage Door Opener`);
68
+ this.garageDoorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
69
+ if (!this.garageDoorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
70
+ this.garageDoorService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
71
+ }
72
+ this.garageDoorService.getCharacteristic(this.platform.Characteristic.TargetDoorState).onSet(this.OnSet.bind(this));
73
+ this.garageDoorService.setCharacteristic(this.platform.Characteristic.ObstructionDetected, false);
74
+ }
75
+ else if (this.otherDeviceType === 'door') {
76
+ this.removeFanService(accessory);
77
+ this.removeLockService(accessory);
78
+ this.removeOutletService(accessory);
79
+ this.removeFaucetService(accessory);
80
+ this.removeSwitchService(accessory);
81
+ this.removeWindowService(accessory);
82
+ this.removeGarageDoorService(accessory);
83
+ this.removeWindowCoveringService(accessory);
84
+ this.removeStatefulProgrammableSwitchService(accessory);
85
+ // Add switchService
86
+ (this.doorService = accessory.getService(this.platform.Service.Door) || accessory.addService(this.platform.Service.Door)),
87
+ `${accessory.displayName} Door`;
88
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Door`);
89
+ this.doorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
90
+ if (!this.doorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
91
+ this.doorService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
92
+ }
93
+ this.doorService
94
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
95
+ .setProps({
96
+ validValues: [0, 100],
97
+ minValue: 0,
98
+ maxValue: 100,
99
+ minStep: 100,
100
+ })
101
+ .onSet(this.OnSet.bind(this));
102
+ this.doorService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
103
+ }
104
+ else if (this.otherDeviceType === 'window') {
105
+ this.removeFanService(accessory);
106
+ this.removeLockService(accessory);
107
+ this.removeDoorService(accessory);
108
+ this.removeOutletService(accessory);
109
+ this.removeFaucetService(accessory);
110
+ this.removeSwitchService(accessory);
111
+ this.removeGarageDoorService(accessory);
112
+ this.removeWindowCoveringService(accessory);
113
+ this.removeStatefulProgrammableSwitchService(accessory);
114
+ // Add switchService
115
+ (this.windowService = accessory.getService(this.platform.Service.Window) || accessory.addService(this.platform.Service.Window)),
116
+ `${accessory.displayName} Window`;
117
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window`);
118
+ this.windowService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
119
+ if (!this.windowService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
120
+ this.windowService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
121
+ }
122
+ this.windowService
123
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
124
+ .setProps({
125
+ validValues: [0, 100],
126
+ minValue: 0,
127
+ maxValue: 100,
128
+ minStep: 100,
129
+ })
130
+ .onSet(this.OnSet.bind(this));
131
+ this.windowService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
132
+ }
133
+ else if (this.otherDeviceType === 'windowcovering') {
134
+ this.removeFanService(accessory);
135
+ this.removeLockService(accessory);
136
+ this.removeDoorService(accessory);
137
+ this.removeOutletService(accessory);
138
+ this.removeFaucetService(accessory);
139
+ this.removeSwitchService(accessory);
140
+ this.removeWindowService(accessory);
141
+ this.removeGarageDoorService(accessory);
142
+ this.removeStatefulProgrammableSwitchService(accessory);
143
+ // Add switchService
144
+ (this.windowCoveringService =
145
+ accessory.getService(this.platform.Service.WindowCovering) || accessory.addService(this.platform.Service.WindowCovering)),
146
+ `${accessory.displayName} Window Covering`;
147
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Window Covering`);
148
+ this.windowCoveringService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
149
+ if (!this.windowCoveringService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
150
+ this.windowCoveringService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
151
+ }
152
+ this.windowCoveringService
153
+ .getCharacteristic(this.platform.Characteristic.TargetPosition)
154
+ .setProps({
155
+ validValues: [0, 100],
156
+ minValue: 0,
157
+ maxValue: 100,
158
+ minStep: 100,
159
+ })
160
+ .onSet(this.OnSet.bind(this));
161
+ this.windowCoveringService.setCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
162
+ }
163
+ else if (this.otherDeviceType === 'lock') {
164
+ this.removeFanService(accessory);
165
+ this.removeDoorService(accessory);
166
+ this.removeOutletService(accessory);
167
+ this.removeSwitchService(accessory);
168
+ this.removeFaucetService(accessory);
169
+ this.removeWindowService(accessory);
170
+ this.removeGarageDoorService(accessory);
171
+ this.removeWindowCoveringService(accessory);
172
+ this.removeStatefulProgrammableSwitchService(accessory);
173
+ // Add switchService
174
+ (this.lockService = accessory.getService(this.platform.Service.LockMechanism) || accessory.addService(this.platform.Service.LockMechanism)),
175
+ `${accessory.displayName} Lock`;
176
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Lock`);
177
+ this.lockService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
178
+ if (!this.lockService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
179
+ this.lockService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
180
+ }
181
+ this.lockService.getCharacteristic(this.platform.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
182
+ }
183
+ else if (this.otherDeviceType === 'faucet') {
184
+ this.removeFanService(accessory);
185
+ this.removeLockService(accessory);
186
+ this.removeDoorService(accessory);
187
+ this.removeOutletService(accessory);
188
+ this.removeSwitchService(accessory);
189
+ this.removeWindowService(accessory);
190
+ this.removeGarageDoorService(accessory);
191
+ this.removeWindowCoveringService(accessory);
192
+ this.removeStatefulProgrammableSwitchService(accessory);
193
+ // Add switchService
194
+ (this.faucetService = accessory.getService(this.platform.Service.Faucet) || accessory.addService(this.platform.Service.Faucet)),
195
+ `${accessory.displayName} Faucet`;
196
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Faucet`);
197
+ this.faucetService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
198
+ if (!this.faucetService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
199
+ this.faucetService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
200
+ }
201
+ this.faucetService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.OnSet.bind(this));
202
+ }
203
+ else if (this.otherDeviceType === 'fan') {
204
+ this.removeLockService(accessory);
205
+ this.removeDoorService(accessory);
206
+ this.removeFaucetService(accessory);
207
+ this.removeOutletService(accessory);
208
+ this.removeSwitchService(accessory);
209
+ this.removeWindowService(accessory);
210
+ this.removeGarageDoorService(accessory);
211
+ this.removeWindowCoveringService(accessory);
212
+ this.removeStatefulProgrammableSwitchService(accessory);
213
+ // Add switchService
214
+ (this.fanService = accessory.getService(this.platform.Service.Fan) || accessory.addService(this.platform.Service.Fan)),
45
215
  `${accessory.displayName} Fan`;
46
- this.fanService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Fan`);
216
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Fan`);
217
+ this.fanService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
47
218
  if (!this.fanService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
48
- this.fanService.addCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Fan`);
219
+ this.fanService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
220
+ }
221
+ this.fanService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
222
+ }
223
+ else if (this.otherDeviceType === 'stateful') {
224
+ this.removeFanService(accessory);
225
+ this.removeLockService(accessory);
226
+ this.removeDoorService(accessory);
227
+ this.removeFaucetService(accessory);
228
+ this.removeOutletService(accessory);
229
+ this.removeSwitchService(accessory);
230
+ this.removeWindowService(accessory);
231
+ this.removeGarageDoorService(accessory);
232
+ this.removeWindowCoveringService(accessory);
233
+ // Add switchService
234
+ (this.statefulProgrammableSwitchService =
235
+ accessory.getService(this.platform.Service.StatefulProgrammableSwitch) ||
236
+ accessory.addService(this.platform.Service.StatefulProgrammableSwitch)),
237
+ `${accessory.displayName} Stateful Programmable Switch`;
238
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Stateful Programmable Switch`);
239
+ this.statefulProgrammableSwitchService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
240
+ if (!this.statefulProgrammableSwitchService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
241
+ this.statefulProgrammableSwitchService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
49
242
  }
50
- this.fanService.getCharacteristic(this.platform.Characteristic.Active).onSet(this.ActiveSet.bind(this));
243
+ this.statefulProgrammableSwitchService
244
+ .getCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState)
245
+ .onSet(this.OnSet.bind(this));
51
246
  }
52
247
  else {
53
- this.debugLog(`${this.device.remoteType}: ${accessory.displayName} Fanv2 Service Not Added, deviceType: ${device.other?.deviceType}`);
248
+ this.removeFanService(accessory);
249
+ this.removeLockService(accessory);
250
+ this.removeDoorService(accessory);
251
+ this.removeFaucetService(accessory);
252
+ this.removeSwitchService(accessory);
253
+ this.removeWindowService(accessory);
254
+ this.removeGarageDoorService(accessory);
255
+ this.removeWindowCoveringService(accessory);
256
+ this.removeStatefulProgrammableSwitchService(accessory);
257
+ // Add outletService
258
+ (this.outletService = accessory.getService(this.platform.Service.Outlet) || accessory.addService(this.platform.Service.Outlet)),
259
+ `${accessory.displayName} Outlet`;
260
+ this.debugWarnLog(`${this.device.remoteType}: ${accessory.displayName} Displaying as Outlet`);
261
+ this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
262
+ if (!this.outletService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
263
+ this.outletService.addCharacteristic(this.platform.Characteristic.ConfiguredName, accessory.displayName);
264
+ }
265
+ this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
54
266
  }
55
267
  }
56
- async ActiveSet(value) {
57
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${value}`);
58
- this.Active = value;
59
- if (this.Active) {
60
- await this.pushOnChanges();
268
+ /**
269
+ * Handle requests to set the "On" characteristic
270
+ */
271
+ async OnSet(value) {
272
+ if (this.otherDeviceType === 'garagedoor') {
273
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetDoorState: ${value}`);
274
+ if (value === this.platform.Characteristic.TargetDoorState.CLOSED) {
275
+ this.On = false;
276
+ }
277
+ else {
278
+ this.On = true;
279
+ }
280
+ }
281
+ else if (this.otherDeviceType === 'door' ||
282
+ this.otherDeviceType === 'window' ||
283
+ this.otherDeviceType === 'windowcovering') {
284
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set TargetPosition: ${value}`);
285
+ if (value === 0) {
286
+ this.On = false;
287
+ }
288
+ else {
289
+ this.On = true;
290
+ }
291
+ }
292
+ else if (this.otherDeviceType === 'lock') {
293
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set LockTargetState: ${value}`);
294
+ if (value === this.platform.Characteristic.LockTargetState.SECURED) {
295
+ this.On = false;
296
+ }
297
+ else {
298
+ this.On = true;
299
+ }
300
+ }
301
+ else if (this.otherDeviceType === 'faucet') {
302
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set Active: ${value}`);
303
+ if (value === this.platform.Characteristic.Active.INACTIVE) {
304
+ this.On = false;
305
+ }
306
+ else {
307
+ this.On = true;
308
+ }
309
+ }
310
+ else if (this.otherDeviceType === 'stateful') {
311
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set ProgrammableSwitchOutputState: ${value}`);
312
+ if (value === 0) {
313
+ this.On = false;
314
+ }
315
+ else {
316
+ this.On = true;
317
+ }
61
318
  }
62
319
  else {
63
- await this.pushOffChanges();
320
+ this.infoLog(`${this.device.remoteType}: ${this.accessory.displayName} Set On: ${value}`);
321
+ this.On = value;
64
322
  }
65
323
  }
66
324
  /**
@@ -74,10 +332,10 @@ class Others {
74
332
  * Other - "command" "channelSub" "default" = previous channel
75
333
  */
76
334
  async pushOnChanges() {
77
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges Active: ${this.Active},` +
335
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOnChanges On: ${this.On},` +
78
336
  ` disablePushOn: ${this.disablePushOn}, customize: ${this.device.customize}, customOn: ${this.device.customOn}`);
79
337
  if (this.device.customize) {
80
- if (this.Active === this.platform.Characteristic.Active.ACTIVE && !this.disablePushOn) {
338
+ if (this.On && !this.disablePushOn) {
81
339
  const commandType = await this.commandType();
82
340
  const command = await this.commandOn();
83
341
  const bodyChange = JSON.stringify({
@@ -93,10 +351,10 @@ class Others {
93
351
  }
94
352
  }
95
353
  async pushOffChanges() {
96
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges Active: ${this.Active},` +
354
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} pushOffChanges On: ${this.On},` +
97
355
  ` disablePushOff: ${this.disablePushOff}, customize: ${this.device.customize}, customOff: ${this.device.customOff}`);
98
356
  if (this.device.customize) {
99
- if (this.Active === this.platform.Characteristic.Active.INACTIVE && !this.disablePushOff) {
357
+ if (!this.On && !this.disablePushOff) {
100
358
  const commandType = await this.commandType();
101
359
  const command = await this.commandOff();
102
360
  const bodyChange = JSON.stringify({
@@ -150,14 +408,172 @@ class Others {
150
408
  }
151
409
  }
152
410
  async updateHomeKitCharacteristics() {
153
- // Active
154
- if (this.Active === undefined) {
155
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Active: ${this.Active}`);
411
+ if (this.otherDeviceType === 'garagedoor') {
412
+ if (this.On === undefined) {
413
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
414
+ }
415
+ else {
416
+ if (this.On) {
417
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, this.platform.Characteristic.TargetDoorState.OPEN);
418
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, this.platform.Characteristic.CurrentDoorState.OPEN);
419
+ this.debugLog(`${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
420
+ }
421
+ else {
422
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, this.platform.Characteristic.TargetDoorState.CLOSED);
423
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, this.platform.Characteristic.CurrentDoorState.CLOSED);
424
+ this.debugLog(`${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open`);
425
+ }
426
+ }
427
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Garage Door On: ${this.On}`);
428
+ }
429
+ else if (this.otherDeviceType === 'door') {
430
+ if (this.On === undefined) {
431
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
432
+ }
433
+ else {
434
+ if (this.On) {
435
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
436
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
437
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
438
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
439
+ }
440
+ else {
441
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
442
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
443
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
444
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
445
+ }
446
+ }
447
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Door On: ${this.On}`);
448
+ }
449
+ else if (this.otherDeviceType === 'window') {
450
+ if (this.On === undefined) {
451
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
452
+ }
453
+ else {
454
+ if (this.On) {
455
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
456
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
457
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
458
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
459
+ }
460
+ else {
461
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
462
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
463
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
464
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
465
+ }
466
+ }
467
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window On: ${this.On}`);
468
+ }
469
+ else if (this.otherDeviceType === 'windowcovering') {
470
+ if (this.On === undefined) {
471
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
472
+ }
473
+ else {
474
+ if (this.On) {
475
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 100);
476
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 100);
477
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
478
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 100, CurrentPosition: 100`);
479
+ }
480
+ else {
481
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, 0);
482
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, 0);
483
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, this.platform.Characteristic.PositionState.STOPPED);
484
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic TargetPosition: 0, CurrentPosition: 0`);
485
+ }
486
+ }
487
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Window Covering On: ${this.On}`);
488
+ }
489
+ else if (this.otherDeviceType === 'lock') {
490
+ if (this.On === undefined) {
491
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
492
+ }
493
+ else {
494
+ if (this.On) {
495
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.platform.Characteristic.LockTargetState.UNSECURED);
496
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.platform.Characteristic.LockCurrentState.UNSECURED);
497
+ this.debugLog(`${this.device.remoteType}: ` +
498
+ `${this.accessory.displayName} updateCharacteristic LockTargetState: UNSECURED, LockCurrentState: UNSECURED`);
499
+ }
500
+ else {
501
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, this.platform.Characteristic.LockTargetState.SECURED);
502
+ this.lockService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, this.platform.Characteristic.LockCurrentState.SECURED);
503
+ this.debugLog(`${this.device.remoteType}: ` + `${this.accessory.displayName} updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED`);
504
+ }
505
+ }
506
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Lock On: ${this.On}`);
507
+ }
508
+ else if (this.otherDeviceType === 'faucet') {
509
+ if (this.On === undefined) {
510
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
511
+ }
512
+ else {
513
+ if (this.On) {
514
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.ACTIVE);
515
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
516
+ }
517
+ else {
518
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, this.platform.Characteristic.Active.INACTIVE);
519
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.On}`);
520
+ }
521
+ }
522
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Faucet On: ${this.On}`);
523
+ }
524
+ else if (this.otherDeviceType === 'fan') {
525
+ if (this.On === undefined) {
526
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
527
+ }
528
+ else {
529
+ if (this.On) {
530
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
531
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
532
+ }
533
+ else {
534
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
535
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
536
+ }
537
+ }
538
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} Fan On: ${this.On}`);
539
+ }
540
+ else if (this.otherDeviceType === 'stateful') {
541
+ if (this.On === undefined) {
542
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
543
+ }
544
+ else {
545
+ if (this.On) {
546
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
547
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 1);
548
+ this.debugLog(`${this.device.remoteType}: ` +
549
+ `${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 1`);
550
+ }
551
+ else {
552
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, this.platform.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
553
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, 0);
554
+ this.debugLog(`${this.device.remoteType}: ` +
555
+ `${this.accessory.displayName} updateCharacteristic ProgrammableSwitchEvent: SINGLE, ProgrammableSwitchOutputState: 0`);
556
+ }
557
+ }
558
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} StatefulProgrammableSwitch On: ${this.On}`);
559
+ }
560
+ else if (this.otherDeviceType === 'switch') {
561
+ if (this.On === undefined) {
562
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
563
+ }
564
+ else {
565
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
566
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
567
+ }
156
568
  }
157
569
  else {
158
- this.accessory.context.Active = this.Active;
159
- this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, this.Active);
160
- this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic Active: ${this.Active}`);
570
+ if (this.On === undefined) {
571
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} On: ${this.On}`);
572
+ }
573
+ else {
574
+ this.outletService?.updateCharacteristic(this.platform.Characteristic.On, this.On);
575
+ this.debugLog(`${this.device.remoteType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
576
+ }
161
577
  }
162
578
  // FirmwareRevision
163
579
  if (this.FirmwareRevision === undefined) {
@@ -251,8 +667,126 @@ class Others {
251
667
  }
252
668
  }
253
669
  async apiError(e) {
254
- this.fanService?.updateCharacteristic(this.platform.Characteristic.Active, e);
255
- //throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
670
+ if (this.otherDeviceType === 'garagedoor') {
671
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.TargetDoorState, e);
672
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.CurrentDoorState, e);
673
+ this.garageDoorService?.updateCharacteristic(this.platform.Characteristic.ObstructionDetected, e);
674
+ }
675
+ else if (this.otherDeviceType === 'door') {
676
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
677
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
678
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
679
+ }
680
+ else if (this.otherDeviceType === 'window') {
681
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
682
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
683
+ this.windowService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
684
+ }
685
+ else if (this.otherDeviceType === 'windowcovering') {
686
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.TargetPosition, e);
687
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.CurrentPosition, e);
688
+ this.windowCoveringService?.updateCharacteristic(this.platform.Characteristic.PositionState, e);
689
+ }
690
+ else if (this.otherDeviceType === 'lock') {
691
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.LockTargetState, e);
692
+ this.doorService?.updateCharacteristic(this.platform.Characteristic.LockCurrentState, e);
693
+ }
694
+ else if (this.otherDeviceType === 'faucet') {
695
+ this.faucetService?.updateCharacteristic(this.platform.Characteristic.Active, e);
696
+ }
697
+ else if (this.otherDeviceType === 'fan') {
698
+ this.fanService?.updateCharacteristic(this.platform.Characteristic.On, e);
699
+ }
700
+ else if (this.otherDeviceType === 'stateful') {
701
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchEvent, e);
702
+ this.statefulProgrammableSwitchService?.updateCharacteristic(this.platform.Characteristic.ProgrammableSwitchOutputState, e);
703
+ }
704
+ else if (this.otherDeviceType === 'switch') {
705
+ this.switchService?.updateCharacteristic(this.platform.Characteristic.On, e);
706
+ }
707
+ else {
708
+ this.outletService?.updateCharacteristic(this.platform.Characteristic.On, e);
709
+ }
710
+ }
711
+ async removeOutletService(accessory) {
712
+ // If outletService still pressent, then remove first
713
+ this.outletService = this.accessory.getService(this.platform.Service.Outlet);
714
+ if (this.outletService) {
715
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Outlet Service`);
716
+ }
717
+ accessory.removeService(this.outletService);
718
+ }
719
+ async removeGarageDoorService(accessory) {
720
+ // If garageDoorService still pressent, then remove first
721
+ this.garageDoorService = this.accessory.getService(this.platform.Service.GarageDoorOpener);
722
+ if (this.garageDoorService) {
723
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Garage Door Service`);
724
+ }
725
+ accessory.removeService(this.garageDoorService);
726
+ }
727
+ async removeDoorService(accessory) {
728
+ // If doorService still pressent, then remove first
729
+ this.doorService = this.accessory.getService(this.platform.Service.Door);
730
+ if (this.doorService) {
731
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Door Service`);
732
+ }
733
+ accessory.removeService(this.doorService);
734
+ }
735
+ async removeLockService(accessory) {
736
+ // If lockService still pressent, then remove first
737
+ this.lockService = this.accessory.getService(this.platform.Service.LockMechanism);
738
+ if (this.lockService) {
739
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Lock Service`);
740
+ }
741
+ accessory.removeService(this.lockService);
742
+ }
743
+ async removeFaucetService(accessory) {
744
+ // If faucetService still pressent, then remove first
745
+ this.faucetService = this.accessory.getService(this.platform.Service.Faucet);
746
+ if (this.faucetService) {
747
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Faucet Service`);
748
+ }
749
+ accessory.removeService(this.faucetService);
750
+ }
751
+ async removeFanService(accessory) {
752
+ // If fanService still pressent, then remove first
753
+ this.fanService = this.accessory.getService(this.platform.Service.Fan);
754
+ if (this.fanService) {
755
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Fan Service`);
756
+ }
757
+ accessory.removeService(this.fanService);
758
+ }
759
+ async removeWindowService(accessory) {
760
+ // If windowService still pressent, then remove first
761
+ this.windowService = this.accessory.getService(this.platform.Service.Window);
762
+ if (this.windowService) {
763
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Service`);
764
+ }
765
+ accessory.removeService(this.windowService);
766
+ }
767
+ async removeWindowCoveringService(accessory) {
768
+ // If windowCoveringService still pressent, then remove first
769
+ this.windowCoveringService = this.accessory.getService(this.platform.Service.WindowCovering);
770
+ if (this.windowCoveringService) {
771
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Window Covering Service`);
772
+ }
773
+ accessory.removeService(this.windowCoveringService);
774
+ }
775
+ async removeStatefulProgrammableSwitchService(accessory) {
776
+ // If statefulProgrammableSwitchService still pressent, then remove first
777
+ this.statefulProgrammableSwitchService = this.accessory.getService(this.platform.Service.StatefulProgrammableSwitch);
778
+ if (this.statefulProgrammableSwitchService) {
779
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Stateful Programmable Switch Service`);
780
+ }
781
+ accessory.removeService(this.statefulProgrammableSwitchService);
782
+ }
783
+ async removeSwitchService(accessory) {
784
+ // If switchService still pressent, then remove first
785
+ this.switchService = this.accessory.getService(this.platform.Service.Switch);
786
+ if (this.switchService) {
787
+ this.warnLog(`${this.device.remoteType}: ${accessory.displayName} Removing Leftover Switch Service`);
788
+ }
789
+ accessory.removeService(this.switchService);
256
790
  }
257
791
  async deviceType(device) {
258
792
  if (device.other?.deviceType) {
@@ -262,7 +796,9 @@ class Others {
262
796
  }
263
797
  }
264
798
  else {
799
+ this.otherDeviceType = 'outlet';
265
800
  this.errorLog(`${this.device.remoteType}: ${this.accessory.displayName} No Device Type Set, deviceType: ${this.device.other?.deviceType}`);
801
+ this.warnLog(`${this.device.remoteType}: ${this.accessory.displayName} Using default deviceType: ${this.otherDeviceType}`);
266
802
  }
267
803
  }
268
804
  setFirmwareRevision(accessory, device) {
@@ -282,11 +818,11 @@ class Others {
282
818
  return JSON.stringify(this.FirmwareRevision);
283
819
  }
284
820
  async context() {
285
- if (this.Active === undefined) {
286
- this.Active = this.platform.Characteristic.Active.INACTIVE;
821
+ if (this.On === undefined) {
822
+ this.On = true;
287
823
  }
288
824
  else {
289
- this.Active = this.accessory.context.Active;
825
+ this.On = this.accessory.context.On;
290
826
  }
291
827
  }
292
828
  async config(device) {