@switchbot/homebridge-switchbot 3.7.1-beta.2 → 3.7.1-beta.21

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 (199) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +14 -0
  3. package/assets/security-privacy-bluetooth.png +0 -0
  4. package/config.schema.json +74 -2
  5. package/dist/device/blindtilt.d.ts +21 -9
  6. package/dist/device/blindtilt.d.ts.map +1 -1
  7. package/dist/device/blindtilt.js +167 -96
  8. package/dist/device/blindtilt.js.map +1 -1
  9. package/dist/device/bot-old.d.ts +132 -0
  10. package/dist/device/bot-old.d.ts.map +1 -0
  11. package/dist/device/bot-old.js +1482 -0
  12. package/dist/device/bot-old.js.map +1 -0
  13. package/dist/device/bot.d.ts +10 -9
  14. package/dist/device/bot.d.ts.map +1 -1
  15. package/dist/device/bot.js +186 -187
  16. package/dist/device/bot.js.map +1 -1
  17. package/dist/device/ceilinglight.d.ts +14 -13
  18. package/dist/device/ceilinglight.d.ts.map +1 -1
  19. package/dist/device/ceilinglight.js +87 -97
  20. package/dist/device/ceilinglight.js.map +1 -1
  21. package/dist/device/colorbulb.d.ts +13 -12
  22. package/dist/device/colorbulb.d.ts.map +1 -1
  23. package/dist/device/colorbulb.js +92 -105
  24. package/dist/device/colorbulb.js.map +1 -1
  25. package/dist/device/contact.d.ts +6 -5
  26. package/dist/device/contact.d.ts.map +1 -1
  27. package/dist/device/contact.js +71 -68
  28. package/dist/device/contact.js.map +1 -1
  29. package/dist/device/curtain.d.ts +17 -5
  30. package/dist/device/curtain.d.ts.map +1 -1
  31. package/dist/device/curtain.js +184 -118
  32. package/dist/device/curtain.js.map +1 -1
  33. package/dist/device/device.d.ts +18 -18
  34. package/dist/device/device.d.ts.map +1 -1
  35. package/dist/device/device.js +33 -36
  36. package/dist/device/device.js.map +1 -1
  37. package/dist/device/fan.d.ts +9 -8
  38. package/dist/device/fan.d.ts.map +1 -1
  39. package/dist/device/fan.js +94 -101
  40. package/dist/device/fan.js.map +1 -1
  41. package/dist/device/hub.d.ts +6 -5
  42. package/dist/device/hub.d.ts.map +1 -1
  43. package/dist/device/hub.js +69 -65
  44. package/dist/device/hub.js.map +1 -1
  45. package/dist/device/humidifier.d.ts +6 -5
  46. package/dist/device/humidifier.d.ts.map +1 -1
  47. package/dist/device/humidifier.js +89 -104
  48. package/dist/device/humidifier.js.map +1 -1
  49. package/dist/device/iosensor.d.ts +6 -5
  50. package/dist/device/iosensor.d.ts.map +1 -1
  51. package/dist/device/iosensor.js +72 -66
  52. package/dist/device/iosensor.js.map +1 -1
  53. package/dist/device/lightstrip.d.ts +7 -6
  54. package/dist/device/lightstrip.d.ts.map +1 -1
  55. package/dist/device/lightstrip.js +85 -99
  56. package/dist/device/lightstrip.js.map +1 -1
  57. package/dist/device/lock.d.ts +10 -9
  58. package/dist/device/lock.d.ts.map +1 -1
  59. package/dist/device/lock.js +89 -79
  60. package/dist/device/lock.js.map +1 -1
  61. package/dist/device/meter.d.ts +6 -5
  62. package/dist/device/meter.d.ts.map +1 -1
  63. package/dist/device/meter.js +72 -65
  64. package/dist/device/meter.js.map +1 -1
  65. package/dist/device/meterplus.d.ts +6 -5
  66. package/dist/device/meterplus.d.ts.map +1 -1
  67. package/dist/device/meterplus.js +72 -64
  68. package/dist/device/meterplus.js.map +1 -1
  69. package/dist/device/motion.d.ts +6 -5
  70. package/dist/device/motion.d.ts.map +1 -1
  71. package/dist/device/motion.js +65 -58
  72. package/dist/device/motion.js.map +1 -1
  73. package/dist/device/plug.d.ts +13 -12
  74. package/dist/device/plug.d.ts.map +1 -1
  75. package/dist/device/plug.js +68 -52
  76. package/dist/device/plug.js.map +1 -1
  77. package/dist/device/robotvacuumcleaner.d.ts +12 -11
  78. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  79. package/dist/device/robotvacuumcleaner.js +93 -82
  80. package/dist/device/robotvacuumcleaner.js.map +1 -1
  81. package/dist/device/waterdetector.d.ts +6 -5
  82. package/dist/device/waterdetector.d.ts.map +1 -1
  83. package/dist/device/waterdetector.js +73 -63
  84. package/dist/device/waterdetector.js.map +1 -1
  85. package/dist/homebridge-ui/server.js +2 -2
  86. package/dist/homebridge-ui/server.js.map +1 -1
  87. package/dist/index.d.ts.map +1 -1
  88. package/dist/index.js +0 -4
  89. package/dist/index.js.map +1 -1
  90. package/dist/irdevice/airconditioner.d.ts +8 -8
  91. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  92. package/dist/irdevice/airconditioner.js +61 -105
  93. package/dist/irdevice/airconditioner.js.map +1 -1
  94. package/dist/irdevice/airpurifier.d.ts +10 -10
  95. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  96. package/dist/irdevice/airpurifier.js +22 -42
  97. package/dist/irdevice/airpurifier.js.map +1 -1
  98. package/dist/irdevice/camera.d.ts +9 -9
  99. package/dist/irdevice/camera.d.ts.map +1 -1
  100. package/dist/irdevice/camera.js +15 -25
  101. package/dist/irdevice/camera.js.map +1 -1
  102. package/dist/irdevice/fan.d.ts +8 -8
  103. package/dist/irdevice/fan.d.ts.map +1 -1
  104. package/dist/irdevice/fan.js +21 -40
  105. package/dist/irdevice/fan.js.map +1 -1
  106. package/dist/irdevice/irdevice.d.ts +11 -11
  107. package/dist/irdevice/irdevice.d.ts.map +1 -1
  108. package/dist/irdevice/irdevice.js +14 -22
  109. package/dist/irdevice/irdevice.js.map +1 -1
  110. package/dist/irdevice/light.d.ts +9 -9
  111. package/dist/irdevice/light.d.ts.map +1 -1
  112. package/dist/irdevice/light.js +24 -47
  113. package/dist/irdevice/light.js.map +1 -1
  114. package/dist/irdevice/other.d.ts +9 -9
  115. package/dist/irdevice/other.d.ts.map +1 -1
  116. package/dist/irdevice/other.js +40 -83
  117. package/dist/irdevice/other.js.map +1 -1
  118. package/dist/irdevice/tv.d.ts +9 -9
  119. package/dist/irdevice/tv.d.ts.map +1 -1
  120. package/dist/irdevice/tv.js +29 -54
  121. package/dist/irdevice/tv.js.map +1 -1
  122. package/dist/irdevice/vacuumcleaner.d.ts +5 -5
  123. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  124. package/dist/irdevice/vacuumcleaner.js +11 -21
  125. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  126. package/dist/irdevice/waterheater.d.ts +5 -5
  127. package/dist/irdevice/waterheater.d.ts.map +1 -1
  128. package/dist/irdevice/waterheater.js +11 -22
  129. package/dist/irdevice/waterheater.js.map +1 -1
  130. package/dist/platform.d.ts +24 -23
  131. package/dist/platform.d.ts.map +1 -1
  132. package/dist/platform.js +509 -723
  133. package/dist/platform.js.map +1 -1
  134. package/dist/settings.d.ts +5 -2
  135. package/dist/settings.d.ts.map +1 -1
  136. package/dist/settings.js.map +1 -1
  137. package/dist/types/bledevicestatus.d.ts +9 -9
  138. package/dist/types/bledevicestatus.d.ts.map +1 -1
  139. package/dist/types/devicelist.d.ts +6 -6
  140. package/dist/types/devicelist.d.ts.map +1 -1
  141. package/dist/types/deviceresponse.d.ts +4 -4
  142. package/dist/types/deviceresponse.d.ts.map +1 -1
  143. package/dist/types/devicestatus.d.ts +2 -2
  144. package/dist/types/devicestatus.d.ts.map +1 -1
  145. package/dist/types/devicewebhookstatus.d.ts +5 -5
  146. package/dist/types/devicewebhookstatus.d.ts.map +1 -1
  147. package/dist/types/irdevicelist.d.ts +4 -4
  148. package/dist/types/irdevicelist.d.ts.map +1 -1
  149. package/dist/types/pushbody.d.ts +2 -2
  150. package/dist/types/pushbody.d.ts.map +1 -1
  151. package/dist/utils.d.ts +4 -4
  152. package/dist/utils.d.ts.map +1 -1
  153. package/dist/utils.js +9 -13
  154. package/dist/utils.js.map +1 -1
  155. package/eslint.config.js +48 -93
  156. package/package.json +64 -57
  157. package/src/device/blindtilt.ts +537 -456
  158. package/src/device/bot-old.ts +1540 -0
  159. package/src/device/bot.ts +732 -725
  160. package/src/device/ceilinglight.ts +359 -368
  161. package/src/device/colorbulb.ts +441 -453
  162. package/src/device/contact.ts +229 -226
  163. package/src/device/curtain.ts +526 -444
  164. package/src/device/device.ts +206 -208
  165. package/src/device/fan.ts +336 -345
  166. package/src/device/hub.ts +213 -214
  167. package/src/device/humidifier.ts +326 -347
  168. package/src/device/iosensor.ts +211 -209
  169. package/src/device/lightstrip.ts +391 -404
  170. package/src/device/lock.ts +292 -282
  171. package/src/device/meter.ts +212 -210
  172. package/src/device/meterplus.ts +212 -209
  173. package/src/device/motion.ts +198 -190
  174. package/src/device/plug.ts +203 -182
  175. package/src/device/robotvacuumcleaner.ts +280 -269
  176. package/src/device/waterdetector.ts +198 -189
  177. package/src/homebridge-ui/server.ts +16 -15
  178. package/src/index.ts +5 -6
  179. package/src/irdevice/airconditioner.ts +277 -326
  180. package/src/irdevice/airpurifier.ts +124 -143
  181. package/src/irdevice/camera.ts +58 -64
  182. package/src/irdevice/fan.ts +106 -123
  183. package/src/irdevice/irdevice.ts +116 -119
  184. package/src/irdevice/light.ts +119 -143
  185. package/src/irdevice/other.ts +417 -461
  186. package/src/irdevice/tv.ts +155 -177
  187. package/src/irdevice/vacuumcleaner.ts +54 -60
  188. package/src/irdevice/waterheater.ts +56 -63
  189. package/src/platform.ts +1491 -1681
  190. package/src/settings.ts +172 -169
  191. package/src/types/bledevicestatus.ts +252 -256
  192. package/src/types/devicelist.ts +79 -79
  193. package/src/types/deviceresponse.ts +12 -13
  194. package/src/types/devicestatus.ts +124 -124
  195. package/src/types/devicewebhookstatus.ts +126 -131
  196. package/src/types/irdevicelist.ts +10 -10
  197. package/src/types/pushbody.ts +5 -5
  198. package/src/utils.ts +64 -65
  199. package/tsconfig.json +10 -9
package/src/device/bot.ts CHANGED
@@ -2,17 +2,23 @@
2
2
  *
3
3
  * bot.ts: @switchbot/homebridge-switchbot.
4
4
  */
