@switchbot/homebridge-switchbot 3.7.1-beta.11 → 3.7.1-beta.13

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 (190) hide show
  1. package/dist/device/blindtilt.d.ts +8 -8
  2. package/dist/device/blindtilt.d.ts.map +1 -1
  3. package/dist/device/blindtilt.js +34 -66
  4. package/dist/device/blindtilt.js.map +1 -1
  5. package/dist/device/bot.d.ts +9 -9
  6. package/dist/device/bot.d.ts.map +1 -1
  7. package/dist/device/bot.js +61 -97
  8. package/dist/device/bot.js.map +1 -1
  9. package/dist/device/ceilinglight.d.ts +13 -13
  10. package/dist/device/ceilinglight.d.ts.map +1 -1
  11. package/dist/device/ceilinglight.js +38 -73
  12. package/dist/device/ceilinglight.js.map +1 -1
  13. package/dist/device/colorbulb.d.ts +12 -12
  14. package/dist/device/colorbulb.d.ts.map +1 -1
  15. package/dist/device/colorbulb.js +41 -79
  16. package/dist/device/colorbulb.js.map +1 -1
  17. package/dist/device/contact.d.ts +5 -5
  18. package/dist/device/contact.d.ts.map +1 -1
  19. package/dist/device/contact.js +20 -42
  20. package/dist/device/contact.js.map +1 -1
  21. package/dist/device/curtain.d.ts +5 -5
  22. package/dist/device/curtain.d.ts.map +1 -1
  23. package/dist/device/curtain.js +36 -71
  24. package/dist/device/curtain.js.map +1 -1
  25. package/dist/device/device.d.ts +18 -18
  26. package/dist/device/device.d.ts.map +1 -1
  27. package/dist/device/device.js +33 -36
  28. package/dist/device/device.js.map +1 -1
  29. package/dist/device/fan.d.ts +8 -8
  30. package/dist/device/fan.d.ts.map +1 -1
  31. package/dist/device/fan.js +43 -75
  32. package/dist/device/fan.js.map +1 -1
  33. package/dist/device/hub.d.ts +5 -5
  34. package/dist/device/hub.d.ts.map +1 -1
  35. package/dist/device/hub.js +18 -39
  36. package/dist/device/hub.js.map +1 -1
  37. package/dist/device/humidifier.d.ts +5 -5
  38. package/dist/device/humidifier.d.ts.map +1 -1
  39. package/dist/device/humidifier.js +38 -78
  40. package/dist/device/humidifier.js.map +1 -1
  41. package/dist/device/iosensor.d.ts +5 -5
  42. package/dist/device/iosensor.d.ts.map +1 -1
  43. package/dist/device/iosensor.js +21 -40
  44. package/dist/device/iosensor.js.map +1 -1
  45. package/dist/device/lightstrip.d.ts +6 -6
  46. package/dist/device/lightstrip.d.ts.map +1 -1
  47. package/dist/device/lightstrip.js +34 -73
  48. package/dist/device/lightstrip.js.map +1 -1
  49. package/dist/device/lock.d.ts +9 -9
  50. package/dist/device/lock.d.ts.map +1 -1
  51. package/dist/device/lock.js +37 -52
  52. package/dist/device/lock.js.map +1 -1
  53. package/dist/device/meter.d.ts +5 -5
  54. package/dist/device/meter.d.ts.map +1 -1
  55. package/dist/device/meter.js +21 -39
  56. package/dist/device/meter.js.map +1 -1
  57. package/dist/device/meterplus.d.ts +5 -5
  58. package/dist/device/meterplus.d.ts.map +1 -1
  59. package/dist/device/meterplus.js +21 -38
  60. package/dist/device/meterplus.js.map +1 -1
  61. package/dist/device/motion.d.ts +5 -5
  62. package/dist/device/motion.d.ts.map +1 -1
  63. package/dist/device/motion.js +14 -32
  64. package/dist/device/motion.js.map +1 -1
  65. package/dist/device/plug.d.ts +12 -12
  66. package/dist/device/plug.d.ts.map +1 -1
  67. package/dist/device/plug.js +16 -25
  68. package/dist/device/plug.js.map +1 -1
  69. package/dist/device/robotvacuumcleaner.d.ts +11 -11
  70. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  71. package/dist/device/robotvacuumcleaner.js +42 -56
  72. package/dist/device/robotvacuumcleaner.js.map +1 -1
  73. package/dist/device/waterdetector.d.ts +5 -5
  74. package/dist/device/waterdetector.d.ts.map +1 -1
  75. package/dist/device/waterdetector.js +22 -37
  76. package/dist/device/waterdetector.js.map +1 -1
  77. package/dist/homebridge-ui/server.js +2 -2
  78. package/dist/homebridge-ui/server.js.map +1 -1
  79. package/dist/index.d.ts.map +1 -1
  80. package/dist/index.js +0 -4
  81. package/dist/index.js.map +1 -1
  82. package/dist/irdevice/airconditioner.d.ts +8 -8
  83. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  84. package/dist/irdevice/airconditioner.js +64 -105
  85. package/dist/irdevice/airconditioner.js.map +1 -1
  86. package/dist/irdevice/airpurifier.d.ts +10 -10
  87. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  88. package/dist/irdevice/airpurifier.js +22 -42
  89. package/dist/irdevice/airpurifier.js.map +1 -1
  90. package/dist/irdevice/camera.d.ts +9 -9
  91. package/dist/irdevice/camera.d.ts.map +1 -1
  92. package/dist/irdevice/camera.js +15 -25
  93. package/dist/irdevice/camera.js.map +1 -1
  94. package/dist/irdevice/fan.d.ts +8 -8
  95. package/dist/irdevice/fan.d.ts.map +1 -1
  96. package/dist/irdevice/fan.js +21 -40
  97. package/dist/irdevice/fan.js.map +1 -1
  98. package/dist/irdevice/irdevice.d.ts +11 -11
  99. package/dist/irdevice/irdevice.d.ts.map +1 -1
  100. package/dist/irdevice/irdevice.js +14 -22
  101. package/dist/irdevice/irdevice.js.map +1 -1
  102. package/dist/irdevice/light.d.ts +9 -9
  103. package/dist/irdevice/light.d.ts.map +1 -1
  104. package/dist/irdevice/light.js +24 -47
  105. package/dist/irdevice/light.js.map +1 -1
  106. package/dist/irdevice/other.d.ts +9 -9
  107. package/dist/irdevice/other.d.ts.map +1 -1
  108. package/dist/irdevice/other.js +40 -83
  109. package/dist/irdevice/other.js.map +1 -1
  110. package/dist/irdevice/tv.d.ts +9 -9
  111. package/dist/irdevice/tv.d.ts.map +1 -1
  112. package/dist/irdevice/tv.js +29 -54
  113. package/dist/irdevice/tv.js.map +1 -1
  114. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  115. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  116. package/dist/irdevice/vacuumcleaner.js +11 -21
  117. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  118. package/dist/irdevice/waterheater.d.ts +5 -5
  119. package/dist/irdevice/waterheater.d.ts.map +1 -1
  120. package/dist/irdevice/waterheater.js +11 -22
  121. package/dist/irdevice/waterheater.js.map +1 -1
  122. package/dist/platform.d.ts +5 -6
  123. package/dist/platform.d.ts.map +1 -1
  124. package/dist/platform.js +142 -146
  125. package/dist/platform.js.map +1 -1
  126. package/dist/settings.d.ts +2 -2
  127. package/dist/settings.d.ts.map +1 -1
  128. package/dist/settings.js.map +1 -1
  129. package/dist/types/bledevicestatus.d.ts +9 -9
  130. package/dist/types/bledevicestatus.d.ts.map +1 -1
  131. package/dist/types/devicelist.d.ts +6 -6
  132. package/dist/types/devicelist.d.ts.map +1 -1
  133. package/dist/types/deviceresponse.d.ts +4 -4
  134. package/dist/types/deviceresponse.d.ts.map +1 -1
  135. package/dist/types/devicestatus.d.ts +2 -2
  136. package/dist/types/devicestatus.d.ts.map +1 -1
  137. package/dist/types/devicewebhookstatus.d.ts +5 -5
  138. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  139. package/dist/types/irdevicelist.d.ts +4 -4
  140. package/dist/types/irdevicelist.d.ts.map +1 -1
  141. package/dist/types/pushbody.d.ts +2 -2
  142. package/dist/types/pushbody.d.ts.map +1 -1
  143. package/dist/utils.d.ts +4 -4
  144. package/dist/utils.d.ts.map +1 -1
  145. package/dist/utils.js +9 -13
  146. package/dist/utils.js.map +1 -1
  147. package/eslint.config.js +48 -93
  148. package/package.json +54 -47
  149. package/src/device/blindtilt.ts +419 -456
  150. package/src/device/bot.ts +656 -693
  151. package/src/device/ceilinglight.ts +331 -364
  152. package/src/device/colorbulb.ts +412 -448
  153. package/src/device/contact.ts +200 -221
  154. package/src/device/curtain.ts +400 -435
  155. package/src/device/device.ts +206 -208
  156. package/src/device/fan.ts +307 -340
  157. package/src/device/hub.ts +184 -209
  158. package/src/device/humidifier.ts +297 -342
  159. package/src/device/iosensor.ts +182 -204
  160. package/src/device/lightstrip.ts +362 -399
  161. package/src/device/lock.ts +262 -276
  162. package/src/device/meter.ts +183 -205
  163. package/src/device/meterplus.ts +183 -204
  164. package/src/device/motion.ts +169 -185
  165. package/src/device/plug.ts +174 -177
  166. package/src/device/robotvacuumcleaner.ts +256 -269
  167. package/src/device/waterdetector.ts +169 -184
  168. package/src/homebridge-ui/server.ts +16 -15
  169. package/src/index.ts +5 -6
  170. package/src/irdevice/airconditioner.ts +280 -326
  171. package/src/irdevice/airpurifier.ts +124 -143
  172. package/src/irdevice/camera.ts +58 -64
  173. package/src/irdevice/fan.ts +106 -123
  174. package/src/irdevice/irdevice.ts +116 -119
  175. package/src/irdevice/light.ts +119 -143
  176. package/src/irdevice/other.ts +417 -461
  177. package/src/irdevice/tv.ts +155 -177
  178. package/src/irdevice/vacuumcleaner.ts +54 -60
  179. package/src/irdevice/waterheater.ts +56 -63
  180. package/src/platform.ts +1282 -1281
  181. package/src/settings.ts +170 -170
  182. package/src/types/bledevicestatus.ts +255 -255
  183. package/src/types/devicelist.ts +79 -79
  184. package/src/types/deviceresponse.ts +12 -13
  185. package/src/types/devicestatus.ts +124 -124
  186. package/src/types/devicewebhookstatus.ts +126 -127
  187. package/src/types/irdevicelist.ts +10 -10
  188. package/src/types/pushbody.ts +5 -5
  189. package/src/utils.ts +64 -65
  190. package/tsconfig.json +10 -9
