@switchbot/homebridge-switchbot 3.7.1-beta.8 → 3.8.0

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