5
- import { deviceBase } from './device.js';
6
- import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
7
- import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
8
-
9
- import type { devicesConfig } from '../settings.js';
10
- import type { device } from '../types/devicelist.js';
11
- import type { SwitchBotPlatform } from '../platform.js';
12
- import type { botServiceData } from '../types/bledevicestatus.js';
13
- import type { botStatus } from '../types/devicestatus.js';
14
- import type { botWebhookContext } from '../types/devicewebhookstatus.js';
15
- import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+
7
+ import type { SwitchBotPlatform } from '../platform.js'
8
+ import type { devicesConfig } from '../settings.js'
9
+ import type { botServiceData } from '../types/bledevicestatus.js'
10
+ import type { device } from '../types/devicelist.js'
11
+ import type { botStatus } from '../types/devicestatus.js'
12
+ import type { botWebhookContext } from '../types/devicewebhookstatus.js'
13
+
14
+ /*
15
+ * For Testing Locally:
16
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
17
+ */
18
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
19
+ import { debounceTime, interval, skipWhile, Subject, take, tap } from 'rxjs'
20
+
21
+ import { deviceBase } from './device.js'
16
22
 
17
23
  /**
18
24
  * Platform Accessory
@@ -22,428 +28,403 @@ import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge
22
28
  export class Bot extends deviceBase {
23
29
  // Services
24
30
  private Battery: {
25
- Name: CharacteristicValue;
26
- Service: Service;
27
- BatteryLevel: CharacteristicValue;
28
- StatusLowBattery: CharacteristicValue;
29
- };
31
+ Name: CharacteristicValue
32
+ Service: Service
33
+ BatteryLevel: CharacteristicValue
34
+ StatusLowBattery: CharacteristicValue
35
+ }
30
36
 
31
37
  private Switch?: {
32
- Name: CharacteristicValue;
33
- Service: Service;
34
- };
38
+ Name: CharacteristicValue
39
+ Service: Service
40
+ }
35
41
 
36
42
  private GarageDoor?: {
37
- Name: CharacteristicValue;
38
- Service: Service;
39
- };
43
+ Name: CharacteristicValue
44
+ Service: Service
45
+ }
40
46
 
41
47
  private Door?: {
42
- Name: CharacteristicValue;
43
- Service: Service;
44
- };
48
+ Name: CharacteristicValue
49
+ Service: Service
50
+ }
45
51
 
46
52
  private Window?: {
47
- Name: CharacteristicValue;
48
- Service: Service;
49
- };
53
+ Name: CharacteristicValue
54
+ Service: Service
55
+ }
50
56
 
51
57
  private WindowCovering?: {
52
- Name: CharacteristicValue;
53
- Service: Service;
54
- };
58
+ Name: CharacteristicValue
59
+ Service: Service
60
+ }
55
61
 
56
62
  private LockMechanism?: {
57
- Name: CharacteristicValue;
58
- Service: Service;
59
- };
63
+ Name: CharacteristicValue
64
+ Service: Service
65
+ }
60
66
 
61
67
  private Faucet?: {
62
- Name: CharacteristicValue;
63
- Service: Service;
64
- };
68
+ Name: CharacteristicValue
69
+ Service: Service
70
+ }
65
71
 
66
72
  private Fan?: {
67
- Name: CharacteristicValue;
68
- Service: Service;
69
- };
73
+ Name: CharacteristicValue
74
+ Service: Service
75
+ }
70
76
 
71
77
  private StatefulProgrammableSwitch?: {
72
- Name: CharacteristicValue;
73
- Service: Service;
74
- };
78
+ Name: CharacteristicValue
79
+ Service: Service
80
+ }
75
81
 
76
82
  private Outlet?: {
77
- Name: CharacteristicValue;
78
- Service: Service;
79
- };
83
+ Name: CharacteristicValue
84
+ Service: Service
85
+ }
80
86
 
81
- On!: boolean;
87
+ On!: boolean
82
88
 
83
89
  // OpenAPI
84
- deviceStatus!: botStatus;
90
+ deviceStatus!: botStatus
85
91
 
86
- //Webhook
87
- webhookContext!: botWebhookContext;
92
+ // Webhook
93
+ webhookContext!: botWebhookContext
88
94
 
89
95
  // BLE
90
- serviceData!: botServiceData;
96
+ serviceData!: botServiceData
91
97
 
92
98
  // Config
93
- botMode!: string;
94
- allowPush?: boolean;
95
- doublePress!: number;
96
- botDeviceType!: string;
97
- pushRatePress!: number;
98
- multiPressCount!: number;
99
+ botMode!: string
100
+ allowPush?: boolean
101
+ doublePress!: number
102
+ botDeviceType!: string
103
+ pushRatePress!: number
104
+ multiPressCount!: number
99
105
 
100
106
  // Updates
101
- botUpdateInProgress!: boolean;
102
- doBotUpdate!: Subject<void>;
107
+ botUpdateInProgress!: boolean
108
+ doBotUpdate!: Subject<void>
103
109
 
104
110
  constructor(
105
111
  readonly platform: SwitchBotPlatform,
106
112
  accessory: PlatformAccessory,
107
113
  device: device & devicesConfig,
108
114
  ) {
109
- super(platform, accessory, device);
115
+ super(platform, accessory, device)
110
116
 
111
117
  // default placeholders
112
- this.getBotConfigSettings(device);
118
+ this.getBotConfigSettings(device)
113
119
 
114
120
  // this is subject we use to track when we need to POST changes to the SwitchBot API
115
- this.doBotUpdate = new Subject();
116
- this.botUpdateInProgress = false;
121
+ this.doBotUpdate = new Subject()
122
+ this.botUpdateInProgress = false
117
123
 
118
124
  // Initialize Battery property
119
- accessory.context.Battery = accessory.context.Battery ?? {};
125
+ accessory.context.Battery = accessory.context.Battery ?? {}
120
126
  this.Battery = {
121
127
  Name: `${accessory.displayName} Battery`,
122
128
  Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
123
129
  BatteryLevel: accessory.context.BatteryLevel ?? 100,
124
130
  StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
125
- };
126
- accessory.context.Battery = this.Battery as object;
131
+ }
132
+ accessory.context.Battery = this.Battery as object
127
133
  // Initialize Battery Characteristics
128
- this.Battery.Service
129
- .setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
130
- .setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
131
- .setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
134
+ 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)
132
135
 
133
136
  // deviceType
134
137
  if (this.botDeviceType === 'switch') {
135
138
  // Set category
136
- accessory.category = this.hap.Categories.SWITCH;
139
+ accessory.category = this.hap.Categories.SWITCH
137
140
  // Initialize Switch Service
138
- accessory.context.Switch = accessory.context.Switch ?? {};
141
+ accessory.context.Switch = accessory.context.Switch ?? {}
139
142
  this.Switch = {
140
143
  Name: accessory.displayName,
141
144
  Service: accessory.getService(this.hap.Service.Switch) ?? accessory.addService(this.hap.Service.Switch) as Service,
142
- };
143
- accessory.context.Switch = this.Switch as object;
144
- this.debugLog('Displaying as Switch');
145
+ }
146
+ accessory.context.Switch = this.Switch as object
147
+ this.debugLog('Displaying as Switch')
145
148
  // Initialize Switch Characteristics
146
- this.Switch.Service
147
- .setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name)
148
- .getCharacteristic(this.hap.Characteristic.On)
149
- .onSet(this.OnSet.bind(this));
149
+ this.Switch.Service.setCharacteristic(this.hap.Characteristic.Name, this.Switch.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this))
150
150
  // Remove other services
151
- this.removeFanService(accessory);
152
- this.removeLockService(accessory);
153
- this.removeDoorService(accessory);
154
- this.removeFaucetService(accessory);
155
- this.removeOutletService(accessory);
156
- this.removeWindowService(accessory);
157
- this.removeGarageDoorService(accessory);
158
- this.removeWindowCoveringService(accessory);
159
- this.removeStatefulProgrammableSwitchService(accessory);
151
+ this.removeFanService(accessory)
152
+ this.removeLockService(accessory)
153
+ this.removeDoorService(accessory)
154
+ this.removeFaucetService(accessory)
155
+ this.removeOutletService(accessory)
156
+ this.removeWindowService(accessory)
157
+ this.removeGarageDoorService(accessory)
158
+ this.removeWindowCoveringService(accessory)
159
+ this.removeStatefulProgrammableSwitchService(accessory)
160
160
  } else if (this.botDeviceType === 'garagedoor') {
161
161
  // Set category
162
- accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER;
162
+ accessory.category = this.hap.Categories.GARAGE_DOOR_OPENER
163
163
  // Initialize GarageDoor Service
164
- accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
164
+ accessory.context.GarageDoor = accessory.context.GarageDoor ?? {}
165
165
  this.GarageDoor = {
166
166
  Name: accessory.displayName,
167
167
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) ?? accessory.addService(this.hap.Service.GarageDoorOpener) as Service,
168
- };
169
- accessory.context.GarageDoor = this.GarageDoor as object;
170
- this.debugLog('Displaying as Garage Door Opener');
168
+ }
169
+ accessory.context.GarageDoor = this.GarageDoor as object
170
+ this.debugLog('Displaying as Garage Door Opener')
171
171
  // Initialize GarageDoor Characteristics
172
- this.GarageDoor.Service
173
- .setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name)
174
- .setCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
175
- .getCharacteristic(this.hap.Characteristic.TargetDoorState)
176
- .setProps({
177
- validValues: [0, 100],
178
- minValue: 0,
179
- maxValue: 100,
180
- minStep: 100,
181
- })
182
- .onSet(this.OnSet.bind(this));
172
+ this.GarageDoor.Service.setCharacteristic(this.hap.Characteristic.Name, this.GarageDoor.Name).setCharacteristic(this.hap.Characteristic.ObstructionDetected, false).getCharacteristic(this.hap.Characteristic.TargetDoorState).setProps({
173
+ validValues: [0, 100],
174
+ minValue: 0,
175
+ maxValue: 100,
176
+ minStep: 100,
177
+ }).onSet(this.OnSet.bind(this))
183
178
  // Remove other services
184
- this.removeFanService(accessory);
185
- this.removeLockService(accessory);
186
- this.removeDoorService(accessory);
187
- this.removeFaucetService(accessory);
188
- this.removeOutletService(accessory);
189
- this.removeSwitchService(accessory);
190
- this.removeWindowService(accessory);
191
- this.removeWindowCoveringService(accessory);
192
- this.removeStatefulProgrammableSwitchService(accessory);
179
+ this.removeFanService(accessory)
180
+ this.removeLockService(accessory)
181
+ this.removeDoorService(accessory)
182
+ this.removeFaucetService(accessory)
183
+ this.removeOutletService(accessory)
184
+ this.removeSwitchService(accessory)
185
+ this.removeWindowService(accessory)
186
+ this.removeWindowCoveringService(accessory)
187
+ this.removeStatefulProgrammableSwitchService(accessory)
193
188
  } else if (this.botDeviceType === 'door') {
194
189
  // Set category
195
- accessory.category = this.hap.Categories.DOOR;
190
+ accessory.category = this.hap.Categories.DOOR
196
191
  // Initialize Door Service
197
- accessory.context.Door = accessory.context.Door ?? {};
192
+ accessory.context.Door = accessory.context.Door ?? {}
198
193
  this.Door = {
199
194
  Name: accessory.displayName,
200
195
  Service: accessory.getService(this.hap.Service.Door) ?? accessory.addService(this.hap.Service.Door) as Service,
201
- };
202
- accessory.context.Door = this.Door as object;
203
- this.debugLog('Displaying as Door');
196
+ }
197
+ accessory.context.Door = this.Door as object
198
+ this.debugLog('Displaying as Door')
204
199
  // Initialize Door Characteristics
205
- this.Door.Service
206
- .setCharacteristic(this.hap.Characteristic.Name, this.Door.Name)
207
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
208
- .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
209
- validValues: [0, 100],
210
- minValue: 0,
211
- maxValue: 100,
212
- minStep: 100,
213
- })
214
- .onSet(this.OnSet.bind(this));
200
+ 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({
201
+ validValues: [0, 100],
202
+ minValue: 0,
203
+ maxValue: 100,
204
+ minStep: 100,
205
+ }).onSet(this.OnSet.bind(this))
215
206
  // Remove other services
216
- this.removeFanService(accessory);
217
- this.removeLockService(accessory);
218
- this.removeOutletService(accessory);
219
- this.removeFaucetService(accessory);
220
- this.removeSwitchService(accessory);
221
- this.removeWindowService(accessory);
222
- this.removeGarageDoorService(accessory);
223
- this.removeWindowCoveringService(accessory);
224
- this.removeStatefulProgrammableSwitchService(accessory);
207
+ this.removeFanService(accessory)
208
+ this.removeLockService(accessory)
209
+ this.removeOutletService(accessory)
210
+ this.removeFaucetService(accessory)
211
+ this.removeSwitchService(accessory)
212
+ this.removeWindowService(accessory)
213
+ this.removeGarageDoorService(accessory)
214
+ this.removeWindowCoveringService(accessory)
215
+ this.removeStatefulProgrammableSwitchService(accessory)
225
216
  } else if (this.botDeviceType === 'window') {
226
217
  // Set category
227
- accessory.category = this.hap.Categories.WINDOW;
218
+ accessory.category = this.hap.Categories.WINDOW
228
219
  // Initialize Window Service
229
- accessory.context.Window = accessory.context.Window ?? {};
220
+ accessory.context.Window = accessory.context.Window ?? {}
230
221
  this.Window = {
231
222
  Name: accessory.displayName,
232
223
  Service: accessory.getService(this.hap.Service.Window) ?? accessory.addService(this.hap.Service.Window) as Service,
233
- };
234
- accessory.context.Window = this.Window as object;
235
- this.debugLog('Displaying as Window');
224
+ }
225
+ accessory.context.Window = this.Window as object
226
+ this.debugLog('Displaying as Window')
236
227
  // Initialize Window Characteristics
237
- this.Window.Service
238
- .setCharacteristic(this.hap.Characteristic.Name, this.Window.Name)
239
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
240
- .getCharacteristic(this.hap.Characteristic.TargetPosition).setProps({
241
- validValues: [0, 100],
242
- minValue: 0,
243
- maxValue: 100,
244
- minStep: 100,
245
- })
246
- .onSet(this.OnSet.bind(this));
228
+ 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({
229
+ validValues: [0, 100],
230
+ minValue: 0,
231
+ maxValue: 100,
232
+ minStep: 100,
233
+ }).onSet(this.OnSet.bind(this))
247
234
  // Remove other services
248
- this.removeFanService(accessory);
249
- this.removeLockService(accessory);
250
- this.removeDoorService(accessory);
251
- this.removeOutletService(accessory);
252
- this.removeFaucetService(accessory);
253
- this.removeSwitchService(accessory);
254
- this.removeGarageDoorService(accessory);
255
- this.removeWindowCoveringService(accessory);
256
- this.removeStatefulProgrammableSwitchService(accessory);
235
+ this.removeFanService(accessory)
236
+ this.removeLockService(accessory)
237
+ this.removeDoorService(accessory)
238
+ this.removeOutletService(accessory)
239
+ this.removeFaucetService(accessory)
240
+ this.removeSwitchService(accessory)
241
+ this.removeGarageDoorService(accessory)
242
+ this.removeWindowCoveringService(accessory)
243
+ this.removeStatefulProgrammableSwitchService(accessory)
257
244
  } else if (this.botDeviceType === 'windowcovering') {
258
245
  // Set category
259
- accessory.category = this.hap.Categories.WINDOW_COVERING;
246
+ accessory.category = this.hap.Categories.WINDOW_COVERING
260
247
  // Initialize WindowCovering Service
261
- accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
248
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
262
249
  this.WindowCovering = {
263
250
  Name: accessory.displayName,
264
251
  Service: accessory.getService(this.hap.Service.WindowCovering) ?? accessory.addService(this.hap.Service.WindowCovering) as Service,
265
- };
266
- accessory.context.WindowCovering = this.WindowCovering as object;
267
- this.debugLog('Displaying as Window Covering');
252
+ }
253
+ accessory.context.WindowCovering = this.WindowCovering as object
254
+ this.debugLog('Displaying as Window Covering')
268
255
  // Initialize WindowCovering Characteristics
269
- this.WindowCovering.Service
270
- .setCharacteristic(this.hap.Characteristic.Name, this.WindowCovering.Name)
271
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
272
- .getCharacteristic(this.hap.Characteristic.TargetPosition)
273
- .setProps({
274
- validValues: [0, 100],
275
- minValue: 0,
276
- maxValue: 100,
277
- minStep: 100,
278
- })
279
- .onSet(this.OnSet.bind(this));
256
+ 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({
257
+ validValues: [0, 100],
258
+ minValue: 0,
259
+ maxValue: 100,
260
+ minStep: 100,
261
+ }).onSet(this.OnSet.bind(this))
280
262
  // Remove other services
281
- this.removeFanService(accessory);
282
- this.removeLockService(accessory);
283
- this.removeDoorService(accessory);
284
- this.removeOutletService(accessory);
285
- this.removeFaucetService(accessory);
286
- this.removeSwitchService(accessory);
287
- this.removeWindowService(accessory);
288
- this.removeGarageDoorService(accessory);
289
- this.removeStatefulProgrammableSwitchService(accessory);
263
+ this.removeFanService(accessory)
264
+ this.removeLockService(accessory)
265
+ this.removeDoorService(accessory)
266
+ this.removeOutletService(accessory)
267
+ this.removeFaucetService(accessory)
268
+ this.removeSwitchService(accessory)
269
+ this.removeWindowService(accessory)
270
+ this.removeGarageDoorService(accessory)
271
+ this.removeStatefulProgrammableSwitchService(accessory)
290
272
  } else if (this.botDeviceType === 'lock') {
291
273
  // Set category
292
- accessory.category = this.hap.Categories.DOOR_LOCK;
274
+ accessory.category = this.hap.Categories.DOOR_LOCK
293
275
  // Initialize Lock Service
294
- accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
276
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {}
295
277
  this.LockMechanism = {
296
278
  Name: accessory.displayName,
297
279
  Service: accessory.getService(this.hap.Service.LockMechanism) ?? accessory.addService(this.hap.Service.LockMechanism) as Service,
298
- };
299
- accessory.context.LockMechanism = this.LockMechanism as object;
300
- this.debugLog('Displaying as Lock');
280
+ }
281
+ accessory.context.LockMechanism = this.LockMechanism as object
282
+ this.debugLog('Displaying as Lock')
301
283
  // Initialize Lock Characteristics
302
- this.LockMechanism.Service
303
- .setCharacteristic(this.hap.Characteristic.Name, this.LockMechanism.Name)
304
- .setCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
305
- .getCharacteristic(this.hap.Characteristic.LockTargetState)
306
- .onSet(this.OnSet.bind(this));
284
+ 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))
307
285
  // Remove other services
308
- this.removeFanService(accessory);
309
- this.removeDoorService(accessory);
310
- this.removeOutletService(accessory);
311
- this.removeSwitchService(accessory);
312
- this.removeFaucetService(accessory);
313
- this.removeWindowService(accessory);
314
- this.removeGarageDoorService(accessory);
315
- this.removeWindowCoveringService(accessory);
316
- this.removeStatefulProgrammableSwitchService(accessory);
286
+ this.removeFanService(accessory)
287
+ this.removeDoorService(accessory)
288
+ this.removeOutletService(accessory)
289
+ this.removeSwitchService(accessory)
290
+ this.removeFaucetService(accessory)
291
+ this.removeWindowService(accessory)
292
+ this.removeGarageDoorService(accessory)
293
+ this.removeWindowCoveringService(accessory)
294
+ this.removeStatefulProgrammableSwitchService(accessory)
317
295
  } else if (this.botDeviceType === 'faucet') {
318
296
  // Set category
319
- accessory.category = this.hap.Categories.FAUCET;
297
+ accessory.category = this.hap.Categories.FAUCET
320
298
  // Initialize Faucet Service
321
- accessory.context.Faucet = accessory.context.Faucet ?? {};
299
+ accessory.context.Faucet = accessory.context.Faucet ?? {}
322
300
  this.Faucet = {
323
301
  Name: accessory.displayName,
324
302
  Service: accessory.getService(this.hap.Service.Faucet) ?? accessory.addService(this.hap.Service.Faucet) as Service,
325
- };
326
- accessory.context.Faucet = this.Faucet as object;
327
- this.debugLog('Displaying as Faucet');
303
+ }
304
+ accessory.context.Faucet = this.Faucet as object
305
+ this.debugLog('Displaying as Faucet')
328
306
  // Initialize Faucet Characteristics
329
- this.Faucet.Service
330
- .setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name)
331
- .getCharacteristic(this.hap.Characteristic.Active)
332
- .onSet(this.OnSet.bind(this));
307
+ this.Faucet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Faucet.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this))
333
308
  // Remove other services
334
- this.removeFanService(accessory);
335
- this.removeLockService(accessory);
336
- this.removeDoorService(accessory);
337
- this.removeOutletService(accessory);
338
- this.removeSwitchService(accessory);
339
- this.removeWindowService(accessory);
340
- this.removeGarageDoorService(accessory);
341
- this.removeWindowCoveringService(accessory);
342
- this.removeStatefulProgrammableSwitchService(accessory);
309
+ this.removeFanService(accessory)
310
+ this.removeLockService(accessory)
311
+ this.removeDoorService(accessory)
312
+ this.removeOutletService(accessory)
313
+ this.removeSwitchService(accessory)
314
+ this.removeWindowService(accessory)
315
+ this.removeGarageDoorService(accessory)
316
+ this.removeWindowCoveringService(accessory)
317
+ this.removeStatefulProgrammableSwitchService(accessory)
343
318
  } else if (this.botDeviceType === 'fan') {
344
319
  // Set category
345
- accessory.category = this.hap.Categories.FAN;
320
+ accessory.category = this.hap.Categories.FAN
346
321
  // Initialize Fan Service
347
- accessory.context.Fan = accessory.context.Fan ?? {};
322
+ accessory.context.Fan = accessory.context.Fan ?? {}
348
323
  this.Fan = {
349
324
  Name: accessory.displayName,
350
325
  Service: accessory.getService(this.hap.Service.Fanv2) ?? accessory.addService(this.hap.Service.Fanv2) as Service,
351
- };
352
- accessory.context.Fan = this.Fan as object;
353
- this.debugLog('Displaying as Fan');
326
+ }
327
+ accessory.context.Fan = this.Fan as object
328
+ this.debugLog('Displaying as Fan')
354
329
  // Initialize Fan Characteristics
355
- this.Fan.Service
356
- .setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name)
357
- .getCharacteristic(this.hap.Characteristic.Active)
358
- .onSet(this.OnSet.bind(this));
330
+ this.Fan.Service.setCharacteristic(this.hap.Characteristic.Name, this.Fan.Name).getCharacteristic(this.hap.Characteristic.Active).onSet(this.OnSet.bind(this))
359
331
  // Remove other services
360
- this.removeLockService(accessory);
361
- this.removeDoorService(accessory);
362
- this.removeFaucetService(accessory);
363
- this.removeOutletService(accessory);
364
- this.removeSwitchService(accessory);
365
- this.removeWindowService(accessory);
366
- this.removeGarageDoorService(accessory);
367
- this.removeWindowCoveringService(accessory);
368
- this.removeStatefulProgrammableSwitchService(accessory);
332
+ this.removeLockService(accessory)
333
+ this.removeDoorService(accessory)
334
+ this.removeFaucetService(accessory)
335
+ this.removeOutletService(accessory)
336
+ this.removeSwitchService(accessory)
337
+ this.removeWindowService(accessory)
338
+ this.removeGarageDoorService(accessory)
339
+ this.removeWindowCoveringService(accessory)
340
+ this.removeStatefulProgrammableSwitchService(accessory)
369
341
  } else if (this.botDeviceType === 'stateful') {
370
342
  // Set category
371
- accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH;
343
+ accessory.category = this.hap.Categories.PROGRAMMABLE_SWITCH
372
344
  // Initialize StatefulProgrammableSwitch Service
373
- accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
345
+ accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {}
374
346
  this.StatefulProgrammableSwitch = {
375
347
  Name: accessory.displayName,
376
- Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch)
377
- ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
378
- };
379
- accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
380
- this.debugLog('Displaying as Stateful Programmable Switch');
348
+ Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) ?? accessory.addService(this.hap.Service.StatefulProgrammableSwitch) as Service,
349
+ }
350
+ accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object
351
+ this.debugLog('Displaying as Stateful Programmable Switch')
381
352
  // Initialize StatefulProgrammableSwitch Characteristics
382
- this.StatefulProgrammableSwitch.Service
383
- .setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name)
384
- .getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState)
385
- .onSet(this.OnSet.bind(this));
353
+ this.StatefulProgrammableSwitch.Service.setCharacteristic(this.hap.Characteristic.Name, this.StatefulProgrammableSwitch.Name).getCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState).onSet(this.OnSet.bind(this))
386
354
  // Remove other services
387
- this.removeFanService(accessory);
388
- this.removeLockService(accessory);
389
- this.removeDoorService(accessory);
390
- this.removeFaucetService(accessory);
391
- this.removeOutletService(accessory);
392
- this.removeSwitchService(accessory);
393
- this.removeWindowService(accessory);
394
- this.removeGarageDoorService(accessory);
395
- this.removeWindowCoveringService(accessory);
355
+ this.removeFanService(accessory)
356
+ this.removeLockService(accessory)
357
+ this.removeDoorService(accessory)
358
+ this.removeFaucetService(accessory)
359
+ this.removeOutletService(accessory)
360
+ this.removeSwitchService(accessory)
361
+ this.removeWindowService(accessory)
362
+ this.removeGarageDoorService(accessory)
363
+ this.removeWindowCoveringService(accessory)
396
364
  } else if (this.botDeviceType === 'outlet') {
397
365
  // Set category
398
- accessory.category = this.hap.Categories.OUTLET;
366
+ accessory.category = this.hap.Categories.OUTLET
399
367
  // Initialize Switch property
400
- accessory.context.Outlet = accessory.context.Outlet ?? {};
368
+ accessory.context.Outlet = accessory.context.Outlet ?? {}
401
369
  this.Outlet = {
402
370
  Name: accessory.displayName,
403
371
  Service: accessory.getService(this.hap.Service.Outlet) ?? accessory.addService(this.hap.Service.Outlet) as Service,
404
- };
405
- accessory.context.Outlet = this.Outlet as object;
406
- this.debugLog('Displaying as Outlet');
372
+ }
373
+ accessory.context.Outlet = this.Outlet as object
374
+ this.debugLog('Displaying as Outlet')
407
375
  // Initialize Outlet Characteristics
408
- this.Outlet.Service
409
- .setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name)
410
- .getCharacteristic(this.hap.Characteristic.On)
411
- .onSet(this.OnSet.bind(this));
376
+ this.Outlet.Service.setCharacteristic(this.hap.Characteristic.Name, this.Outlet.Name).getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this))
412
377
  // Remove other services
413
- this.removeFanService(accessory);
414
- this.removeLockService(accessory);
415
- this.removeDoorService(accessory);
416
- this.removeFaucetService(accessory);
417
- this.removeSwitchService(accessory);
418
- this.removeWindowService(accessory);
419
- this.removeGarageDoorService(accessory);
420
- this.removeWindowCoveringService(accessory);
421
- this.removeStatefulProgrammableSwitchService(accessory);
378
+ this.removeFanService(accessory)
379
+ this.removeLockService(accessory)
380
+ this.removeDoorService(accessory)
381
+ this.removeFaucetService(accessory)
382
+ this.removeSwitchService(accessory)
383
+ this.removeWindowService(accessory)
384
+ this.removeGarageDoorService(accessory)
385
+ this.removeWindowCoveringService(accessory)
386
+ this.removeStatefulProgrammableSwitchService(accessory)
422
387
  } else {
423
- this.errorLog('Device Type not set');
388
+ this.errorLog('Device Type not set')
424
389
  }
425
390
 
426
391
  // Retrieve initial values and updateHomekit
427
- this.debugLog('Retrieve initial values and update Homekit');
428
- this.refreshStatus();
392
+ try {
393
+ this.debugLog('Retrieve initial values and update Homekit')
394
+ this.refreshStatus()
395
+ } catch (e: any) {
396
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
397
+ }
429
398
 
430
- //regisiter webhook event handler
431
- this.debugLog('Registering Webhook Event Handler');
432
- this.registerWebhook();
399
+ // regisiter webhook event handler if enabled
400
+ try {
401
+ this.debugLog('Registering Webhook Event Handler')
402
+ this.registerWebhook()
403
+ } catch (e: any) {
404
+ this.errorLog(`failed to registerWebhook, Error: ${e}`)
405
+ }
406
+
407
+ // regisiter platform BLE event handler if enabled
408
+ try {
409
+ this.debugLog('Registering Platform BLE Event Handler')
410
+ this.registerPlatformBLE()
411
+ } catch (e: any) {
412
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
413
+ }
433
414
 
434
415
  // Start an update interval
435
416
  interval(this.deviceRefreshRate * 1000)
436
417
  .pipe(skipWhile(() => this.botUpdateInProgress))
437
418
  .subscribe(async () => {
438
- await this.refreshStatus();
439
- });
419
+ await this.refreshStatus()
420
+ })
440
421
 
441
422
  // Watch for Bot change events
442
423
  // We put in a debounce of 1000ms so we don't make duplicate calls
443
424
  this.doBotUpdate
444
425
  .pipe(
445
426
  tap(() => {
446
- this.botUpdateInProgress = true;
427
+ this.botUpdateInProgress = true
447
428
  }),
448
429
  debounceTime(this.devicePushRate * 1000),
449
430
  )
@@ -453,103 +434,102 @@ export class Bot extends deviceBase {
453
434
  interval(this.pushRatePress * 1000)
454
435
  .pipe(take(this.doublePress!))
455
436
  .subscribe(async () => {
456
- await this.pushChanges();
457
- });
437
+ await this.pushChanges()
438
+ })
458
439
  } else {
459
- await this.pushChanges();
440
+ await this.pushChanges()
460
441
  }
461
442
  } catch (e: any) {
462
- await this.apiError(e);
463
- await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
443
+ await this.apiError(e)
444
+ await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
464
445
  }
465
- this.botUpdateInProgress = false;
466
- });
446
+ this.botUpdateInProgress = false
447
+ })
467
448
  }
468
449
 
469
450
  /**
470
451
  * Parse the device status from the SwitchBotBLE API
471
452
  */
