@switchbot/homebridge-switchbot 3.6.1-beta.1 → 3.6.1-beta.11

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.
Files changed (136) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +44 -17
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +1 -2
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +220 -397
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +3 -2
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +59 -31
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +3 -2
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +57 -29
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts.map +1 -1
  18. package/dist/device/contact.js +47 -18
  19. package/dist/device/contact.js.map +1 -1
  20. package/dist/device/curtain.d.ts.map +1 -1
  21. package/dist/device/curtain.js +16 -5
  22. package/dist/device/curtain.js.map +1 -1
  23. package/dist/device/device.d.ts +9 -0
  24. package/dist/device/device.d.ts.map +1 -1
  25. package/dist/device/device.js +30 -3
  26. package/dist/device/device.js.map +1 -1
  27. package/dist/device/fan.d.ts.map +1 -1
  28. package/dist/device/fan.js +44 -18
  29. package/dist/device/fan.js.map +1 -1
  30. package/dist/device/hub.d.ts.map +1 -1
  31. package/dist/device/hub.js +46 -18
  32. package/dist/device/hub.js.map +1 -1
  33. package/dist/device/humidifier.d.ts.map +1 -1
  34. package/dist/device/humidifier.js +45 -20
  35. package/dist/device/humidifier.js.map +1 -1
  36. package/dist/device/iosensor.d.ts.map +1 -1
  37. package/dist/device/iosensor.js +46 -18
  38. package/dist/device/iosensor.js.map +1 -1
  39. package/dist/device/lightstrip.d.ts +4 -3
  40. package/dist/device/lightstrip.d.ts.map +1 -1
  41. package/dist/device/lightstrip.js +60 -31
  42. package/dist/device/lightstrip.js.map +1 -1
  43. package/dist/device/lock.d.ts.map +1 -1
  44. package/dist/device/lock.js +48 -17
  45. package/dist/device/lock.js.map +1 -1
  46. package/dist/device/meter.d.ts.map +1 -1
  47. package/dist/device/meter.js +46 -18
  48. package/dist/device/meter.js.map +1 -1
  49. package/dist/device/meterplus.d.ts.map +1 -1
  50. package/dist/device/meterplus.js +46 -18
  51. package/dist/device/meterplus.js.map +1 -1
  52. package/dist/device/motion.d.ts.map +1 -1
  53. package/dist/device/motion.js +45 -17
  54. package/dist/device/motion.js.map +1 -1
  55. package/dist/device/plug.d.ts.map +1 -1
  56. package/dist/device/plug.js +40 -18
  57. package/dist/device/plug.js.map +1 -1
  58. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  59. package/dist/device/robotvacuumcleaner.js +42 -17
  60. package/dist/device/robotvacuumcleaner.js.map +1 -1
  61. package/dist/device/waterdetector.d.ts.map +1 -1
  62. package/dist/device/waterdetector.js +41 -16
  63. package/dist/device/waterdetector.js.map +1 -1
  64. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  65. package/dist/irdevice/airconditioner.js +8 -1
  66. package/dist/irdevice/airconditioner.js.map +1 -1
  67. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  68. package/dist/irdevice/airpurifier.js +6 -0
  69. package/dist/irdevice/airpurifier.js.map +1 -1
  70. package/dist/irdevice/camera.d.ts.map +1 -1
  71. package/dist/irdevice/camera.js +3 -0
  72. package/dist/irdevice/camera.js.map +1 -1
  73. package/dist/irdevice/fan.d.ts.map +1 -1
  74. package/dist/irdevice/fan.js +3 -0
  75. package/dist/irdevice/fan.js.map +1 -1
  76. package/dist/irdevice/irdevice.d.ts +9 -0
  77. package/dist/irdevice/irdevice.d.ts.map +1 -1
  78. package/dist/irdevice/irdevice.js +29 -2
  79. package/dist/irdevice/irdevice.js.map +1 -1
  80. package/dist/irdevice/light.d.ts.map +1 -1
  81. package/dist/irdevice/light.js +9 -0
  82. package/dist/irdevice/light.js.map +1 -1
  83. package/dist/irdevice/other.d.ts +1 -0
  84. package/dist/irdevice/other.d.ts.map +1 -1
  85. package/dist/irdevice/other.js +216 -228
  86. package/dist/irdevice/other.js.map +1 -1
  87. package/dist/irdevice/tv.d.ts.map +1 -1
  88. package/dist/irdevice/tv.js +9 -0
  89. package/dist/irdevice/tv.js.map +1 -1
  90. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  91. package/dist/irdevice/vacuumcleaner.js +3 -0
  92. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  93. package/dist/irdevice/waterheater.js +1 -1
  94. package/dist/irdevice/waterheater.js.map +1 -1
  95. package/dist/platform.d.ts.map +1 -1
  96. package/dist/platform.js +11 -2
  97. package/dist/platform.js.map +1 -1
  98. package/dist/types/bledevicestatus.d.ts +1 -0
  99. package/dist/types/bledevicestatus.d.ts.map +1 -1
  100. package/dist/utils.d.ts +8 -0
  101. package/dist/utils.d.ts.map +1 -1
  102. package/dist/utils.js +16 -0
  103. package/dist/utils.js.map +1 -1
  104. package/package.json +6 -6
  105. package/src/device/blindtilt.ts +44 -17
  106. package/src/device/bot.ts +224 -407
  107. package/src/device/ceilinglight.ts +57 -33
  108. package/src/device/colorbulb.ts +55 -31
  109. package/src/device/contact.ts +48 -19
  110. package/src/device/curtain.ts +19 -6
  111. package/src/device/device.ts +36 -3
  112. package/src/device/fan.ts +44 -19
  113. package/src/device/hub.ts +46 -18
  114. package/src/device/humidifier.ts +44 -20
  115. package/src/device/iosensor.ts +46 -18
  116. package/src/device/lightstrip.ts +60 -33
  117. package/src/device/lock.ts +49 -17
  118. package/src/device/meter.ts +46 -18
  119. package/src/device/meterplus.ts +46 -18
  120. package/src/device/motion.ts +46 -18
  121. package/src/device/plug.ts +38 -18
  122. package/src/device/robotvacuumcleaner.ts +41 -17
  123. package/src/device/waterdetector.ts +40 -16
  124. package/src/irdevice/airconditioner.ts +11 -2
  125. package/src/irdevice/airpurifier.ts +8 -0
  126. package/src/irdevice/camera.ts +4 -0
  127. package/src/irdevice/fan.ts +4 -0
  128. package/src/irdevice/irdevice.ts +35 -2
  129. package/src/irdevice/light.ts +12 -0
  130. package/src/irdevice/other.ts +254 -283
  131. package/src/irdevice/tv.ts +12 -0
  132. package/src/irdevice/vacuumcleaner.ts +4 -0
  133. package/src/irdevice/waterheater.ts +1 -1
  134. package/src/platform.ts +11 -2
  135. package/src/types/bledevicestatus.ts +1 -0
  136. package/src/utils.ts +15 -0