@@ -1,14 +1,10 @@
1
- /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
- *
3
- * bot.ts: @switchbot/homebridge-switchbot.
4
- */
5
- import { deviceBase } from './device.js';
6
1
  /*
7
2
  * For Testing Locally:
8
3
  * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
9
4
  */
10
5
  import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
11
- import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
6
+ import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs';
7
+ import { deviceBase } from './device.js';
12
8
  /**
13
9
  * Platform Accessory
14
10
  * An instance of this class is created for each accessory your platform registers
@@ -31,7 +27,7 @@ export class Bot extends deviceBase {
31
27
  On;
32
28
  // OpenAPI
33
29
  deviceStatus;
34
- //Webhook
30
+ // Webhook
35
31
  webhookContext;
36
32
  // BLE
37
33
  serviceData;
@@ -63,10 +59,7 @@ export class Bot extends deviceBase {
63
59
  };
64
60
  accessory.context.Battery = this.Battery;
65
61
  // Initialize Battery Characteristics
66
- this.Battery.Service
67
- .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
68
- .setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
69
- .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
62
+ this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
70
63
  // deviceType
71
64
  if (this.botDeviceType === 'switch') {
72
65
  // Set category
@@ -80,10 +73,7 @@ export class Bot extends deviceBase {
80
73
  accessory.context.Switch = this.Switch;
81
74
  this.debugLog('Displaying as Switch');
82
75
  // Initialize Switch Characteristics
83
- this.Switch.Service
84
- .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
85
- .getCharacteristic(this.hap.Characteristic.On)
86
- .onSet(this.OnSet.bind(this));
76
+ this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
87
77
  // Remove other services
88
78
  this.removeFanService(accessory);
89
79
  this.removeLockService(accessory);
@@ -107,17 +97,12 @@ export class Bot extends deviceBase {
107
97
  accessory.context.GarageDoor = this.GarageDoor;
108
98
  this.debugLog('Displaying as Garage Door Opener');
109
99
  // Initialize GarageDoor Characteristics
110
- this.GarageDoor.Service
111
- .setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
112
- .setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
113
- .getCharacteristic(this.hap.Characteristic.TargetDoorState)
114
- .setProps({
100
+ this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name).setCharacteristic(this.hap.Characteristic.ObstructionDetected, false).getCharacteristic(this.hap.Characteristic.TargetDoorState).setProps({
115
101
  validValues: [0, 100],
116
102
  minValue: 0,
117
103
  maxValue: 100,
118
104
  minStep: 100,
119
- })
120
- .onSet(this.OnSet.bind(this));
105
+ }).onSet(this.OnSet.bind(this));
121
106
  // Remove other services
122
107
  this.removeFanService(accessory);
123
108
  this.removeLockService(accessory);
@@ -141,16 +126,12 @@ export class Bot extends deviceBase {
141
126
  accessory.context.Door = this.Door;
142
127
  this.debugLog('Displaying as Door');
143
128
  // Initialize Door Characteristics
144
- this.Door.Service
145
- .setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
146
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
147
- .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
129
+ this.Door.Service.setCharacteristic(this.hap.Characteristic.Name, this.Door.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
148
130
  validValues: [0, 100],
149
131
  minValue: 0,
150
132
  maxValue: 100,
151
133
  minStep: 100,
152
- })
153
- .onSet(this.OnSet.bind(this));
134
+ }).onSet(this.OnSet.bind(this));
154
135
  // Remove other services
155
136
  this.removeFanService(accessory);
156
137
  this.removeLockService(accessory);
@@ -174,16 +155,12 @@ export class Bot extends deviceBase {
174
155
  accessory.context.Window = this.Window;
175
156
  this.debugLog('Displaying as Window');
176
157
  // Initialize Window Characteristics
177
- this.Window.Service
178
- .setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
179
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
180
- .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
158
+ this.Window.Service.setCharacteristic(this.hap.Characteristic.Name, this.Window.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
181
159
  validValues: [0, 100],
182
160
  minValue: 0,
183
161
  maxValue: 100,
184
162
  minStep: 100,
185
- })
186
- .onSet(this.OnSet.bind(this));
163
+ }).onSet(this.OnSet.bind(this));
187
164
  // Remove other services
188
165
  this.removeFanService(accessory);
189
166
  this.removeLockService(accessory);
@@ -207,17 +184,12 @@ export class Bot extends deviceBase {
207
184
  accessory.context.WindowCovering = this.WindowCovering;
208
185
  this.debugLog('Displaying as Window Covering');
209
186
  // Initialize WindowCovering Characteristics
210
- this.WindowCovering.Service
211
- .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
212
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
213
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
214
- .setProps({
187
+ this.WindowCovering.Service.setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
215
188
  validValues: [0, 100],
216
189
  minValue: 0,
217
190
  maxValue: 100,
218
191
  minStep: 100,
219
- })
220
- .onSet(this.OnSet.bind(this));
192
+ }).onSet(this.OnSet.bind(this));
221
193
  // Remove other services
222
194
  this.removeFanService(accessory);
223
195
  this.removeLockService(accessory);
@@ -241,11 +213,7 @@ export class Bot extends deviceBase {
241
213
  accessory.context.LockMechanism = this.LockMechanism;
242
214
  this.debugLog('Displaying as Lock');
243
215
  // Initialize Lock Characteristics
244
- this.LockMechanism.Service
245
- .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
246
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
247
- .getCharacteristic(this.hap.Characteristic.LockTargetState)
248
- .onSet(this.OnSet.bind(this));
216
+ this.LockMechanism.Service.setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name).setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED).getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.OnSet.bind(this));
249
217
  // Remove other services
250
218
  this.removeFanService(accessory);
251
219
  this.removeDoorService(accessory);
@@ -269,10 +237,7 @@ export class Bot extends deviceBase {
269
237
  accessory.context.Faucet = this.Faucet;
270
238
  this.debugLog('Displaying as Faucet');
271
239
  // Initialize Faucet Characteristics
272
- this.Faucet.Service
273
- .setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
274
- .getCharacteristic(this.hap.Characteristic.Active)
275
- .onSet(this.OnSet.bind(this));
240
+ this.Faucet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
276
241
  // Remove other services
277
242
  this.removeFanService(accessory);
278
243
  this.removeLockService(accessory);
@@ -296,10 +261,7 @@ export class Bot extends deviceBase {
296
261
  accessory.context.Fan = this.Fan;
297
262
  this.debugLog('Displaying as Fan');
298
263
  // Initialize Fan Characteristics
299
- this.Fan.Service
300
- .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
301
- .getCharacteristic(this.hap.Characteristic.Active)
302
- .onSet(this.OnSet.bind(this));
264
+ this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this));
303
265
  // Remove other services
304
266
  this.removeLockService(accessory);
305
267
  this.removeDoorService(accessory);
@@ -318,16 +280,12 @@ export class Bot extends deviceBase {
318
280
  accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
319
281
  this.StatefulProgrammableSwitch = {
320
282
  Name: accessory.displayName,
321
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
322
- ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
283
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch),
323
284
  };
324
285
  accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch;
325
286
  this.debugLog('Displaying as Stateful Programmable Switch');
326
287
  // Initialize StatefulProgrammableSwitch Characteristics
327
- this.StatefulProgrammableSwitch.Service
328
- .setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
329
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
330
- .onSet(this.OnSet.bind(this));
288
+ this.StatefulProgrammableSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onSet(this.OnSet.bind(this));
331
289
  // Remove other services
332
290
  this.removeFanService(accessory);
333
291
  this.removeLockService(accessory);
@@ -351,10 +309,7 @@ export class Bot extends deviceBase {
351
309
  accessory.context.Outlet = this.Outlet;
352
310
  this.debugLog('Displaying as Outlet');
353
311
  // Initialize Outlet Characteristics
354
- this.Outlet.Service
355
- .setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
356
- .getCharacteristic(this.hap.Characteristic.On)
357
- .onSet(this.OnSet.bind(this));
312
+ this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
358
313
  // Remove other services
359
314
  this.removeFanService(accessory);
360
315
  this.removeLockService(accessory);
@@ -377,7 +332,7 @@ export class Bot extends deviceBase {
377
332
  catch (e) {
378
333
  this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`);
379
334
  }
380
- //regisiter webhook event handler if enabled
335
+ // regisiter webhook event handler if enabled
381
336
  try {
382
337
  this.debugLog('Registering Webhook Event Handler');
383
338
  this.registerWebhook();
@@ -385,7 +340,7 @@ export class Bot extends deviceBase {
385
340
  catch (e) {
386
341
  this.errorLog(`failed to registerWebhook, Error: ${e}`);
387
342
  }
388
- //regisiter platform BLE event handler if enabled
343
+ // regisiter platform BLE event handler if enabled
389
344
  try {
390
345
  this.debugLog('Registering Platform BLE Event Handler');
391
346
  this.registerPlatformBLE();
@@ -430,8 +385,7 @@ export class Bot extends deviceBase {
430
385
  */