472
453
  async BLEparseStatus(): Promise<void> {
473
- await this.debugLog('BLEparseStatus');
474
- await this.debugLog(`(power, battery, deviceMode) = BLE:(${this.serviceData.state}, ${this.serviceData.battery}, ${this.serviceData.mode}),`
475
- + ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
454
+ await this.debugLog('BLEparseStatus')
455
+ 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})`)
476
456
 
477
457
  // BLEmode (true if Switch Mode) | (false if Press Mode)
478
- this.On = this.serviceData.mode ? this.serviceData.state : false;
479
- const mode = this.serviceData.mode ? 'Switch' : 'Press';
480
- await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`);
481
- this.accessory.context.On = this.On;
458
+ this.On = this.serviceData.mode ? this.serviceData.state : false
459
+ const mode = this.serviceData.mode ? 'Switch' : 'Press'
460
+ await this.debugLog(`${mode} Mode, On: ${this.accessory.context.On}`)
461
+ this.accessory.context.On = this.On
482
462
 
483
463
  // BatteryLevel
484
- this.Battery.BatteryLevel = this.serviceData.battery;
485
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
464
+ this.Battery.BatteryLevel = this.serviceData.battery
465
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
486
466
 
487
467
  // StatusLowBattery
488
468
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
489
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
490
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
469
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
470
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
471
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
491
472
  }