package/src/device/bot.ts CHANGED
@@ -31,63 +31,55 @@ export class Bot extends deviceBase {
31
31
  private Switch?: {
32
32
  Name: CharacteristicValue;
33
33
  Service: Service;
34
- On: CharacteristicValue;
35
34
  };
36
35
 
37
36
  private GarageDoor?: {
38
37
  Name: CharacteristicValue;
39
38
  Service: Service;
40
- On: CharacteristicValue;
41
39
  };
42
40
 
43
41
  private Door?: {
44
42
  Name: CharacteristicValue;
45
43
  Service: Service;
46
- On: CharacteristicValue;
47
44
  };
48
45
 
49
46
  private Window?: {
50
47
  Name: CharacteristicValue;
51
48
  Service: Service;
52
- On: CharacteristicValue;
53
49
  };
54
50
 
55
51
  private WindowCovering?: {
56
52
  Name: CharacteristicValue;
57
53
  Service: Service;
58
- On: CharacteristicValue;
59
54
  };
60
55
 
61
56
  private LockMechanism?: {
62
57
  Name: CharacteristicValue;
63
58
  Service: Service;
64
- On: CharacteristicValue;
65
59
  };
66
60
 
67
61
  private Faucet?: {
68
62
  Name: CharacteristicValue;
69
63
  Service: Service;
70
- On: CharacteristicValue;
71
64
  };
72
65
 
73
66
  private Fan?: {
74
67
  Name: CharacteristicValue;
75
68
  Service: Service;
76
- On: CharacteristicValue;
77
69
  };
78
70
 
79
71
  private StatefulProgrammableSwitch?: {
80
72
  Name: CharacteristicValue;
81
73
  Service: Service;
82
- On: CharacteristicValue;
83
74
  };
84
75
 
85
76
  private Outlet?: {
86
77
  Name: CharacteristicValue;
87
78
  Service: Service;
88
- On: CharacteristicValue;
89
79
  };
90
80
 
81
+ On!: boolean;
82
+
91
83
  // OpenAPI
92
84
  deviceStatus!: botStatus;
93
85
 
@@ -123,8 +115,12 @@ export class Bot extends deviceBase {
123
115
  this.doBotUpdate = new Subject();
124
116
  this.botUpdateInProgress = false;
125
117
 
126
- accessory.context.Battery = accessory.context.Battery ?? {};
127
118
  // Initialize Battery property
119
+ accessory.context.Battery = accessory.context.Battery ?? {};
120
+ if (accessory.context.Battery.Name) {
121
+ accessory.context.Battery.Name = this.validateAndCleanString(accessory.context.Battery.Name,
122
+ 'Battery Name', accessory.context.Battery.Name);
123
+ }
128
124
  this.Battery = {
129
125
  Name: accessory.context.Battery.Name ?? `${accessory.displayName} Battery`,
130
126
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
@@ -132,7 +128,6 @@ export class Bot extends deviceBase {
132
128
  StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
133
129
  };
134
130
  accessory.context.Battery = this.Battery as object;
135
-
136
131
  // Initialize Battery Characteristics
137
132
  this.Battery.Service
138
133
  .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
@@ -142,28 +137,24 @@ export class Bot extends deviceBase {
142
137
  // deviceType
143
138
  if (this.botDeviceType === 'switch') {
144
139
  // Set category
145
- accessory.category = this.hap.Categories.SWITCH
146
- ;
140
+ accessory.category = this.hap.Categories.SWITCH;
147
141
  // Initialize Switch Service
148
142
  accessory.context.Switch = accessory.context.Switch ?? {};
143
+ if (accessory.context.Switch.Name) {
144
+ accessory.context.Switch.Name = this.validateAndCleanString(accessory.context.Switch.Name,
145
+ 'Switch Name', accessory.context.Switch.Name);
146
+ }
149
147
  this.Switch = {
150
148
  Name: accessory.context.Switch.Name ?? accessory.displayName,
151
149
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
152
- On: accessory.context.On ?? false,
153
150
  };
154
151
  accessory.context.Switch = this.Switch as object;
155
152
  this.debugLog('Displaying as Switch');
156
-
157
153
  // Initialize Switch Characteristics
158
154
  this.Switch.Service
159
155
  .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
160
- .setCharacteristic(this.hap.Characteristic.On, this.Switch.On)
161
156
  .getCharacteristic(this.hap.Characteristic.On)
162
- .onGet(() => {
163
- return this.Switch!.On;
164
- })
165
157
  .onSet(this.OnSet.bind(this));
166
-
167
158
  // Remove other services
168
159
  this.removeFanService(accessory);
169
160
  this.removeLockService(accessory);
@@ -177,32 +168,30 @@ export class Bot extends deviceBase {
177
168
  } else if (this.botDeviceType === 'garagedoor') {
178
169
  // Set category
179
170
  accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER;
180
-
181
171
  // Initialize GarageDoor Service
182
172
  accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
173
+ if (accessory.context.GarageDoor.Name) {
174
+ accessory.context.GarageDoor.Name = this.validateAndCleanString(accessory.context.GarageDoor.Name,
175
+ 'GarageDoor Name', accessory.context.GarageDoor.Name);
176
+ }
183
177
  this.GarageDoor = {
184
178
  Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
185
179
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
186
- On: accessory.context.On ?? false,
187
180
  };
188
181
  accessory.context.GarageDoor = this.GarageDoor as object;
189
182
  this.debugLog('Displaying as Garage Door Opener');
190
-
191
183
  // Initialize GarageDoor Characteristics
192
184
  this.GarageDoor.Service
193
185
  .setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
194
186
  .setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
195
- .getCharacteristic(this.hap.Characteristic.TargetDoorState).setProps({
187
+ .getCharacteristic(this.hap.Characteristic.TargetDoorState)
188
+ .setProps({
196
189
  validValues: [0, 100],
197
190
  minValue: 0,
198
191
  maxValue: 100,
199
192
  minStep: 100,
200
193
  })
201
- .onGet(() => {
202
- return this.GarageDoor!.On;
203
- })
204
194
  .onSet(this.OnSet.bind(this));
205
-
206
195
  // Remove other services
207
196
  this.removeFanService(accessory);
208
197
  this.removeLockService(accessory);
@@ -216,17 +205,18 @@ export class Bot extends deviceBase {
216
205
  } else if (this.botDeviceType === 'door') {
217
206
  // Set category
218
207
  accessory.category = this.hap.Categories.DOOR;
219
-
220
208
  // Initialize Door Service
221
209
  accessory.context.Door = accessory.context.Door ?? {};
210
+ if (accessory.context.Door.Name) {
211
+ accessory.context.Door.Name = this.validateAndCleanString(accessory.context.Door.Name,
212
+ 'Door Name', accessory.context.Door.Name);
213
+ }
222
214
  this.Door = {
223
215
  Name: accessory.context.Door.Name ?? accessory.displayName,
224
216
  Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
225
- On: accessory.context.On ?? false,
226
217
  };
227
218
  accessory.context.Door = this.Door as object;
228
219
  this.debugLog('Displaying as Door');
229
-
230
220
  // Initialize Door Characteristics
231
221
  this.Door.Service
232
222
  .setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
@@ -237,11 +227,7 @@ export class Bot extends deviceBase {
237
227
  maxValue: 100,
238
228
  minStep: 100,
239
229
  })
240
- .onGet(() => {
241
- return this.Door!.On;
242
- })
243
230
  .onSet(this.OnSet.bind(this));
244
-
245
231
  // Remove other services
246
232
  this.removeFanService(accessory);
247
233
  this.removeLockService(accessory);
@@ -255,17 +241,18 @@ export class Bot extends deviceBase {
255
241
  } else if (this.botDeviceType === 'window') {
256
242
  // Set category
257
243
  accessory.category = this.hap.Categories.WINDOW;
258
-
259
244
  // Initialize Window Service
260
245
  accessory.context.Window = accessory.context.Window ?? {};
246
+ if (accessory.context.Window.Name) {
247
+ accessory.context.Window.Name = this.validateAndCleanString(accessory.context.Window.Name,
248
+ 'Window Name', accessory.context.Window.Name);
249
+ }
261
250
  this.Window = {
262
251
  Name: accessory.context.Window.Name ?? accessory.displayName,
263
252
  Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
264
- On: accessory.context.On ?? false,
265
253
  };
266
254
  accessory.context.Window = this.Window as object;
267
255
  this.debugLog('Displaying as Window');
268
-
269
256
  // Initialize Window Characteristics
270
257
  this.Window.Service
271
258
  .setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
@@ -276,11 +263,7 @@ export class Bot extends deviceBase {
276
263
  maxValue: 100,
277
264
  minStep: 100,
278
265
  })
279
- .onGet(() => {
280
- return this.Window!.On;
281
- })
282
266
  .onSet(this.OnSet.bind(this));
283
-
284
267
  // Remove other services
285
268
  this.removeFanService(accessory);
286
269
  this.removeLockService(accessory);
@@ -294,32 +277,30 @@ export class Bot extends deviceBase {
294
277
  } else if (this.botDeviceType === 'windowcovering') {
295
278
  // Set category
296
279
  accessory.category = this.hap.Categories.WINDOW_COVERING;
297
-
298
280
  // Initialize WindowCovering Service
299
281
  accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
282
+ if (accessory.context.WindowCovering.Name) {
283
+ accessory.context.WindowCovering.Name = this.validateAndCleanString(accessory.context.WindowCovering.Name,
284
+ 'WindowCovering Name', accessory.context.WindowCovering.Name);
285
+ }
300
286
  this.WindowCovering = {
301
287
  Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
302
288
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
303
- On: accessory.context.On ?? false,
304
289
  };
305
290
  accessory.context.WindowCovering = this.WindowCovering as object;
306
291
  this.debugLog('Displaying as Window Covering');
307
-
308
292
  // Initialize WindowCovering Characteristics
309
293
  this.WindowCovering.Service
310
294
  .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
311
295
  .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
312
- .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
296
+ .getCharacteristic(this.hap.Characteristic.TargetPosition)
297
+ .setProps({
313
298
  validValues: [0, 100],
314
299
  minValue: 0,
315
300
  maxValue: 100,
316
301
  minStep: 100,
317
302
  })
318
- .onGet(() => {
319
- return this.WindowCovering!.On;
320
- })
321
303
  .onSet(this.OnSet.bind(this));
322
-
323
304
  // Remove other services
324
305
  this.removeFanService(accessory);
325
306
  this.removeLockService(accessory);
@@ -333,26 +314,24 @@ export class Bot extends deviceBase {
333
314
  } else if (this.botDeviceType === 'lock') {
334
315
  // Set category
335
316
  accessory.category = this.hap.Categories.DOOR_LOCK;
336
-
337
317
  // Initialize Lock Service
338
318
  accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
319
+ if (accessory.context.LockMechanism.Name) {
320
+ accessory.context.LockMechanism.Name = this.validateAndCleanString(accessory.context.LockMechanism.Name,
321
+ 'LockMechanism Name', accessory.context.LockMechanism.Name);
322
+ }
339
323
  this.LockMechanism = {
340
324
  Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
341
325
  Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
342
- On: accessory.context.On ?? false,
343
326
  };
344
327
  accessory.context.LockMechanism = this.LockMechanism as object;
345
328
  this.debugLog('Displaying as Lock');
346
-
347
329
  // Initialize Lock Characteristics
348
330
  this.LockMechanism.Service
349
331
  .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
332
+ .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
350
333
  .getCharacteristic(this.hap.Characteristic.LockTargetState)
351
- .onGet(() => {
352
- return this.LockMechanism!.On;
353
- })
354
334
  .onSet(this.OnSet.bind(this));
355
-
356
335
  // Remove other services
357
336
  this.removeFanService(accessory);
358
337
  this.removeDoorService(accessory);
@@ -366,26 +345,23 @@ export class Bot extends deviceBase {
366
345
  } else if (this.botDeviceType === 'faucet') {
367
346
  // Set category
368
347
  accessory.category = this.hap.Categories.FAUCET;
369
-
370
348
  // Initialize Faucet Service
371
349
  accessory.context.Faucet = accessory.context.Faucet ?? {};
350
+ if (accessory.context.Faucet.Name) {
351
+ accessory.context.Faucet.Name = this.validateAndCleanString(accessory.context.Faucet.Name,
352
+ 'Faucet Name', accessory.context.Faucet.Name);
353
+ }
372
354
  this.Faucet = {
373
355
  Name: accessory.context.Faucet.Name ?? accessory.displayName,
374
356
  Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
375
- On: accessory.context.On ?? false,
376
357
  };
377
358
  accessory.context.Faucet = this.Faucet as object;
378
359
  this.debugLog('Displaying as Faucet');
379
-
380
360
  // Initialize Faucet Characteristics
381
361
  this.Faucet.Service
382
362
  .setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
383
363
  .getCharacteristic(this.hap.Characteristic.Active)
384
- .onGet(() => {
385
- return this.Faucet!.On;
386
- })
387
364
  .onSet(this.OnSet.bind(this));
388
-
389
365
  // Remove other services
390
366
  this.removeFanService(accessory);
391
367
  this.removeLockService(accessory);
@@ -399,26 +375,23 @@ export class Bot extends deviceBase {
399
375
  } else if (this.botDeviceType === 'fan') {
400
376
  // Set category
401
377
  accessory.category = this.hap.Categories.FAN;
402
-
403
378
  // Initialize Fan Service
404
379
  accessory.context.Fan = accessory.context.Fan ?? {};
380
+ if (accessory.context.Fan.Name) {
381
+ accessory.context.Fan.Name = this.validateAndCleanString(accessory.context.Fan.Name,
382
+ 'Fan Name', accessory.context.Fan.Name);
383
+ }
405
384
  this.Fan = {
406
385
  Name: accessory.context.Fan.Name ?? accessory.displayName,
407
386
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
408
- On: accessory.context.On ?? false,
409
387
  };
410
388
  accessory.context.Fan = this.Fan as object;
411
389
  this.debugLog('Displaying as Fan');
412
-
413
390
  // Initialize Fan Characteristics
414
391
  this.Fan.Service
415
392
  .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
416
- .getCharacteristic(this.hap.Characteristic.On)
417
- .onGet(() => {
418
- return this.Fan!.On;
419
- })
393
+ .getCharacteristic(this.hap.Characteristic.Active)
420
394
  .onSet(this.OnSet.bind(this));
421
-
422
395
  // Remove other services
423
396
  this.removeLockService(accessory);
424
397
  this.removeDoorService(accessory);
@@ -432,27 +405,24 @@ export class Bot extends deviceBase {
432
405
  } else if (this.botDeviceType === 'stateful') {
433
406
  // Set category
434
407
  accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH;
435
-
436
408
  // Initialize StatefulProgrammableSwitch Service
437
409
  accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
410
+ if (accessory.context.StatefulProgrammableSwitch.Name) {
411
+ accessory.context.StatefulProgrammableSwitch.Name = this.validateAndCleanString(accessory.context.StatefulProgrammableSwitch.Name,
412
+ 'StatefulProgrammableSwitch Name', accessory.context.StatefulProgrammableSwitch.Name);
413
+ }
438
414
  this.StatefulProgrammableSwitch = {
439
415
  Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
440
416
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
441
417
  ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
442
- On: accessory.context.On ?? false,
443
418
  };
444
419
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
445
420
  this.debugLog('Displaying as Stateful Programmable Switch');
446
-
447
421
  // Initialize StatefulProgrammableSwitch Characteristics
448
422
  this.StatefulProgrammableSwitch.Service
449
423
  .setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
450
424
  .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
451
- .onGet(() => {
452
- return this.StatefulProgrammableSwitch!.On;
453
- })
454
425
  .onSet(this.OnSet.bind(this));
455
-
456
426
  // Remove other services
457
427
  this.removeFanService(accessory);
458
428
  this.removeLockService(accessory);
@@ -463,29 +433,26 @@ export class Bot extends deviceBase {
463
433
  this.removeWindowService(accessory);
464
434
  this.removeGarageDoorService(accessory);
465
435
  this.removeWindowCoveringService(accessory);
466
- } else {
436
+ } else if (this.botDeviceType === 'outlet') {
467
437
  // Set category
468
438
  accessory.category = this.hap.Categories.OUTLET;
469
-
470
439
  // Initialize Switch property
471
440
  accessory.context.Outlet = accessory.context.Outlet ?? {};
441
+ if (accessory.context.Outlet.Name) {
442
+ accessory.context.Outlet.Name = this.validateAndCleanString(accessory.context.Outlet.Name,
443
+ 'Outlet Name', accessory.context.Outlet.Name);
444
+ }
472
445
  this.Outlet = {
473
446
  Name: accessory.context.Outlet.Name ?? accessory.displayName,
474
447
  Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
475
- On: accessory.context.On ?? false,
476
448
  };
477
449
  accessory.context.Outlet = this.Outlet as object;
478
450
  this.debugLog('Displaying as Outlet');
479
-
480
451
  // Initialize Outlet Characteristics
481
452
  this.Outlet.Service
482
453
  .setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
483
454
  .getCharacteristic(this.hap.Characteristic.On)
484
- .onGet(() => {
485
- return this.Outlet!.On;
486
- })
487
455
  .onSet(this.OnSet.bind(this));
488
-
489
456
  // Remove other services
490
457
  this.removeFanService(accessory);
491
458
  this.removeLockService(accessory);
@@ -496,6 +463,8 @@ export class Bot extends deviceBase {
496
463
  this.removeGarageDoorService(accessory);
497
464
  this.removeWindowCoveringService(accessory);
498
465
  this.removeStatefulProgrammableSwitchService(accessory);
466
+ } else {
467
+ this.errorLog('Device Type not set');
499
468
  }
500
469
 
501
470
  // Retrieve initial values and updateHomekit
@@ -550,18 +519,10 @@ export class Bot extends deviceBase {
550
519
  + ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
551
520
 
552
521
  // BLEmode (true if Switch Mode) | (false if Press Mode)
553
- if (this.serviceData.mode) {
554
- await this.setOn(this.serviceData.state);
555
- this.accessory.context.On = await this.getOn();
556
- if (this.getOn() === undefined) {
557
- this.setOn(Boolean(this.serviceData.state));
558
- }
559
- this.debugLog(`Switch Mode, mode: ${this.serviceData.mode}, On: ${this.accessory.context.On}`);
560
- } else {
561
- this.setOn(false);
562
- this.accessory.context.On = await this.getOn();
563
- this.debugLog(`Press Mode, mode: ${this.serviceData.mode}, On: ${this.accessory.context.On}`);
564
- }
522
+ this.On = this.serviceData.mode ? this.serviceData.state : false;
523
+ const mode = this.serviceData.mode ? 'Switch' : 'Press';
524
+ await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`);
525
+ this.accessory.context.On = this.On;
565
526
 
566
527
  // BatteryLevel
567
528
  this.Battery.BatteryLevel = this.serviceData.battery;
@@ -583,16 +544,8 @@ export class Bot extends deviceBase {
583
544
  + ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
584
545
 
585
546
  // On
586
- if (this.botMode === 'press') {
587
- this.setOn(false);
588
- this.accessory.context.On = await this.getOn();
589
- } else {
590
- this.setOn(this.deviceStatus.power === 'on' ? true : false);
591
- this.accessory.context.On = await this.getOn();
592
- if (this.getOn() === undefined) {
593
- this.setOn(false);
594
- }
595
- }
547
+ this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on' ? true : false;
548
+ this.accessory.context.On = this.On;
596
549
  await this.debugLog(`On: ${this.accessory.context.On}`);
597
550
 
598
551
  // Battery Level
@@ -622,14 +575,12 @@ export class Bot extends deviceBase {
622
575
 
623
576
  async parseStatusWebhook(): Promise<void> {
624
577
  await this.debugLog('parseStatusWebhook');
625
- const getOn = await this.getOn();
626
578
  await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery},`
627
- + ` ${this.webhookContext.deviceMode}), current:(${getOn}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
579
+ + ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
628
580
 
629
581
  // On
630
- const setOn = this.webhookContext.power === 'on' ? true : false;
631
- await this.setOn(setOn);
632
- await this.debugLog(`On: ${setOn}`);
582
+ this.On = this.webhookContext.power === 'on' ? true : false;
583
+ await this.debugLog(`On: ${this.On}`);
633
584
 
634
585
  // BatteryLevel
635
586
  this.Battery.BatteryLevel = this.webhookContext.battery;
@@ -651,7 +602,7 @@ export class Bot extends deviceBase {
651
602
  async refreshStatus(): Promise<void> {
652
603
  if (!this.device.enableCloudService && this.OpenAPI) {
653
604
  await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
654
- } else if (this.BLE) {
605
+ } else if (this.BLE || this.config.options?.BLE) {
655
606
  await this.BLERefreshStatus();
656
607
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
657
608
  await this.openAPIRefreshStatus();
@@ -663,25 +614,41 @@ export class Bot extends deviceBase {
663
614
 
664
615
  async BLERefreshStatus(): Promise<void> {
665
616
  await this.debugLog('BLERefreshStatus');
666
- const switchbot = await this.switchbotBLE();
667
-
668
- if (switchbot === undefined) {
669
- await this.BLERefreshConnection(switchbot);
670
- } else {
671
- // Start to monitor advertisement packets
672
- (async () => {
673
- // Start to monitor advertisement packets
674
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
675
- // Update HomeKit
676
- if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
677
- this.serviceData = serviceData;
617
+ if (this.config.options?.BLE) {
618
+ await this.debugLog('is listening to Platform BLE.');
619
+ this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
620
+ await this.debugLog(`bleMac: ${this.device.bleMac}`);
621
+ this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
622
+ try {
623
+ await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
624
+ this.serviceData = context;
678
625
  await this.BLEparseStatus();
679
626
  await this.updateHomeKitCharacteristics();
680
- } else {
681
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
682
- await this.BLERefreshConnection(switchbot);
627
+ } catch (e: any) {
628
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
683
629
  }
684
- })();
630
+ };
631
+ } else {
632
+ await this.debugLog('is using Device BLE Scanning.');
633
+ const switchbot = await this.switchbotBLE();
634
+ if (switchbot === undefined) {
635
+ await this.BLERefreshConnection(switchbot);
636
+ } else {
637
+ // Start to monitor advertisement packets
638
+ (async () => {
639
+ // Start to monitor advertisement packets
640
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
641
+ // Update HomeKit
642
+ if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
643
+ this.serviceData = serviceData;
644
+ await this.BLEparseStatus();
645
+ await this.updateHomeKitCharacteristics();
646
+ } else {
647
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
648
+ await this.BLERefreshConnection(switchbot);
649
+ }
650
+ })();
651
+ }
685
652
  }
686
653
  }
687
654
 
@@ -753,30 +720,26 @@ export class Bot extends deviceBase {
753
720
 
754
721
  async BLEpushChanges(): Promise<void> {
755
722
  await this.debugLog('BLEpushChanges');
756
- const On = await this.getOn();
757
- if (On !== this.accessory.context.On || this.allowPush) {
758
- this.debugLog(`BLEpushChanges On: ${On} OnCached: ${this.accessory.context.On}`);
723
+ if (this.On !== this.accessory.context.On || this.allowPush) {
724
+ await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
759
725
  const switchbot = await this.platform.connectBLE(this.accessory, this.device);
760
726
  await this.convertBLEAddress();
761
727
  //if (switchbot !== false) {
728
+ await this.debugLog(`Bot Mode: ${this.botMode}`);
762
729
  if (this.botMode === 'press') {
763
- this.debugLog(`Bot Mode: ${this.botMode}`);
764
730
  switchbot
765
731
  .discover({ model: 'H', quick: true, id: this.device.bleMac })
766
732
  .then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
767
- this.infoLog(`On: ${On}`);
733
+ await this.infoLog(`On: ${this.On}`);
768
734
  return await device_list[0].press({ id: this.device.bleMac });
769
735
  })
770
736
  .then(async () => {
771
- await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
737
+ await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
772
738
  await this.updateHomeKitCharacteristics();
773
- setTimeout(() => {
774
- if (this.botDeviceType === 'switch') {
775
- this.Switch?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
776
- } else {
777
- this.Outlet?.Service.getCharacteristic(this.hap.Characteristic.On).updateValue(On);
778
- }
779
- this.debugLog(`On: ${On}, Switch Timeout`);
739
+ setTimeout(async () => {
740
+ this.On = false;
741
+ await this.updateHomeKitCharacteristics();
742
+ this.debugLog(`On: ${this.On}, Switch Timeout`);
780
743
  }, 500);
781
744
  })
782
745
  .catch(async (e: any) => {
@@ -785,15 +748,14 @@ export class Bot extends deviceBase {
785
748
  await this.BLEPushConnection();
786
749
  });
787
750
  } else if (this.botMode === 'switch') {
788
- this.debugLog(`Press Mode: ${this.botMode}`);
789
751
  switchbot
790
752
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
791
753
  .then(async (device_list: any) => {
792
- this.infoLog(`On: ${On}`);
754
+ this.infoLog(`On: ${this.On}`);
793
755
  return await this.retryBLE({
794
756
  max: await this.maxRetryBLE(),
795
757
  fn: async () => {
796
- if (On) {
758
+ if (this.On) {
797
759
  return await device_list[0].turnOn({ id: this.device.bleMac });
798
760
  } else {
799
761
  return await device_list[0].turnOff({ id: this.device.bleMac });
@@ -802,7 +764,7 @@ export class Bot extends deviceBase {
802
764
  });
803
765
  })
804
766
  .then(async () => {
805
- await this.successLog(`On: ${On} sent over SwitchBot BLE, sent successfully`);
767
+ await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
806
768
  await this.updateHomeKitCharacteristics();
807
769
  })
808
770
  .catch(async (e: any) => {
@@ -814,31 +776,24 @@ export class Bot extends deviceBase {
814
776
  await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
815
777
  }
816
778
  } else {
817
- await this.debugLog(`No Changes (BLEpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
779
+ await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
818
780
  }
819
781
  }
820
782
 
821
783
  async openAPIpushChanges(): Promise<void> {
822
784
  await this.debugLog('openAPIpushChanges');
823
- let On = await this.getOn();
824
785
  if (this.multiPressCount > 0) {
825
786
  await this.debugLog(`${this.multiPressCount} request(s) queued.`);
826
- On = true;
827
787
  }
828
- if (On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
788
+ if (this.On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
829
789
  let command = '';
830
- if (this.botMode === 'switch' && On) {
831
- command = 'turnOn';
832
- On = true;
833
- await this.debugLog(`Switch Mode, Turning ${On}`);
834
- } else if (this.botMode === 'switch' && !On) {
835
- command = 'turnOff';
836
- On = false;
837
- await this.debugLog(`Switch Mode, Turning ${On}`);
790
+ if (this.botMode === 'switch') {
791
+ command = this.On ? 'turnOn' : 'turnOff';
792
+ await this.debugLog(`Switch Mode, Command: ${command}`);
838
793
  } else if (this.botMode === 'press' || this.botMode === 'multipress') {
839
794
  command = 'press';
840
795
  await this.debugLog('Press Mode');
841
- On = false;
796
+ this.On = false;
842
797
  } else {
843
798
  throw new Error('Device Parameters not set for this Bot.');
844
799
  }
@@ -863,7 +818,7 @@ export class Bot extends deviceBase {
863
818
  this.multiPressCount--;
864
819
  if (this.multiPressCount > 0) {
865
820
  await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
866
- On = true;
821
+ this.On = true;
867
822
  await this.openAPIpushChanges();
868
823
  }
869
824
  }
@@ -872,7 +827,7 @@ export class Bot extends deviceBase {
872
827
  await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
873
828
  }
874
829
  } else {
875
- await this.debugLog(`No Changes (openAPIpushChanges), On: ${On} OnCached: ${this.accessory.context.On}`);
830
+ await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
876
831
  }
877
832
  }
878
833
 
@@ -880,104 +835,54 @@ export class Bot extends deviceBase {
880
835
  * Handle requests to set the "On" characteristic
881
836
  */
882
837
  async OnSet(value: CharacteristicValue): Promise<void> {
883
- if (this.botDeviceType === 'garagedoor') {
838
+ if (this.botDeviceType === 'switch') {
839
+ if (this.Switch) {
840
+ await this.debugLog(`Set On: ${value}`);
841
+ this.On = value === false ? false : true;
842
+ }
843
+ } else if (this.botDeviceType === 'garagedoor') {
884
844
  if (this.GarageDoor) {
885
845
  await this.debugLog(`Set TargetDoorState: ${value}`);
886
- this.infoLog(`Set TargetDoorState: ${value}`);
887
- if (value === this.hap.Characteristic.TargetDoorState.CLOSED) {
888
- await this.setOn(false);
889
- this.GarageDoor.On = false;
890
- } else {
891
- await this.setOn(true);
892
- this.GarageDoor.On = true;
893
- }
846
+ this.On = value === this.hap.Characteristic.TargetDoorState.CLOSED ? false : true;
894
847
  }
895
848
  } else if (this.botDeviceType === 'door') {
896
849
  if (this.Door) {
897
850
  await this.debugLog(`Set TargetPosition: ${value}`);
898
- if (value === 0) {
899
- await this.setOn(false);
900
- this.Door.On = false;
901
- } else {
902
- await this.setOn(true);
903
- this.Door.On = true;
904
- }
851
+ this.On = value === 0 ? false : true;
905
852
  }
906
853
  } else if (this.botDeviceType === 'window') {
907
854
  if (this.Window) {
908
855
  await this.debugLog(`Set TargetPosition: ${value}`);
909
- if (value === 0) {
910
- await this.setOn(false);
911
- this.Window.On = false;
912
- } else {
913
- await this.setOn(true);
914
- this.Window.On = true;
915
- }
856
+ this.On = value === 0 ? false : true;
916
857
  }
917
858
  } else if (this.botDeviceType === 'windowcovering') {
918
859
  if (this.WindowCovering) {
919
860
  await this.debugLog(`Set TargetPosition: ${value}`);
920
- if (value === 0) {
921
- await this.setOn(false);
922
- this.WindowCovering.On = false;
923
- } else {
924
- await this.setOn(true);
925
- this.WindowCovering.On = true;
926
- }
861
+ this.On = value === 0 ? false : true;
927
862
  }
928
863
  } else if (this.botDeviceType === 'lock') {
929
864
  if (this.LockMechanism) {
930
865
  await this.debugLog(`Set LockTargetState: ${value}`);
931
- if (value === this.hap.Characteristic.LockTargetState.SECURED) {
932
- await this.setOn(false);
933
- this.LockMechanism.On = false;
934
- } else {
935
- await this.setOn(true);
936
- this.LockMechanism.On = true;
937
- }
866
+ this.On = value === this.hap.Characteristic.LockTargetState.SECURED ? false : true;
938
867
  }
939
868
  } else if (this.botDeviceType === 'faucet') {
940
869
  if (this.Faucet) {
941
870
  await this.debugLog(`Set Active: ${value}`);
942
- if (value === this.hap.Characteristic.Active.INACTIVE) {
943
- await this.setOn(false);
944
- this.Faucet.On = false;
945
- } else {
946
- await this.setOn(true);
947
- this.Faucet.On = true;
948
- }
871
+ this.On = value === this.hap.Characteristic.Active.INACTIVE ? false : true;
949
872
  }
950
873
  } else if (this.botDeviceType === 'stateful') {
951
874
  if (this.StatefulProgrammableSwitch) {
952
875
  await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
953
- if (value === 0) {
954
- await this.setOn(false);
955
- this.StatefulProgrammableSwitch.On = false;
956
- } else {
957
- await this.setOn(true);
958
- this.StatefulProgrammableSwitch.On = true;
959
- }
960
- }
961
- } else if (this.botDeviceType === 'switch') {
962
- if (this.Switch) {
963
- await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
964
- if (value === 0) {
965
- await this.setOn(false);
966
- this.Switch.On = false;
967
- } else {
968
- await this.setOn(true);
969
- this.Switch.On = true;
970
- }
876
+ this.On = value === 0 ? false : true;
971
877
  }
972
878
  } else {
973
879
  if (this.Outlet) {
974
880
  await this.debugLog(`Set On: ${value}`);
975
- await this.setOn(Boolean(value));
976
- this.Outlet.On = value;
881
+ this.On = value === false ? false : true;
977
882
  }
978
883
  }
979
884
  if (this.device.bot?.mode === 'multipress') {
980
- if (value === true) {
885
+ if (this.On === true) {
981
886
  this.multiPressCount++;
982
887
  await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
983
888
  }
@@ -989,176 +894,168 @@ export class Bot extends deviceBase {
989
894
  * Updates the status for each of the HomeKit Characteristics
990
895
  */
991
896
  async updateHomeKitCharacteristics(): Promise<void> {
897
+ await this.debugLog('updateHomeKitCharacteristics');
898
+ // BatteryLevel
899
+ if (this.Battery.BatteryLevel === undefined) {
900
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
901
+ } else {
902
+ this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
903
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
904
+ await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
905
+ }
906
+ // StatusLowBattery
907
+ if (this.Battery.StatusLowBattery === undefined) {
908
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
909
+ } else {
910
+ this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
911
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
912
+ await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
913
+ }
992
914
  // State
993
- if (this.botDeviceType === 'garagedoor') {
994
- if (this.GarageDoor?.On === undefined) {
995
- await this.debugLog(`On: ${this.GarageDoor?.On}`);
915
+ if (this.botDeviceType === 'switch' && this.Switch) {
916
+ if (this.On === undefined) {
917
+ await this.debugLog(`On: ${this.On}`);
996
918
  } else {
997
- if (this.GarageDoor.On) {
919
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
920
+ await this.debugLog(`updateCharacteristic On: ${this.On}`);
921
+ }
922
+ } else if (this.botDeviceType === 'garagedoor' && this.GarageDoor) {
923
+ if (this.On === undefined) {
924
+ await this.debugLog(`On: ${this.On}`);
925
+ } else {
926
+ if (this.On) {
998
927
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
999
928
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
1000
- await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
929
+ await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`);
1001
930
  } else {
1002
931
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
1003
932
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
1004
- await this.debugLog(`updateCharacteristicc TargetDoorState: Open, CurrentDoorState: Open (${this.GarageDoor.On})`);
933
+ await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`);
1005
934
  }
1006
935
  }
1007
- await this.setOn(Boolean(this.GarageDoor?.On));
1008
- await this.debugLog(`Garage Door On: ${this.GarageDoor?.On}`);
1009
- } else if (this.botDeviceType === 'door') {
1010
- if (this.Door?.On === undefined) {
1011
- await this.debugLog(`On: ${this.Door?.On}`);
936
+ await this.debugLog(`Garage Door On: ${this.On}`);
937
+ } else if (this.botDeviceType === 'door' && this.Door) {
938
+ if (this.On === undefined) {
939
+ await this.debugLog(`On: ${this.On}`);
1012
940
  } else {
1013
- if (this.Door.On) {
941
+ if (this.On) {
1014
942
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
1015
943
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
1016
944
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1017
- await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Door.On})`);
945
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
1018
946
  } else {
1019
947
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1020
948
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1021
949
  this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1022
- await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Door.On})`);
950
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
1023
951
  }
1024
952
  }
1025
- await this.setOn(Boolean(this.Door?.On));
1026
- await this.debugLog(`Door On: ${this.Door?.On}`);
1027
- } else if (this.botDeviceType === 'window') {
1028
- if (this.Window?.On === undefined) {
1029
- await this.debugLog(`On: ${this.Window?.On}`);
953
+ await this.debugLog(`Door On: ${this.On}`);
954
+ } else if (this.botDeviceType === 'window' && this.Window) {
955
+ if (this.On === undefined) {
956
+ await this.debugLog(`On: ${this.On}`);
1030
957
  } else {
1031
- if (this.Window.On) {
958
+ if (this.On) {
1032
959
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
1033
960
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
1034
961
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1035
- await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.Window.On})`);
962
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
1036
963
  } else {
1037
964
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1038
965
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1039
966
  this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1040
- await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.Window.On})`);
967
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
1041
968
  }
1042
969
  }
1043
- await this.setOn(Boolean(this.Window?.On));
1044
- await this.debugLog(`Window On: ${this.Window?.On}`);
1045
- } else if (this.botDeviceType === 'windowcovering') {
1046
- if (this.WindowCovering?.On === undefined) {
1047
- await this.debugLog(`On: ${this.WindowCovering?.On}`);
970
+ await this.debugLog(`Window On: ${this.On}`);
971
+ } else if (this.botDeviceType === 'windowcovering' && this.WindowCovering) {
972
+ if (this.On === undefined) {
973
+ await this.debugLog(`On: ${this.On}`);
1048
974
  } else {
1049
- if (this.WindowCovering.On) {
975
+ if (this.On) {
1050
976
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
1051
977
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
1052
978
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1053
- await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.WindowCovering.On})`);
979
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
1054
980
  } else {
1055
981
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1056
982
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1057
983
  this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1058
- await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.WindowCovering.On})`);
984
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
1059
985
  }
1060
986
  }
1061
- await this.setOn(Boolean(this.WindowCovering?.On));
1062
- await this.debugLog(`Window Covering On: ${this.WindowCovering?.On}`);
1063
- } else if (this.botDeviceType === 'lock') {
1064
- if (this.LockMechanism?.On === undefined) {
1065
- await this.debugLog(`On: ${this.LockMechanism?.On}`);
987
+ await this.debugLog(`Window Covering On: ${this.On}`);
988
+ } else if (this.botDeviceType === 'lock' && this.LockMechanism) {
989
+ if (this.On === undefined) {
990
+ await this.debugLog(`On: ${this.On}`);
1066
991
  } else {
1067
- if (this.LockMechanism.On) {
992
+ if (this.On) {
1068
993
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
1069
994
  this.hap.Characteristic.LockTargetState.UNSECURED);
1070
995
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
1071
996
  this.hap.Characteristic.LockCurrentState.UNSECURED);
1072
- await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.LockMechanism.On})`);
997
+ await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`);
1073
998
  } else {
1074
999
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
1075
1000
  this.hap.Characteristic.LockTargetState.SECURED);
1076
1001
  this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
1077
1002
  this.hap.Characteristic.LockCurrentState.SECURED);
1078
- await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.LockMechanism.On})`);
1003
+ await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`);
1079
1004
  }
1080
1005
  }
1081
- await this.setOn(Boolean(this.LockMechanism?.On));
1082
- await this.debugLog(`Lock On: ${this.LockMechanism?.On}`);
1083
- } else if (this.botDeviceType === 'faucet') {
1084
- if (this.Faucet?.On === undefined) {
1085
- await this.debugLog(`On: ${this.Faucet?.On}`);
1006
+ await this.debugLog(`Lock On: ${this.On}`);
1007
+ } else if (this.botDeviceType === 'faucet' && this.Faucet) {
1008
+ if (this.On === undefined) {
1009
+ await this.debugLog(`On: ${this.On}`);
1086
1010
  } else {
1087
- if (this.Faucet.On) {
1011
+ if (this.On) {
1088
1012
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
1089
- await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1013
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
1090
1014
  } else {
1091
1015
  this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
1092
- await this.debugLog(`updateCharacteristic Active: ${this.Faucet.On}`);
1016
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
1093
1017
  }
1094
1018
  }
1095
- await this.setOn(Boolean(this.Faucet?.On));
1096
- await this.debugLog(`Faucet On: ${this.Faucet?.On}`);
1097
- } else if (this.botDeviceType === 'fan') {
1098
- if (this.Fan?.On === undefined) {
1099
- await this.debugLog(`On: ${this.Fan?.On}`);
1019
+ await this.debugLog(`Faucet On: ${this.On}`);
1020
+ } else if (this.botDeviceType === 'fan' && this.Fan) {
1021
+ if (this.On === undefined) {
1022
+ await this.debugLog(`On: ${this.On}`);
1100
1023
  } else {
1101
- if (this.Fan.On) {
1102
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1103
- await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1024
+ if (this.On) {
1025
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
1026
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
1104
1027
  } else {
1105
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, this.Fan.On);
1106
- await this.debugLog(`updateCharacteristic On: ${this.Fan.On}`);
1028
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
1029
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`);
1107
1030
  }
1108
1031
  }
1109
- await this.setOn(Boolean(this.Fan?.On));
1110
- await this.debugLog(`Fan On: ${this.Fan?.On}`);
1111
- } else if (this.botDeviceType === 'stateful') {
1112
- if (this.StatefulProgrammableSwitch?.On === undefined) {
1113
- await this.debugLog(`On: ${this.StatefulProgrammableSwitch?.On}`);
1032
+ await this.debugLog(`Fan On: ${this.On}`);
1033
+ } else if (this.botDeviceType === 'stateful' && this.StatefulProgrammableSwitch) {
1034
+ if (this.On === undefined) {
1035
+ await this.debugLog(`On: ${this.On}`);
1114
1036
  } else {
1115
- if (this.StatefulProgrammableSwitch.On) {
1037
+ if (this.On) {
1116
1038
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1117
1039
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1118
1040
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
1119
- await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1041
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
1120
1042
  } else {
1121
1043
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1122
1044
  this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1123
1045
  this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
1124
- await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.StatefulProgrammableSwitch.On})`);
1046
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
1125
1047
  }
1126
1048
  }
1127
- await this.setOn(Boolean(this.StatefulProgrammableSwitch?.On));
1128
- await this.debugLog(`StatefulProgrammableSwitch On: ${this.StatefulProgrammableSwitch?.On}`);
1129
- } else if (this.botDeviceType === 'switch') {
1130
- if (this.Switch?.On === undefined) {
1131
- await this.debugLog(`On: ${this.Switch?.On}`);
1049
+ await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`);
1050
+ } else if (this.botDeviceType === 'outlet' && this.Outlet) {
1051
+ if (this.On === undefined) {
1052
+ await this.debugLog(`On: ${this.On}`);
1132
1053
  } else {
1133
- this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.Switch.On);
1134
- await this.debugLog(`updateCharacteristic On: ${this.Switch.On}`);
1054
+ this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
1055
+ await this.debugLog(`updateCharacteristic On: ${this.On}`);
1135
1056
  }
1136
- await this.setOn(Boolean(this.Switch?.On));
1137
1057
  } else {
1138
- if (this.Outlet?.On === undefined) {
1139
- await this.debugLog(`On: ${this.Outlet?.On}`);
1140
- } else {
1141
- this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.Outlet.On);
1142
- await this.debugLog(`updateCharacteristic On: ${this.Outlet.On}`);
1143
- }
1144
- await this.setOn(Boolean(this.Outlet?.On));
1145
- }
1146
- this.accessory.context.On = await this.getOn();
1147
- // BatteryLevel
1148
- if (this.Battery.BatteryLevel === undefined) {
1149
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
1150
- } else {
1151
- this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
1152
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
1153
- await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
1154
- }
1155
- // StatusLowBattery
1156
- if (this.Battery.StatusLowBattery === undefined) {
1157
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1158
- } else {
1159
- this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
1160
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
1161
- await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
1058
+ await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`);
1162
1059
  }
1163
1060
  }
1164
1061
 
@@ -1168,7 +1065,6 @@ export class Bot extends deviceBase {
1168
1065
  this.Outlet = {
1169
1066
  Name: accessory.context.Outlet.Name ?? accessory.displayName,
1170
1067
  Service: accessory.getService(this.hap.Service.Outlet) as Service,
1171
- On: accessory.context.On ?? false,
1172
1068
  };
1173
1069
  accessory.context.Outlet = this.Outlet as object;
1174
1070
  await this.warnLog('Removing any leftover Outlet Service');
@@ -1181,7 +1077,6 @@ export class Bot extends deviceBase {
1181
1077
  this.GarageDoor = {
1182
1078
  Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
1183
1079
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
1184
- On: accessory.context.On ?? false,
1185
1080
  };
1186
1081
  accessory.context.GarageDoor = this.GarageDoor as object;
1187
1082
  await this.warnLog('Removing any leftover Garage Door Service');
@@ -1194,7 +1089,6 @@ export class Bot extends deviceBase {
1194
1089
  this.Door = {
1195
1090
  Name: accessory.context.Door.Name ?? accessory.displayName,
1196
1091
  Service: accessory.getService(this.hap.Service.Door) as Service,
1197
- On: accessory.context.On ?? false,
1198
1092
  };
1199
1093
  accessory.context.Door = this.Door as object;
1200
1094
  await this.warnLog('Removing any leftover Door Service');
@@ -1207,7 +1101,6 @@ export class Bot extends deviceBase {
1207
1101
  this.LockMechanism = {
1208
1102
  Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
1209
1103
  Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
1210
- On: accessory.context.On ?? false,
1211
1104
  };
1212
1105
  accessory.context.LockMechanism = this.LockMechanism as object;
1213
1106
  this.warnLog('Removing any leftover Lock Service');
@@ -1220,7 +1113,6 @@ export class Bot extends deviceBase {
1220
1113
  this.Faucet = {
1221
1114
  Name: accessory.context.Faucet.Name ?? accessory.displayName,
1222
1115
  Service: accessory.getService(this.hap.Service.Valve) as Service,
1223
- On: accessory.context.On ?? false,
1224
1116
  };
1225
1117
  accessory.context.Faucet = this.Faucet as object;
1226
1118
  await this.warnLog('Removing any leftover Faucet Service');
@@ -1233,7 +1125,6 @@ export class Bot extends deviceBase {
1233
1125
  this.Fan = {
1234
1126
  Name: accessory.context.Fan.Name ?? accessory.displayName,
1235
1127
  Service: accessory.getService(this.hap.Service.Fan) as Service,
1236
- On: accessory.context.On ?? false,
1237
1128
  };
1238
1129
  accessory.context.Fan = this.Fan as object;
1239
1130
  this.warnLog('Removing any leftover Fan Service');
@@ -1246,7 +1137,6 @@ export class Bot extends deviceBase {
1246
1137
  this.Window = {
1247
1138
  Name: accessory.context.Window.Name ?? accessory.displayName,
1248
1139
  Service: accessory.getService(this.hap.Service.Window) as Service,
1249
- On: accessory.context.On ?? false,
1250
1140
  };
1251
1141
  accessory.context.Window = this.Window as object;
1252
1142
  await this.warnLog('Removing any leftover Window Service');
@@ -1259,7 +1149,6 @@ export class Bot extends deviceBase {
1259
1149
  this.WindowCovering = {
1260
1150
  Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
1261
1151
  Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
1262
- On: accessory.context.On ?? false,
1263
1152
  };
1264
1153
  accessory.context.WindowCovering = this.WindowCovering as object;
1265
1154
  await this.warnLog('Removing any leftover Window Covering Service');
@@ -1272,7 +1161,6 @@ export class Bot extends deviceBase {
1272
1161
  this.StatefulProgrammableSwitch = {
1273
1162
  Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
1274
1163
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
1275
- On: accessory.context.On ?? false,
1276
1164
  };
1277
1165
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
1278
1166
  await this.warnLog('Removing any leftover Stateful Programmable Switch Service');
@@ -1285,83 +1173,12 @@ export class Bot extends deviceBase {
1285
1173
  this.Switch = {
1286
1174
  Name: accessory.context.Switch.Name ?? accessory.displayName,
1287
1175
  Service: accessory.getService(this.hap.Service.Switch) as Service,
1288
- On: accessory.context.On ?? false,
1289
1176
  };
1290
1177
  accessory.context.Switch = this.Switch as object;
1291
1178
  await this.warnLog('Removing any leftover Switch Service');
1292
1179
  accessory.removeService(this.Switch.Service);
1293
1180
  }
1294
1181
 
1295
- async getOn(): Promise<boolean> {
1296
- let On: boolean;
1297
- if (this.botDeviceType === 'garagedoor') {
1298
- On = this.GarageDoor?.On ? true : false;
1299
- } else if (this.botDeviceType === 'door') {
1300
- On = this.Door?.On ? true : false;
1301
- } else if (this.botDeviceType === 'window') {
1302
- On = this.Window?.On ? true : false;
1303
- } else if (this.botDeviceType === 'windowcovering') {
1304
- On = this.WindowCovering?.On ? true : false;
1305
- } else if (this.botDeviceType === 'lock') {
1306
- On = this.LockMechanism?.On ? true : false;
1307
- } else if (this.botDeviceType === 'faucet') {
1308
- On = this.Faucet?.On ? true : false;
1309
- } else if (this.botDeviceType === 'fan') {
1310
- On = this.Fan?.On ? true : false;
1311
- } else if (this.botDeviceType === 'stateful') {
1312
- On = this.StatefulProgrammableSwitch?.On ? true : false;
1313
- } else if (this.botDeviceType === 'switch') {
1314
- On = this.Switch?.On ? true : false;
1315
- } else {
1316
- On = this.Outlet?.On ? true : false;
1317
- }
1318
- return On;
1319
- }
1320
-
1321
- async setOn(On: boolean): Promise<void> {
1322
- if (this.botDeviceType === 'garagedoor') {
1323
- if (this.GarageDoor) {
1324
- this.GarageDoor.On = On;
1325
- }
1326
- } else if (this.botDeviceType === 'door') {
1327
- if (this.Door) {
1328
- this.Door.On = On;
1329
- }
1330
- } else if (this.botDeviceType === 'window') {
1331
- if (this.Window) {
1332
- this.Window.On = On;
1333
- }
1334
- } else if (this.botDeviceType === 'windowcovering') {
1335
- if (this.WindowCovering) {
1336
- this.WindowCovering.On = On;
1337
- }
1338
- } else if (this.botDeviceType === 'lock') {
1339
- if (this.LockMechanism) {
1340
- this.LockMechanism.On = On;
1341
- }
1342
- } else if (this.botDeviceType === 'faucet') {
1343
- if (this.Faucet) {
1344
- this.Faucet.On = On;
1345
- }
1346
- } else if (this.botDeviceType === 'fan') {
1347
- if (this.Fan) {
1348
- this.Fan.On = On;
1349
- }
1350
- } else if (this.botDeviceType === 'stateful') {
1351
- if (this.StatefulProgrammableSwitch) {
1352
- this.StatefulProgrammableSwitch.On = On;
1353
- }
1354
- } else if (this.botDeviceType === 'switch') {
1355
- if (this.Switch) {
1356
- this.Switch.On = On;
1357
- }
1358
- } else {
1359
- if (this.Outlet) {
1360
- this.Outlet.On = On;
1361
- }
1362
- }
1363
- }
1364
-
1365
1182
  async getBotConfigSettings(device: device & devicesConfig) {
1366
1183
  //Bot Device Type
1367
1184
  this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType ? this.accessory.context.botDeviceType
@@ -1476,6 +1293,8 @@ export class Bot extends deviceBase {
1476
1293
  }
1477
1294
 
1478
1295
  async apiError(e: any): Promise<void> {
1296
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
1297
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
1479
1298
  if (this.botDeviceType === 'garagedoor') {
1480
1299
  if (this.GarageDoor) {
1481
1300
  this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
@@ -1527,7 +1346,5 @@ export class Bot extends deviceBase {
1527
1346
  this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e);
1528
1347
  }
1529
1348
  }
1530
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
1531
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
1532
1349
  }
1533
1350
  }