431
386
  async BLEparseStatus() {
432
387
  await this.debugLog('BLEparseStatus');
433
- await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}),`
434
- + ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
388
+ await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
435
389
  // BLEmode (true if Switch Mode) | (false if Press Mode)
436
390
  this.On = this.serviceData.mode ? this.serviceData.state : false;
437
391
  const mode = this.serviceData.mode ? 'Switch' : 'Press';
@@ -442,7 +396,8 @@ export class Bot extends deviceBase {
442
396
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
443
397
  // StatusLowBattery
444
398
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
445
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
399
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
400
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
446
401
  await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
447
402
  }
448
403
  /**
@@ -450,10 +405,9 @@ export class Bot extends deviceBase {
450
405
  */
451
406
  async openAPIparseStatus() {
452
407
  await this.debugLog('openAPIparseStatus');
453
- await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}),`
454
- + ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
408
+ await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}), current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
455
409
  // On
456
- this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on' ? true : false;
410
+ this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on';
457
411
  this.accessory.context.On = this.On;
458
412
  await this.debugLog(`On: ${this.accessory.context.On}`);
459
413
  // Battery Level
@@ -461,7 +415,8 @@ export class Bot extends deviceBase {
461
415
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
462
416
  // StatusLowBattery
463
417
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
464
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
418
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
419
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
465
420
  await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
466
421
  // Firmware Version
467
422
  if (this.deviceStatus.version) {
@@ -480,17 +435,17 @@ export class Bot extends deviceBase {
480
435
  }
481
436
  async parseStatusWebhook() {
482
437
  await this.debugLog('parseStatusWebhook');
483
- await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery},`
484
- + ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
438
+ await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}, ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
485
439
  // On
486
- this.On = this.webhookContext.power === 'on' ? true : false;
440
+ this.On = this.webhookContext.power === 'on';
487
441
  await this.debugLog(`On: ${this.On}`);
488
442
  // BatteryLevel
489
443
  this.Battery.BatteryLevel = this.webhookContext.battery;
490
444
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
491
445
  // StatusLowBattery
492
446
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
493
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
447
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
448
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
494
449
  await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
495
450
  // Mode
496
451
  this.botMode = this.webhookContext.deviceMode;
@@ -566,7 +521,6 @@ export class Bot extends deviceBase {
566
521
  const { body, statusCode } = await this.deviceRefreshStatus();
567
522
  const deviceStatus = await body.json();
568
523
  await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
569
- ;
570
524
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
571
525
  await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
572
526
  this.deviceStatus = deviceStatus.body;
@@ -604,10 +558,10 @@ export class Bot extends deviceBase {
604
558
  }
605
559
  /**
606
560
  * Pushes the requested changes to the SwitchBot API
607
- * deviceType commandType Command command parameter Description
608
- * Bot - "command" "turnOff" "default" = set to OFF state
609
- * Bot - "command" "turnOn" "default" = set to ON state
610
- * Bot - "command" "press" "default" = trigger press
561
+ * deviceType commandType Command command parameter Description
562
+ * Bot "command" "turnOff" "default" = set to OFF state
563
+ * Bot "command" "turnOn" "default" = set to ON state
564
+ * Bot "command" "press" "default" = trigger press
611
565
  */
612
566
  async pushChanges() {
613
567
  if (!this.device.enableCloudService && this.OpenAPI) {
@@ -637,7 +591,7 @@ export class Bot extends deviceBase {
637
591
  await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
638
592
  const switchbot = await this.platform.connectBLE(this.accessory, this.device);
639
593
  await this.convertBLEAddress();
640
- //if (switchbot !== false) {
594
+ // if (switchbot !== false) {
641
595
  await this.debugLog(`Bot Mode: ${this.botMode}`);
642
596
  if (this.botMode === 'press') {
643
597
  switchbot
@@ -764,9 +718,9 @@ export class Bot extends deviceBase {
764
718
  this.On = true;
765
719
  }
766
720
  }
767
- else if (this.botDeviceType === 'door' ||
768
- this.botDeviceType === 'window' ||
769
- this.botDeviceType === 'windowcovering') {
721
+ else if (this.botDeviceType === 'door'
722
+ || this.botDeviceType === 'window'
723
+ || this.botDeviceType === 'windowcovering') {
770
724
  this.debugLog(`Set TargetPosition: ${value}`);
771
725
  if (value === 0) {
772
726
  this.On = false;
@@ -1117,38 +1071,48 @@ export class Bot extends deviceBase {
1117
1071
  accessory.removeService(this.Switch.Service);
1118
1072
  }
1119
1073
  async getBotConfigSettings(device) {
1120
- //Bot Device Type
1121
- this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType ? this.accessory.context.botDeviceType
1074
+ // Bot Device Type
1075
+ this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType
1076
+ ? this.accessory.context.botDeviceType
1122
1077
  : device.bot?.deviceType ?? 'outlet';
1123
- const botDeviceType = this.accessory.context.botDeviceType ? `Using Device Type: ${this.botDeviceType}, from Accessory Cache.`
1124
- : device.bot?.deviceType ? `Using Device Type: ${this.botDeviceType}`
1078
+ const botDeviceType = this.accessory.context.botDeviceType
1079
+ ? `Using Device Type: ${this.botDeviceType}, from Accessory Cache.`
1080
+ : device.bot?.deviceType
1081
+ ? `Using Device Type: ${this.botDeviceType}`
1125
1082
  : `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`;
1126
1083
  await this.debugWarnLog(botDeviceType);
1127
1084
  this.accessory.context.botDeviceType = this.botDeviceType;
1128
1085
  // Bot Mode
1129
1086
  this.botMode = this.accessory.context.botMode ?? device.bot?.mode ?? 'switch';
1130
- const botMode = this.accessory.context.botMode ? `Using Bot Mode: ${this.botMode}, from Accessory Cache.`
1087
+ const botMode = this.accessory.context.botMode
1088
+ ? `Using Bot Mode: ${this.botMode}, from Accessory Cache.`
1131
1089
  : device.bot?.mode ? `Using Bot Mode: ${this.botMode}` : `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`;
1132
1090
  await this.debugWarnLog(botMode);
1133
1091
  this.accessory.context.botMode = this.botMode;
1134
1092
  // Bot Double Press
1135
1093
  this.doublePress = this.accessory.context.doublePress ?? device.bot?.doublePress ?? 1;
1136
- const doublePress = this.accessory.context.doublePress ? `Using Double Press: ${this.doublePress}, from Accessory Cache.`
1137
- : device.bot?.doublePress ? `Using Double Press: ${this.doublePress}`
1094
+ const doublePress = this.accessory.context.doublePress
1095
+ ? `Using Double Press: ${this.doublePress}, from Accessory Cache.`
1096
+ : device.bot?.doublePress
1097
+ ? `Using Double Press: ${this.doublePress}`
1138
1098
  : `No Double Press Set, Using default Double Press: ${this.doublePress}`;
1139
1099
  await this.debugWarnLog(doublePress);
1140
1100
  this.accessory.context.doublePress = this.doublePress;
1141
1101
  // Bot Press PushRate
1142
1102
  this.pushRatePress = this.accessory.context.pushRatePress ?? device.bot?.pushRatePress ?? 15;
1143
- const pushRatePress = this.accessory.context.pushRatePress ? `Using Push Rate Press: ${this.pushRatePress}, from Accessory Cache.`
1144
- : device.bot?.pushRatePress ? `Using Bot Push Rate Press: ${this.pushRatePress}`
1103
+ const pushRatePress = this.accessory.context.pushRatePress
1104
+ ? `Using Push Rate Press: ${this.pushRatePress}, from Accessory Cache.`
1105
+ : device.bot?.pushRatePress
1106
+ ? `Using Bot Push Rate Press: ${this.pushRatePress}`
1145
1107
  : `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`;
1146
1108
  await this.debugWarnLog(pushRatePress);
1147
1109
  this.accessory.context.pushRatePress = this.pushRatePress;
1148
1110
  // Bot Allow Push
1149
1111
  this.allowPush = this.accessory.context.allowPush ?? device.bot?.allowPush ?? false;
1150
- const allowPush = this.accessory.context.allowPush ? `Using Allow Push: ${this.allowPush}, from Accessory Cache.`
1151
- : device.bot?.allowPush ? `Using Allow Push: ${this.allowPush}`
1112
+ const allowPush = this.accessory.context.allowPush
1113
+ ? `Using Allow Push: ${this.allowPush}, from Accessory Cache.`
1114
+ : device.bot?.allowPush
1115
+ ? `Using Allow Push: ${this.allowPush}`
1152
1116
  : `No Allow Push Set, Using default Allow Push: ${this.allowPush}`;
1153
1117
  await this.debugWarnLog(allowPush);
1154
1118
  this.accessory.context.allowPush = this.allowPush;