492
473
 
493
-
494
474
  /**
495
475
  * Parse the device status from the SwitchBot OpenAPI
496
476
  */
497
477
  async openAPIparseStatus(): Promise<void> {
498
- await this.debugLog('openAPIparseStatus');
499
- await this.debugLog(`(power, battery, deviceMode) = API:(${this.deviceStatus.power}, ${this.deviceStatus.battery}, ${this.botMode}),`
500
- + ` current:(${this.accessory.context.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
478
+ await this.debugLog('openAPIparseStatus')
479
+ 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})`)
501
480
 
502
481
  // On
503
- this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on' ? true : false;
504
- this.accessory.context.On = this.On;
505
- await this.debugLog(`On: ${this.accessory.context.On}`);
482
+ this.On = this.botMode === 'press' ? false : this.deviceStatus.power === 'on'
483
+ this.accessory.context.On = this.On
484
+ await this.debugLog(`On: ${this.accessory.context.On}`)
506
485
 
507
486
  // Battery Level
508
- this.Battery.BatteryLevel = this.deviceStatus.battery;
509
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
487
+ this.Battery.BatteryLevel = this.deviceStatus.battery
488
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
510
489
 
511
490
  // StatusLowBattery
512
491
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
513
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
514
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
492
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
493
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
494
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
515
495
 
516
496
  // Firmware Version
517
497
  if (this.deviceStatus.version) {
518
- const version = this.deviceStatus.version.toString();
519
- this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
520
- const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
498
+ const version = this.deviceStatus.version.toString()
499
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
500
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
521
501
  this.accessory
522
502
  .getService(this.hap.Service.AccessoryInformation)!
523
503
  .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
524
504
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
525
505
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
526
- .updateValue(deviceVersion);
527
- this.accessory.context.version = deviceVersion;
528
- await this.debugLog(`version: ${this.accessory.context.version}`);
506
+ .updateValue(deviceVersion)
507
+ this.accessory.context.version = deviceVersion
508
+ await this.debugLog(`version: ${this.accessory.context.version}`)
529
509
  }
530
510
  }
531
511
 
532
512
  async parseStatusWebhook(): Promise<void> {
533
- await this.debugLog('parseStatusWebhook');
534
- await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery},`
535
- + ` ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`);
513
+ await this.debugLog('parseStatusWebhook')
514
+ await this.debugLog(`(power, battery, deviceMode) = Webhook:(${this.webhookContext.power}, ${this.webhookContext.battery}, ${this.webhookContext.deviceMode}), current:(${this.On}, ${this.Battery.BatteryLevel}, ${this.botMode})`)
536
515
 
537
516
  // On
538
- this.On = this.webhookContext.power === 'on' ? true : false;
539
- await this.debugLog(`On: ${this.On}`);
517
+ this.On = this.webhookContext.power === 'on'
518
+ await this.debugLog(`On: ${this.On}`)
540
519
 
541
520
  // BatteryLevel
542
- this.Battery.BatteryLevel = this.webhookContext.battery;
543
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
521
+ this.Battery.BatteryLevel = this.webhookContext.battery
522
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
544
523
 
545
524
  // StatusLowBattery
546
525
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
547
- ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
548
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
526
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
527
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
528
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
549
529
 
550
530
  // Mode
551
- this.botMode = this.webhookContext.deviceMode;
552
- await this.debugLog(`Mode: ${this.botMode}`);
531
+ this.botMode = this.webhookContext.deviceMode
532
+ await this.debugLog(`Mode: ${this.botMode}`)
553
533
  }
554
534
 
555
535
  /**
@@ -557,233 +537,237 @@ export class Bot extends deviceBase {
557
537
  */
558
538
  async refreshStatus(): Promise<void> {
559
539
  if (!this.device.enableCloudService && this.OpenAPI) {
560
- await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
561
- } else if (this.BLE || this.config.options?.BLE) {
562
- await this.BLERefreshStatus();
540
+ await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
541
+ } else if (this.BLE) {
542
+ await this.BLERefreshStatus()
563
543
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
564
- await this.openAPIRefreshStatus();
544
+ await this.openAPIRefreshStatus()
565
545
  } else {
566
- await this.offlineOff();
567
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
546
+ await this.offlineOff()
547
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
568
548
  }
569
549
  }
570
550
 
571
551
  async BLERefreshStatus(): Promise<void> {
572
- await this.debugLog('BLERefreshStatus');
552
+ await this.debugLog('BLERefreshStatus')
553
+ const switchbot = await this.switchbotBLE()
554
+ if (switchbot === undefined) {
555
+ await this.BLERefreshConnection(switchbot)
556
+ } else {
557
+ // Start to monitor advertisement packets
558
+ (async () => {
559
+ // Start to monitor advertisement packets
560
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData
561
+ // Update HomeKit
562
+ if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
563
+ this.serviceData = serviceData
564
+ await this.BLEparseStatus()
565
+ await this.updateHomeKitCharacteristics()
566
+ } else {
567
+ await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
568
+ await this.BLERefreshConnection(switchbot)
569
+ }
570
+ })()
571
+ }
572
+ }
573
+
574
+ async registerPlatformBLE(): Promise<void> {
575
+ await this.debugLog('registerPlatformBLE')
573
576
  if (this.config.options?.BLE) {
574
- await this.debugLog('is listening to Platform BLE.');
575
- this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
576
- await this.debugLog(`bleMac: ${this.device.bleMac}`);
577
+ await this.debugLog('is listening to Platform BLE.')
578
+ this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
579
+ await this.debugLog(`bleMac: ${this.device.bleMac}`)
577
580
  this.platform.bleEventHandler[this.device.bleMac] = async (context: botServiceData) => {
578
581
  try {
579
- await this.debugLog(`received BLE: ${JSON.stringify(context)}`);
580
- this.serviceData = context;
581
- await this.BLEparseStatus();
582
- await this.updateHomeKitCharacteristics();
582
+ await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
583
+ this.serviceData = context
584
+ await this.BLEparseStatus()
585
+ await this.updateHomeKitCharacteristics()
583
586
  } catch (e: any) {
584
- await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`);
587
+ await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
585
588
  }
586
- };
587
- } else {
588
- await this.debugLog('is using Device BLE Scanning.');
589
- const switchbot = await this.switchbotBLE();
590
- if (switchbot === undefined) {
591
- await this.BLERefreshConnection(switchbot);
592
- } else {
593
- // Start to monitor advertisement packets
594
- (async () => {
595
- // Start to monitor advertisement packets
596
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as botServiceData;
597
- // Update HomeKit
598
- if (serviceData.model === SwitchBotBLEModel.Bot && serviceData.modelName === SwitchBotBLEModelName.Bot) {
599
- this.serviceData = serviceData;
600
- await this.BLEparseStatus();
601
- await this.updateHomeKitCharacteristics();
602
- } else {
603
- await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
604
- await this.BLERefreshConnection(switchbot);
605
- }
606
- })();
607
589
  }
590
+ } else {
591
+ await this.debugLog('is not listening to Platform BLE')
608
592
  }
609
593
  }
610
594
 
611
595
  async openAPIRefreshStatus(): Promise<void> {
612
- await this.debugLog('openAPIRefreshStatus');
596
+ await this.debugLog('openAPIRefreshStatus')
613
597
  try {
614
- const { body, statusCode } = await this.deviceRefreshStatus();
615
- const deviceStatus: any = await body.json();
616
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
598
+ const { body, statusCode } = await this.deviceRefreshStatus()
599
+ const deviceStatus: any = await body.json()
600
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
617
601
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
618
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
619
- this.deviceStatus = deviceStatus.body;
620
- await this.openAPIparseStatus();
621
- await this.updateHomeKitCharacteristics();
602
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
603
+ this.deviceStatus = deviceStatus.body
604
+ await this.openAPIparseStatus()
605
+ await this.updateHomeKitCharacteristics()
622
606
  } else {
623
- await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
624
- await this.debugWarnLog(statusCode, deviceStatus);
607
+ await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
608
+ await this.debugWarnLog(statusCode, deviceStatus)
625
609
  }
626
610
  } catch (e: any) {
627
- await this.apiError(e);
628
- await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
611
+ await this.apiError(e)
612
+ await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
629
613
  }
630
614
  }
631
615
 
632
616
  async registerWebhook() {
633
617
  if (this.device.webhook) {
634
- await this.debugLog('is listening webhook.');
618
+ await this.debugLog('is listening webhook.')
635
619
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: botWebhookContext) => {
636
620
  try {
637
- await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
638
- this.webhookContext = context;
639
- await this.parseStatusWebhook();
640
- await this.updateHomeKitCharacteristics();
621
+ await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
622
+ this.webhookContext = context
623
+ await this.parseStatusWebhook()
624
+ await this.updateHomeKitCharacteristics()
641
625
  } catch (e: any) {
642
- await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
626
+ await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
643
627
  }
644
- };
628
+ }
645
629
  } else {
646
- await this.debugLog('is not listening webhook.');
630
+ await this.debugLog('is not listening webhook.')
647
631
  }
648
632
  }
649
633
 
650
634
  /**
651
635
  * Pushes the requested changes to the SwitchBot API
652
- * deviceType commandType Command command parameter Description
653
- * Bot - "command" "turnOff" "default" = set to OFF state
654
- * Bot - "command" "turnOn" "default" = set to ON state
655
- * Bot - "command" "press" "default" = trigger press
636
+ * deviceType commandType Command command parameter Description
637
+ * Bot "command" "turnOff" "default" = set to OFF state
638
+ * Bot "command" "turnOn" "default" = set to ON state
639
+ * Bot "command" "press" "default" = trigger press
656
640
  */
657
641
  async pushChanges(): Promise<void> {
658
642
  if (!this.device.enableCloudService && this.OpenAPI) {
659
- await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
643
+ await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
660
644
  } else if (this.BLE) {
661
- await this.BLEpushChanges();
645
+ await this.BLEpushChanges()
662
646
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
663
- await this.openAPIpushChanges();
647
+ await this.openAPIpushChanges()
664
648
  } else {
665
- await this.offlineOff();
666
- await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
649
+ await this.offlineOff()
650
+ await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`)
667
651
  }
668
652
  // Refresh the status from the API
669
653
  interval(15000)
670
654
  .pipe(skipWhile(() => this.botUpdateInProgress))
671
655
  .pipe(take(1))
672
656
  .subscribe(async () => {
673
- await this.refreshStatus();
674
- });
657
+ await this.refreshStatus()
658
+ })
675
659
  }
676
660
 
677
661
  async BLEpushChanges(): Promise<void> {
678
- await this.debugLog('BLEpushChanges');
662
+ await this.debugLog('BLEpushChanges')
679
663
  if (this.On !== this.accessory.context.On || this.allowPush) {
680
- await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
681
- const switchbot = await this.platform.connectBLE(this.accessory, this.device);
682
- await this.convertBLEAddress();
683
- //if (switchbot !== false) {
684
- await this.debugLog(`Bot Mode: ${this.botMode}`);
664
+ await this.debugLog(`BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`)
665
+ const switchbot = await this.platform.connectBLE(this.accessory, this.device)
666
+ await this.convertBLEAddress()
667
+ // if (switchbot !== false) {
668
+ await this.debugLog(`Bot Mode: ${this.botMode}`)
685
669
  if (this.botMode === 'press') {
686
670
  switchbot
687
671
  .discover({ model: 'H', quick: true, id: this.device.bleMac })
688
672
  .then(async (device_list: { press: (arg0: { id: string | undefined }) => any }[]) => {
689
- await this.infoLog(`On: ${this.On}`);
690
- return await device_list[0].press({ id: this.device.bleMac });
673
+ await this.infoLog(`On: ${this.On}`)
674
+ return await device_list[0].press({ id: this.device.bleMac })
691
675
  })
692
676
  .then(async () => {
693
- await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
694
- await this.updateHomeKitCharacteristics();
677
+ await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
678
+ await this.updateHomeKitCharacteristics()
695
679
  setTimeout(async () => {
696
- this.On = false;
697
- await this.updateHomeKitCharacteristics();
698
- this.debugLog(`On: ${this.On}, Switch Timeout`);
699
- }, 500);
680
+ this.On = false
681
+ await this.updateHomeKitCharacteristics()
682
+ this.debugLog(`On: ${this.On}, Switch Timeout`)
683
+ }, 500)
700
684
  })
701
685
  .catch(async (e: any) => {
702
- await this.apiError(e);
703
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
704
- await this.BLEPushConnection();
705
- });
686
+ await this.apiError(e)
687
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
688
+ await this.BLEPushConnection()
689
+ })
706
690
  } else if (this.botMode === 'switch') {
707
691
  switchbot
708
692
  .discover({ model: this.device.bleModel, quick: true, id: this.device.bleMac })
709
693
  .then(async (device_list: any) => {
710
- this.infoLog(`On: ${this.On}`);
694
+ this.infoLog(`On: ${this.On}`)
711
695
  return await this.retryBLE({
712
696
  max: await this.maxRetryBLE(),
713
697
  fn: async () => {
714
698
  if (this.On) {
715
- return await device_list[0].turnOn({ id: this.device.bleMac });
699
+ return await device_list[0].turnOn({ id: this.device.bleMac })
716
700
  } else {
717
- return await device_list[0].turnOff({ id: this.device.bleMac });
701
+ return await device_list[0].turnOff({ id: this.device.bleMac })
718
702
  }
719
703
  },
720
- });
704
+ })
721
705
  })
722
706
  .then(async () => {
723
- await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`);
724
- await this.updateHomeKitCharacteristics();
707
+ await this.successLog(`On: ${this.On} sent over SwitchBot BLE, sent successfully`)
708
+ await this.updateHomeKitCharacteristics()
725
709
  })
726
710
  .catch(async (e: any) => {
727
- await this.apiError(e);
728
- await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
729
- await this.BLEPushConnection();
730
- });
711
+ await this.apiError(e)
712
+ await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
713
+ await this.BLEPushConnection()
714
+ })
731
715
  } else {
732
- await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`);
716
+ await this.errorLog(`Device Parameters not set for this Bot, please check the device configuration. Bot Mode: ${this.botMode}`)
733
717
  }
734
718
  } else {
735
- await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
719
+ await this.debugLog(`No Changes (BLEpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
736
720
  }
737
721
  }
738
722
 
739
723
  async openAPIpushChanges(): Promise<void> {
740
- await this.debugLog('openAPIpushChanges');
724
+ await this.debugLog('openAPIpushChanges')
741
725
  if (this.multiPressCount > 0) {
742
- await this.debugLog(`${this.multiPressCount} request(s) queued.`);
726
+ await this.debugLog(`${this.multiPressCount} request(s) queued.`)
743
727
  }
744
728
  if (this.On !== this.accessory.context.On || this.allowPush || this.multiPressCount > 0) {
745
- let command = '';
729
+ let command = ''
746
730
  if (this.botMode === 'switch') {
747
- command = this.On ? 'turnOn' : 'turnOff';
748
- await this.debugLog(`Switch Mode, Command: ${command}`);
731
+ command = this.On ? 'turnOn' : 'turnOff'
732
+ await this.debugLog(`Switch Mode, Command: ${command}`)
749
733
  } else if (this.botMode === 'press' || this.botMode === 'multipress') {
750
- command = 'press';
751
- await this.debugLog('Press Mode');
752
- this.On = false;
734
+ command = 'press'
735
+ await this.debugLog('Press Mode')
736
+ this.On = false
753
737
  } else {
754
- throw new Error('Device Parameters not set for this Bot.');
738
+ throw new Error('Device Parameters not set for this Bot.')
755
739
  }
756
740
  const bodyChange = JSON.stringify({
757
741
  command: `${command}`,
758
742
  parameter: 'default',
759
743
  commandType: 'command',
760
- });
761
- this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`);
744
+ })
745
+ this.debugLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
762
746
  try {
763
- const { body, statusCode } = await this.pushChangeRequest(bodyChange);
764
- const deviceStatus: any = await body.json();
765
- await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
747
+ const { body, statusCode } = await this.pushChangeRequest(bodyChange)
748
+ const deviceStatus: any = await body.json()
749
+ await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
766
750
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
767
- await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
768
- await this.updateHomeKitCharacteristics();
751
+ await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
752
+ await this.updateHomeKitCharacteristics()
769
753
  } else {
770
- await this.statusCode(statusCode);
771
- await this.statusCode(deviceStatus.statusCode);
754
+ await this.statusCode(statusCode)
755
+ await this.statusCode(deviceStatus.statusCode)
772
756
  }
773
757
  if (this.device.bot?.mode === 'multipress') {
774
- this.multiPressCount--;
758
+ this.multiPressCount--
775
759
  if (this.multiPressCount > 0) {
776
- await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
777
- this.On = true;
778
- await this.openAPIpushChanges();
760
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`)
761
+ this.On = true
762
+ await this.openAPIpushChanges()
779
763
  }
780
764
  }
781
765
  } catch (e: any) {
782
- await this.apiError(e);
783
- await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
766
+ await this.apiError(e)
767
+ await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
784
768
  }
785
769
  } else {
786
- await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`);
770
+ await this.debugLog(`No Changes (openAPIpushChanges), On: ${this.On} OnCached: ${this.accessory.context.On}`)
787
771
  }
788
772
  }
789
773
 
@@ -791,403 +775,427 @@ export class Bot extends deviceBase {
791
775
  * Handle requests to set the "On" characteristic
792
776
  */
793
777
  async OnSet(value: CharacteristicValue): Promise<void> {
794
- if (this.botDeviceType === 'switch') {
795
- if (this.Switch) {
796
- await this.debugLog(`Set On: ${value}`);
797
- this.On = value === false ? false : true;
798
- }
799
- } else if (this.botDeviceType === 'garagedoor') {
800
- if (this.GarageDoor) {
801
- await this.debugLog(`Set TargetDoorState: ${value}`);
802
- this.On = value === this.hap.Characteristic.TargetDoorState.CLOSED ? false : true;
803
- }
804
- } else if (this.botDeviceType === 'door') {
805
- if (this.Door) {
806
- await this.debugLog(`Set TargetPosition: ${value}`);
807
- this.On = value === 0 ? false : true;
808
- }
809
- } else if (this.botDeviceType === 'window') {
810
- if (this.Window) {
811
- await this.debugLog(`Set TargetPosition: ${value}`);
812
- this.On = value === 0 ? false : true;
813
- }
814
- } else if (this.botDeviceType === 'windowcovering') {
815
- if (this.WindowCovering) {
816
- await this.debugLog(`Set TargetPosition: ${value}`);
817
- this.On = value === 0 ? false : true;
818
- }
819
- } else if (this.botDeviceType === 'lock') {
820
- if (this.LockMechanism) {
821
- await this.debugLog(`Set LockTargetState: ${value}`);
822
- this.On = value === this.hap.Characteristic.LockTargetState.SECURED ? false : true;
823
- }
824
- } else if (this.botDeviceType === 'faucet') {
825
- if (this.Faucet) {
826
- await this.debugLog(`Set Active: ${value}`);
827
- this.On = value === this.hap.Characteristic.Active.INACTIVE ? false : true;
828
- }
829
- } else if (this.botDeviceType === 'stateful') {
830
- if (this.StatefulProgrammableSwitch) {
831
- await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`);
832
- this.On = value === 0 ? false : true;
833
- }
778
+ if (this.On === undefined) {
779
+ this.On = false
780
+ this.accessory.context.On = this.On
834
781
  } else {
835
- if (this.Outlet) {
836
- await this.debugLog(`Set On: ${value}`);
837
- this.On = value === false ? false : true;
838
- }
782
+ this.On = this.accessory.context.On
839
783
  }
840
- if (this.device.bot?.mode === 'multipress') {
841
- if (this.On === true) {
842
- this.multiPressCount++;
843
- await this.debugLog(`multiPressCount: ${this.multiPressCount}`);
844
- }
784
+
785
+ const deviceTypeActions: { [key: string]: () => Promise<void> } = {
786
+ switch: async () => {
787
+ if (this.Switch) {
788
+ await this.debugLog(`Set On: ${value}`)
789
+ this.On = value !== false
790
+ }
791
+ },
792
+ garagedoor: async () => {
793
+ if (this.GarageDoor) {
794
+ await this.debugLog(`Set TargetDoorState: ${value}`)
795
+ this.On = value !== this.hap.Characteristic.TargetDoorState.CLOSED
796
+ }
797
+ },
798
+ door: async () => {
799
+ if (this.Door) {
800
+ await this.debugLog(`Set TargetPosition: ${value}`)
801
+ this.On = value !== 0
802
+ }
803
+ },
804
+ window: async () => {
805
+ if (this.Window) {
806
+ await this.debugLog(`Set TargetPosition: ${value}`)
807
+ this.On = value !== 0
808
+ }
809
+ },
810
+ windowcovering: async () => {
811
+ if (this.WindowCovering) {
812
+ await this.debugLog(`Set TargetPosition: ${value}`)
813
+ this.On = value !== 0
814
+ }
815
+ },
816
+ lock: async () => {
817
+ if (this.LockMechanism) {
818
+ await this.debugLog(`Set LockTargetState: ${value}`)
819
+ this.On = value !== this.hap.Characteristic.LockTargetState.SECURED
820
+ }
821
+ },
822
+ faucet: async () => {
823
+ if (this.Faucet) {
824
+ await this.debugLog(`Set Active: ${value}`)
825
+ this.On = value !== this.hap.Characteristic.Active.INACTIVE
826
+ }
827
+ },
828
+ stateful: async () => {
829
+ if (this.StatefulProgrammableSwitch) {
830
+ await this.debugLog(`Set ProgrammableSwitchOutputState: ${value}`)
831
+ this.On = value !== 0
832
+ }
833
+ },
834
+ default: async () => {
835
+ if (this.Outlet) {
836
+ await this.debugLog(`Set On: ${value}`)
837
+ this.On = value !== false
838
+ }
839
+ if (this.device.bot?.mode === 'multipress' && this.On) {
840
+ this.multiPressCount++
841
+ await this.debugLog(`multiPressCount: ${this.multiPressCount}`)
842
+ }
843
+ },
845
844
  }
846
- this.doBotUpdate.next();
845
+
846
+ const action = deviceTypeActions[this.botDeviceType] || deviceTypeActions.default
847
+ await action()
848
+
849
+ this.accessory.context.On = this.On
850
+ this.doBotUpdate.next()
847
851
  }
848
852
 
849
853
  /**
850
854
  * Updates the status for each of the HomeKit Characteristics
851
855
  */
852
856
  async updateHomeKitCharacteristics(): Promise<void> {
853
- await this.debugLog('updateHomeKitCharacteristics');
857
+ await this.debugLog('updateHomeKitCharacteristics')
854
858
  // BatteryLevel
855
859
  if (this.Battery.BatteryLevel === undefined) {
856
- await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
860
+ await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
857
861
  } else {
858
- this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
859
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
860
- await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
862
+ this.accessory.context.BatteryLevel = this.Battery.BatteryLevel
863
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel)
864
+ await this.debugLog(`updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`)
861
865
  }
862
866
  // StatusLowBattery
863
867
  if (this.Battery.StatusLowBattery === undefined) {
864
- await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
868
+ await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
865
869
  } else {
866
- this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
867
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
868
- await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`);
870
+ this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery
871
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery)
872
+ await this.debugLog(`updateCharacteristic StatusLowBattery: ${this.Battery.StatusLowBattery}`)
869
873
  }
870
874
  // State
871
875
  if (this.botDeviceType === 'switch' && this.Switch) {
872
876
  if (this.On === undefined) {
873
- await this.debugLog(`On: ${this.On}`);
877
+ await this.debugLog(`On: ${this.On}`)
874
878
  } else {
875
- this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
876
- await this.debugLog(`updateCharacteristic On: ${this.On}`);
879
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, this.On)
880
+ await this.debugLog(`updateCharacteristic On: ${this.On}`)
877
881
  }
878
882
  } else if (this.botDeviceType === 'garagedoor' && this.GarageDoor) {
879
883
  if (this.On === undefined) {
880
- await this.debugLog(`On: ${this.On}`);
884
+ await this.debugLog(`On: ${this.On}`)
881
885
  } else {
882
886
  if (this.On) {
883
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN);
884
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN);
885
- await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`);
887
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.OPEN)
888
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.OPEN)
889
+ await this.debugLog(`updateCharacteristic TargetDoorState: Open, CurrentDoorState: Open (${this.On})`)
886
890
  } else {
887
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
888
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
889
- await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`);
891
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED)
892
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED)
893
+ await this.debugLog(`updateCharacteristicc TargetDoorState: Closed, CurrentDoorState: Closed (${this.On})`)
890
894
  }
891
895
  }
892
- await this.debugLog(`Garage Door On: ${this.On}`);
896
+ await this.debugLog(`Garage Door On: ${this.On}`)
893
897
  } else if (this.botDeviceType === 'door' && this.Door) {
894
898
  if (this.On === undefined) {
895
- await this.debugLog(`On: ${this.On}`);
899
+ await this.debugLog(`On: ${this.On}`)
896
900
  } else {
897
901
  if (this.On) {
898
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
899
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
900
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
901
- await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
902
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
903
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
904
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
905
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
902
906
  } else {
903
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
904
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
905
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
906
- await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
907
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
908
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
909
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
910
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
907
911
  }
908
912
  }
909
- await this.debugLog(`Door On: ${this.On}`);
913
+ await this.debugLog(`Door On: ${this.On}`)
910
914
  } else if (this.botDeviceType === 'window' && this.Window) {
911
915
  if (this.On === undefined) {
912
- await this.debugLog(`On: ${this.On}`);
916
+ await this.debugLog(`On: ${this.On}`)
913
917
  } else {
914
918
  if (this.On) {
915
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
916
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
917
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
918
- await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
919
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
920
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
921
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
922
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
919
923
  } else {
920
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
921
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
922
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
923
- await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
924
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
925
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
926
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
927
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
924
928
  }
925
929
  }
926
- await this.debugLog(`Window On: ${this.On}`);
930
+ await this.debugLog(`Window On: ${this.On}`)
927
931
  } else if (this.botDeviceType === 'windowcovering' && this.WindowCovering) {
928
932
  if (this.On === undefined) {
929
- await this.debugLog(`On: ${this.On}`);
933
+ await this.debugLog(`On: ${this.On}`)
930
934
  } else {
931
935
  if (this.On) {
932
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100);
933
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100);
934
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
935
- await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`);
936
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 100)
937
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 100)
938
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
939
+ await this.debugLog(`updateCharacteristicc TargetPosition: 100, CurrentPosition: 100 (${this.On})`)
936
940
  } else {
937
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
938
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
939
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
940
- await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`);
941
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
942
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
943
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
944
+ await this.debugLog(`updateCharacteristicc TargetPosition: 0, CurrentPosition: 0 (${this.On})`)
941
945
  }
942
946
  }
943
- await this.debugLog(`Window Covering On: ${this.On}`);
947
+ await this.debugLog(`Window Covering On: ${this.On}`)
944
948
  } else if (this.botDeviceType === 'lock' && this.LockMechanism) {
945
949
  if (this.On === undefined) {
946
- await this.debugLog(`On: ${this.On}`);
950
+ await this.debugLog(`On: ${this.On}`)
947
951
  } else {
948
952
  if (this.On) {
949
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
950
- this.hap.Characteristic.LockTargetState.UNSECURED);
951
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
952
- this.hap.Characteristic.LockCurrentState.UNSECURED);
953
- await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`);
953
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.UNSECURED)
954
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.UNSECURED)
955
+ await this.debugLog(`updateCharacteristicc LockTargetState: UNSECURED, LockCurrentState: UNSECURED (${this.On})`)
954
956
  } else {
955
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState,
956
- this.hap.Characteristic.LockTargetState.SECURED);
957
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState,
958
- this.hap.Characteristic.LockCurrentState.SECURED);
959
- await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`);
957
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED)
958
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED)
959
+ await this.debugLog(`updateCharacteristic LockTargetState: SECURED, LockCurrentState: SECURED (${this.On})`)
960
960
  }
961
961
  }
962
- await this.debugLog(`Lock On: ${this.On}`);
962
+ await this.debugLog(`Lock On: ${this.On}`)
963
963
  } else if (this.botDeviceType === 'faucet' && this.Faucet) {
964
964
  if (this.On === undefined) {
965
- await this.debugLog(`On: ${this.On}`);
965
+ await this.debugLog(`On: ${this.On}`)
966
966
  } else {
967
967
  if (this.On) {
968
- this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
969
- await this.debugLog(`updateCharacteristic Active: ${this.On}`);
968
+ this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
969
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`)
970
970
  } else {
971
- this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
972
- await this.debugLog(`updateCharacteristic Active: ${this.On}`);
971
+ this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
972
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`)
973
973
  }
974
974
  }
975
- await this.debugLog(`Faucet On: ${this.On}`);
975
+ await this.debugLog(`Faucet On: ${this.On}`)
976
976
  } else if (this.botDeviceType === 'fan' && this.Fan) {
977
977
  if (this.On === undefined) {
978
- await this.debugLog(`On: ${this.On}`);
978
+ await this.debugLog(`On: ${this.On}`)
979
979
  } else {
980
980
  if (this.On) {
981
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE);
982
- await this.debugLog(`updateCharacteristic Active: ${this.On}`);
981
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.ACTIVE)
982
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`)
983
983
  } else {
984
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
985
- await this.debugLog(`updateCharacteristic Active: ${this.On}`);
984
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
985
+ await this.debugLog(`updateCharacteristic Active: ${this.On}`)
986
986
  }
987
987
  }
988
- await this.debugLog(`Fan On: ${this.On}`);
988
+ await this.debugLog(`Fan On: ${this.On}`)
989
989
  } else if (this.botDeviceType === 'stateful' && this.StatefulProgrammableSwitch) {
990
990
  if (this.On === undefined) {
991
- await this.debugLog(`On: ${this.On}`);
991
+ await this.debugLog(`On: ${this.On}`)
992
992
  } else {
993
993
  if (this.On) {
994
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
995
- this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
996
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1);
997
- await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
994
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS)
995
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 1)
996
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`)
998
997
  } else {
999
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1000
- this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1001
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
1002
- await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`);
998
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS)
999
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0)
1000
+ await this.debugLog(`updateCharacteristic ProgrammableSwitchEvent: ProgrammableSwitchOutputState: (${this.On})`)
1003
1001
  }
1004
1002
  }
1005
- await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`);
1003
+ await this.debugLog(`StatefulProgrammableSwitch On: ${this.On}`)
1006
1004
  } else if (this.botDeviceType === 'outlet' && this.Outlet) {
1007
1005
  if (this.On === undefined) {
1008
- await this.debugLog(`On: ${this.On}`);
1006
+ await this.debugLog(`On: ${this.On}`)
1009
1007
  } else {
1010
- this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On);
1011
- await this.debugLog(`updateCharacteristic On: ${this.On}`);
1008
+ this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, this.On)
1009
+ await this.debugLog(`updateCharacteristic On: ${this.On}`)
1012
1010
  }
1013
1011
  } else {
1014
- await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`);
1012
+ await this.errorLog(`botDeviceType: ${this.botDeviceType}, On: ${this.On}`)
1015
1013
  }
1016
1014
  }
1017
1015
 
1018
1016
  async removeOutletService(accessory: PlatformAccessory): Promise<void> {
1019
1017
  // If outletService still present, then remove first
1020
- accessory.context.Outlet = accessory.context.Outlet ?? {};
1018
+ accessory.context.Outlet = accessory.context.Outlet ?? {}
1021
1019
  this.Outlet = {
1022
1020
  Name: accessory.context.Outlet.Name ?? accessory.displayName,
1023
1021
  Service: accessory.getService(this.hap.Service.Outlet) as Service,
1024
- };
1025
- accessory.context.Outlet = this.Outlet as object;
1026
- await this.warnLog('Removing any leftover Outlet Service');
1027
- accessory.removeService(this.Outlet.Service);
1022
+ }
1023
+ accessory.context.Outlet = this.Outlet as object
1024
+ await this.debugWarnLog('Removing any leftover Outlet Service')
1025
+ accessory.removeService(this.Outlet.Service)
1028
1026
  }
1029
1027
 
1030
1028
  async removeGarageDoorService(accessory: PlatformAccessory): Promise<void> {
1031
1029
  // If garageDoorService still present, then remove first
1032
- accessory.context.GarageDoor = accessory.context.GarageDoor ?? {};
1030
+ accessory.context.GarageDoor = accessory.context.GarageDoor ?? {}
1033
1031
  this.GarageDoor = {
1034
1032
  Name: accessory.context.GarageDoor.Name ?? accessory.displayName,
1035
1033
  Service: accessory.getService(this.hap.Service.GarageDoorOpener) as Service,
1036
- };
1037
- accessory.context.GarageDoor = this.GarageDoor as object;
1038
- await this.warnLog('Removing any leftover Garage Door Service');
1039
- accessory.removeService(this.GarageDoor.Service);
1034
+ }
1035
+ accessory.context.GarageDoor = this.GarageDoor as object
1036
+ await this.debugWarnLog('Removing any leftover Garage Door Service')
1037
+ accessory.removeService(this.GarageDoor.Service)
1040
1038
  }
1041
1039
 
1042
1040
  async removeDoorService(accessory: PlatformAccessory): Promise<void> {
1043
1041
  // If doorService still present, then remove first
1044
- accessory.context.Door = accessory.context.Door ?? {};
1042
+ accessory.context.Door = accessory.context.Door ?? {}
1045
1043
  this.Door = {
1046
1044
  Name: accessory.context.Door.Name ?? accessory.displayName,
1047
1045
  Service: accessory.getService(this.hap.Service.Door) as Service,
1048
- };
1049
- accessory.context.Door = this.Door as object;
1050
- await this.warnLog('Removing any leftover Door Service');
1051
- accessory.removeService(this.Door.Service);
1046
+ }
1047
+ accessory.context.Door = this.Door as object
1048
+ await this.debugWarnLog('Removing any leftover Door Service')
1049
+ accessory.removeService(this.Door.Service)
1052
1050
  }
1053
1051
 
1054
1052
  async removeLockService(accessory: PlatformAccessory): Promise<void> {
1055
1053
  // If lockService still present, then remove first
1056
- accessory.context.LockMechanism = accessory.context.LockMechanism ?? {};
1054
+ accessory.context.LockMechanism = accessory.context.LockMechanism ?? {}
1057
1055
  this.LockMechanism = {
1058
1056
  Name: accessory.context.LockMechanism.Name ?? accessory.displayName,
1059
1057
  Service: accessory.getService(this.hap.Service.LockMechanism) as Service,
1060
- };
1061
- accessory.context.LockMechanism = this.LockMechanism as object;
1062
- this.warnLog('Removing any leftover Lock Service');
1063
- accessory.removeService(this.LockMechanism.Service);
1058
+ }
1059
+ accessory.context.LockMechanism = this.LockMechanism as object
1060
+ await this.debugWarnLog('Removing any leftover Lock Service')
1061
+ accessory.removeService(this.LockMechanism.Service)
1064
1062
  }
1065
1063
 
1066
1064
  async removeFaucetService(accessory: PlatformAccessory): Promise<void> {
1067
1065
  // If faucetService still present, then remove first
1068
- accessory.context.Faucet = accessory.context.Faucet ?? {};
1066
+ accessory.context.Faucet = accessory.context.Faucet ?? {}
1069
1067
  this.Faucet = {
1070
1068
  Name: accessory.context.Faucet.Name ?? accessory.displayName,
1071
1069
  Service: accessory.getService(this.hap.Service.Valve) as Service,
1072
- };
1073
- accessory.context.Faucet = this.Faucet as object;
1074
- await this.warnLog('Removing any leftover Faucet Service');
1075
- accessory.removeService(this.Faucet.Service);
1070
+ }
1071
+ accessory.context.Faucet = this.Faucet as object
1072
+ await this.debugWarnLog('Removing any leftover Faucet Service')
1073
+ accessory.removeService(this.Faucet.Service)
1076
1074
  }
1077
1075
 
1078
1076
  async removeFanService(accessory: PlatformAccessory): Promise<void> {
1079
1077
  // If fanService still present, then remove first
1080
- accessory.context.Fan = accessory.context.Fan ?? {};
1078
+ accessory.context.Fan = accessory.context.Fan ?? {}
1081
1079
  this.Fan = {
1082
1080
  Name: accessory.context.Fan.Name ?? accessory.displayName,
1083
1081
  Service: accessory.getService(this.hap.Service.Fan) as Service,
1084
- };
1085
- accessory.context.Fan = this.Fan as object;
1086
- this.warnLog('Removing any leftover Fan Service');
1087
- accessory.removeService(this.Fan.Service);
1082
+ }
1083
+ accessory.context.Fan = this.Fan as object
1084
+ await this.debugWarnLog('Removing any leftover Fan Service')
1085
+ accessory.removeService(this.Fan.Service)
1088
1086
  }
1089
1087
 
1090
1088
  async removeWindowService(accessory: PlatformAccessory): Promise<void> {
1091
1089
  // If windowService still present, then remove first
1092
- accessory.context.Window = accessory.context.Window ?? {};
1090
+ accessory.context.Window = accessory.context.Window ?? {}
1093
1091
  this.Window = {
1094
1092
  Name: accessory.context.Window.Name ?? accessory.displayName,
1095
1093
  Service: accessory.getService(this.hap.Service.Window) as Service,
1096
- };
1097
- accessory.context.Window = this.Window as object;
1098
- await this.warnLog('Removing any leftover Window Service');
1099
- accessory.removeService(this.Window.Service);
1094
+ }
1095
+ accessory.context.Window = this.Window as object
1096
+ await this.debugWarnLog('Removing any leftover Window Service')
1097
+ accessory.removeService(this.Window.Service)
1100
1098
  }
1101
1099
 
1102
1100
  async removeWindowCoveringService(accessory: PlatformAccessory): Promise<void> {
1103
1101
  // If windowCoveringService still present, then remove first
1104
- accessory.context.WindowCovering = accessory.context.WindowCovering ?? {};
1102
+ accessory.context.WindowCovering = accessory.context.WindowCovering ?? {}
1105
1103
  this.WindowCovering = {
1106
1104
  Name: accessory.context.WindowCovering.Name ?? accessory.displayName,
1107
1105
  Service: accessory.getService(this.hap.Service.WindowCovering) as Service,
1108
- };
1109
- accessory.context.WindowCovering = this.WindowCovering as object;
1110
- await this.warnLog('Removing any leftover Window Covering Service');
1111
- accessory.removeService(this.WindowCovering.Service);
1106
+ }
1107
+ accessory.context.WindowCovering = this.WindowCovering as object
1108
+ await this.debugWarnLog('Removing any leftover Window Covering Service')
1109
+ accessory.removeService(this.WindowCovering.Service)
1112
1110
  }
1113
1111
 
1114
1112
  async removeStatefulProgrammableSwitchService(accessory: PlatformAccessory): Promise<void> {
1115
1113
  // If statefulProgrammableSwitchService still present, then remove first
1116
- accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {};
1114
+ accessory.context.StatefulProgrammableSwitch = accessory.context.StatefulProgrammableSwitch ?? {}
1117
1115
  this.StatefulProgrammableSwitch = {
1118
1116
  Name: accessory.context.StatefulProgrammableSwitch.Name ?? accessory.displayName,
1119
1117
  Service: accessory.getService(this.hap.Service.StatefulProgrammableSwitch) as Service,
1120
- };
1121
- accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object;
1122
- await this.warnLog('Removing any leftover Stateful Programmable Switch Service');
1123
- accessory.removeService(this.StatefulProgrammableSwitch.Service);
1118
+ }
1119
+ accessory.context.StatefulProgrammableSwitch = this.StatefulProgrammableSwitch as object
1120
+ await this.debugWarnLog('Removing any leftover Stateful Programmable Switch Service')
1121
+ accessory.removeService(this.StatefulProgrammableSwitch.Service)
1124
1122
  }
1125
1123
 
1126
1124
  async removeSwitchService(accessory: PlatformAccessory): Promise<void> {
1127
1125
  // If switchService still present, then remove first
1128
- accessory.context.Switch = accessory.context.Switch ?? {};
1126
+ accessory.context.Switch = accessory.context.Switch ?? {}
1129
1127
  this.Switch = {
1130
1128
  Name: accessory.context.Switch.Name ?? accessory.displayName,
1131
1129
  Service: accessory.getService(this.hap.Service.Switch) as Service,
1132
- };
1133
- accessory.context.Switch = this.Switch as object;
1134
- await this.warnLog('Removing any leftover Switch Service');
1135
- accessory.removeService(this.Switch.Service);
1130
+ }
1131
+ accessory.context.Switch = this.Switch as object
1132
+ await this.debugWarnLog('Removing any leftover Switch Service')
1133
+ accessory.removeService(this.Switch.Service)
1136
1134
  }
1137
1135
 
1138
1136
  async getBotConfigSettings(device: device & devicesConfig) {
1139
- //Bot Device Type
1140
- this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType ? this.accessory.context.botDeviceType
1141
- : device.bot?.deviceType ?? 'outlet';
1142
- const botDeviceType = this.accessory.context.botDeviceType ? `Using Device Type: ${this.botDeviceType}, from Accessory Cache.`
1143
- : device.bot?.deviceType ? `Using Device Type: ${this.botDeviceType}`
1144
- : `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`;
1145
- await this.debugWarnLog(botDeviceType);
1146
- this.accessory.context.botDeviceType = this.botDeviceType;
1137
+ // Bot Device Type
1138
+ this.botDeviceType = this.accessory.context.botDeviceType === device.bot?.deviceType
1139
+ ? this.accessory.context.botDeviceType
1140
+ : device.bot?.deviceType ?? 'outlet'
1141
+ const botDeviceType = this.accessory.context.botDeviceType
1142
+ ? `Using Device Type: ${this.botDeviceType}, from Accessory Cache.`
1143
+ : device.bot?.deviceType
1144
+ ? `Using Device Type: ${this.botDeviceType}`
1145
+ : `No Device Type Set, deviceType: ${this.device.bot?.deviceType}, Using default deviceType: ${this.botDeviceType}`
1146
+ await this.debugWarnLog(botDeviceType)
1147
+ this.accessory.context.botDeviceType = this.botDeviceType
1147
1148
  // Bot Mode
1148
- this.botMode = this.accessory.context.botMode ?? device.bot?.mode ?? 'switch';
1149
- const botMode = this.accessory.context.botMode ? `Using Bot Mode: ${this.botMode}, from Accessory Cache.`
1150
- : device.bot?.mode ? `Using Bot Mode: ${this.botMode}` : `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`;
1151
- await this.debugWarnLog(botMode);
1152
- this.accessory.context.botMode = this.botMode;
1149
+ this.botMode = this.accessory.context.botMode ?? device.bot?.mode ?? 'switch'
1150
+ const botMode = this.accessory.context.botMode
1151
+ ? `Using Bot Mode: ${this.botMode}, from Accessory Cache.`
1152
+ : device.bot?.mode ? `Using Bot Mode: ${this.botMode}` : `No Bot Mode Set, Using default Bot Mode: ${this.botMode}`
1153
+ await this.debugWarnLog(botMode)
1154
+ this.accessory.context.botMode = this.botMode
1153
1155
  // Bot Double Press
1154
- this.doublePress = this.accessory.context.doublePress ?? device.bot?.doublePress ?? 1;
1155
- const doublePress = this.accessory.context.doublePress ? `Using Double Press: ${this.doublePress}, from Accessory Cache.`
1156
- : device.bot?.doublePress ? `Using Double Press: ${this.doublePress}`
1157
- : `No Double Press Set, Using default Double Press: ${this.doublePress}`;
1158
- await this.debugWarnLog(doublePress);
1159
- this.accessory.context.doublePress = this.doublePress;
1156
+ this.doublePress = this.accessory.context.doublePress ?? device.bot?.doublePress ?? 1
1157
+ const doublePress = this.accessory.context.doublePress
1158
+ ? `Using Double Press: ${this.doublePress}, from Accessory Cache.`
1159
+ : device.bot?.doublePress
1160
+ ? `Using Double Press: ${this.doublePress}`
1161
+ : `No Double Press Set, Using default Double Press: ${this.doublePress}`
1162
+ await this.debugWarnLog(doublePress)
1163
+ this.accessory.context.doublePress = this.doublePress
1160
1164
  // Bot Press PushRate
1161
- this.pushRatePress = this.accessory.context.pushRatePress ?? device.bot?.pushRatePress ?? 15;
1162
- const pushRatePress = this.accessory.context.pushRatePress ? `Using Push Rate Press: ${this.pushRatePress}, from Accessory Cache.`
1163
- : device.bot?.pushRatePress ? `Using Bot Push Rate Press: ${this.pushRatePress}`
1164
- : `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`;
1165
- await this.debugWarnLog(pushRatePress);
1166
- this.accessory.context.pushRatePress = this.pushRatePress;
1165
+ this.pushRatePress = this.accessory.context.pushRatePress ?? device.bot?.pushRatePress ?? 15
1166
+ const pushRatePress = this.accessory.context.pushRatePress
1167
+ ? `Using Push Rate Press: ${this.pushRatePress}, from Accessory Cache.`
1168
+ : device.bot?.pushRatePress
1169
+ ? `Using Bot Push Rate Press: ${this.pushRatePress}`
1170
+ : `No Push Rate Press Set, Using default Push Rate Press: ${this.pushRatePress}`
1171
+ await this.debugWarnLog(pushRatePress)
1172
+ this.accessory.context.pushRatePress = this.pushRatePress
1167
1173
  // Bot Allow Push
1168
- this.allowPush = this.accessory.context.allowPush ?? device.bot?.allowPush ?? false;
1169
- const allowPush = this.accessory.context.allowPush ? `Using Allow Push: ${this.allowPush}, from Accessory Cache.`
1170
- : device.bot?.allowPush ? `Using Allow Push: ${this.allowPush}`
1171
- : `No Allow Push Set, Using default Allow Push: ${this.allowPush}`;
1172
- await this.debugWarnLog(allowPush);
1173
- this.accessory.context.allowPush = this.allowPush;
1174
+ this.allowPush = this.accessory.context.allowPush ?? device.bot?.allowPush ?? false
1175
+ const allowPush = this.accessory.context.allowPush
1176
+ ? `Using Allow Push: ${this.allowPush}, from Accessory Cache.`
1177
+ : device.bot?.allowPush
1178
+ ? `Using Allow Push: ${this.allowPush}`
1179
+ : `No Allow Push Set, Using default Allow Push: ${this.allowPush}`
1180
+ await this.debugWarnLog(allowPush)
1181
+ this.accessory.context.allowPush = this.allowPush
1174
1182
  // Bot Multi Press Count
1175
- this.multiPressCount = 0;
1176
- await this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`);
1183
+ this.multiPressCount = 0
1184
+ await this.debugWarnLog(`Multi Press Count: ${this.multiPressCount}`)
1177
1185
  }
1178
1186
 
1179
1187
  async BLEPushConnection() {
1180
1188
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1181
- await this.warnLog('Using OpenAPI Connection to Push Changes');
1182
- await this.openAPIpushChanges();
1189
+ await this.warnLog('Using OpenAPI Connection to Push Changes')
1190
+ await this.openAPIpushChanges()
1183
1191
  }
1184
1192
  }
1185
1193
 
1186
1194
  async BLERefreshConnection(switchbot: any): Promise<void> {
1187
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
1195
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
1188
1196
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
1189
- await this.warnLog('Using OpenAPI Connection to Refresh Status');
1190
- await this.openAPIRefreshStatus();
1197
+ await this.warnLog('Using OpenAPI Connection to Refresh Status')
1198
+ await this.openAPIRefreshStatus()
1191
1199
  }
1192
1200
  }
1193
1201
 
@@ -1195,111 +1203,110 @@ export class Bot extends deviceBase {
1195
1203
  if (this.device.offline) {
1196
1204
  if (this.botDeviceType === 'garagedoor') {
1197
1205
  if (this.GarageDoor) {
1198
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED);
1199
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED);
1200
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, false);
1206
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, this.hap.Characteristic.TargetDoorState.CLOSED)
1207
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, this.hap.Characteristic.CurrentDoorState.CLOSED)
1208
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, false)
1201
1209
  }
1202
1210
  } else if (this.botDeviceType === 'door') {
1203
1211
  if (this.Door) {
1204
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1205
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1206
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1212
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
1213
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
1214
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
1207
1215
  }
1208
1216
  } else if (this.botDeviceType === 'window') {
1209
1217
  if (this.Window) {
1210
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1211
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1212
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1218
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
1219
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
1220
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
1213
1221
  }
1214
1222
  } else if (this.botDeviceType === 'windowcovering') {
1215
1223
  if (this.WindowCovering) {
1216
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0);
1217
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0);
1218
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED);
1224
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, 0)
1225
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, 0)
1226
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, this.hap.Characteristic.PositionState.STOPPED)
1219
1227
  }
1220
1228
  } else if (this.botDeviceType === 'lock') {
1221
1229
  if (this.LockMechanism) {
1222
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED);
1223
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED);
1230
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.hap.Characteristic.LockTargetState.SECURED)
1231
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.hap.Characteristic.LockCurrentState.SECURED)
1224
1232
  }
1225
1233
  } else if (this.botDeviceType === 'faucet') {
1226
1234
  if (this.Faucet) {
1227
- this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE);
1235
+ this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, this.hap.Characteristic.Active.INACTIVE)
1228
1236
  }
1229
1237
  } else if (this.botDeviceType === 'fan') {
1230
1238
  if (this.Fan) {
1231
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, false);
1239
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, false)
1232
1240
  }
1233
1241
  } else if (this.botDeviceType === 'stateful') {
1234
1242
  if (this.StatefulProgrammableSwitch) {
1235
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent,
1236
- this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS);
1237
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0);
1243
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, this.hap.Characteristic.ProgrammableSwitchEvent.SINGLE_PRESS)
1244
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, 0)
1238
1245
  }
1239
1246
  } else if (this.botDeviceType === 'switch') {
1240
1247
  if (this.Switch) {
1241
- this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, false);
1248
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, false)
1242
1249
  }
1243
1250
  } else {
1244
1251
  if (this.Outlet) {
1245
- this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, false);
1252
+ this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, false)
1246
1253
  }
1247
1254
  }
1248
1255
  }
1249
1256
  }
1250
1257
 
1251
1258
  async apiError(e: any): Promise<void> {
1252
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
1253
- this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
1259
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
1260
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
1254
1261
  if (this.botDeviceType === 'garagedoor') {
1255
1262
  if (this.GarageDoor) {
1256
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e);
1257
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e);
1258
- this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e);
1263
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.TargetDoorState, e)
1264
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.CurrentDoorState, e)
1265
+ this.GarageDoor.Service.updateCharacteristic(this.hap.Characteristic.ObstructionDetected, e)
1259
1266
  }
1260
1267
  } else if (this.botDeviceType === 'door') {
1261
1268
  if (this.Door) {
1262
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
1263
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
1264
- this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
1269
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
1270
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
1271
+ this.Door.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
1265
1272
  }
1266
1273
  } else if (this.botDeviceType === 'window') {
1267
1274
  if (this.Window) {
1268
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
1269
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
1270
- this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
1275
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
1276
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
1277
+ this.Window.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
1271
1278
  }
1272
1279
  } else if (this.botDeviceType === 'windowcovering') {
1273
1280
  if (this.WindowCovering) {
1274
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e);
1275
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e);
1276
- this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e);
1281
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.TargetPosition, e)
1282
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.CurrentPosition, e)
1283
+ this.WindowCovering.Service.updateCharacteristic(this.hap.Characteristic.PositionState, e)
1277
1284
  }
1278
1285
  } else if (this.botDeviceType === 'lock') {
1279
1286
  if (this.LockMechanism) {
1280
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
1281
- this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
1287
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockTargetState, e)
1288
+ this.LockMechanism.Service.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e)
1282
1289
  }
1283
1290
  } else if (this.botDeviceType === 'faucet') {
1284
1291
  if (this.Faucet) {
1285
- this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
1292
+ this.Faucet.Service.updateCharacteristic(this.hap.Characteristic.Active, e)
1286
1293
  }
1287
1294
  } else if (this.botDeviceType === 'fan') {
1288
1295
  if (this.Fan) {
1289
- this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, e);
1296
+ this.Fan.Service.updateCharacteristic(this.hap.Characteristic.On, e)
1290
1297
  }
1291
1298
  } else if (this.botDeviceType === 'stateful') {
1292
1299
  if (this.StatefulProgrammableSwitch) {
1293
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e);
1294
- this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e);
1300
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchEvent, e)
1301
+ this.StatefulProgrammableSwitch.Service.updateCharacteristic(this.hap.Characteristic.ProgrammableSwitchOutputState, e)
1295
1302
  }
1296
1303
  } else if (this.botDeviceType === 'switch') {
1297
1304
  if (this.Switch) {
1298
- this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e);
1305
+ this.Switch.Service.updateCharacteristic(this.hap.Characteristic.On, e)
1299
1306
  }
1300
1307
  } else {
1301
1308
  if (this.Outlet) {
1302
- this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e);
1309
+ this.Outlet.Service.updateCharacteristic(this.hap.Characteristic.On, e)
1303
1310
  }
1304
1311
  }
1305
1312
  }