@switchbot/homebridge-switchbot 4.3.2-beta.8 → 4.3.2

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 (222) hide show
  1. package/.github/copilot-instructions.md +328 -0
  2. package/.github/scripts/npm-version-script-esm-auto.js +207 -0
  3. package/.github/workflows/beta-release.yml +8 -12
  4. package/.github/workflows/release.yml +54 -22
  5. package/CHANGELOG.md +1 -1
  6. package/README.md +13 -10
  7. package/config.schema.json +2 -2
  8. package/coverage/base.css +224 -0
  9. package/coverage/block-navigation.js +87 -0
  10. package/coverage/clover.xml +15847 -0
  11. package/coverage/coverage-final.json +42 -0
  12. package/coverage/docs/assets/dmt/dmt-component-data.js.html +85 -0
  13. package/coverage/docs/assets/dmt/dmt-components.js.html +286 -0
  14. package/coverage/docs/assets/dmt/index.html +131 -0
  15. package/coverage/docs/assets/hierarchy.js.html +85 -0
  16. package/coverage/docs/assets/icons.js.html +136 -0
  17. package/coverage/docs/assets/index.html +146 -0
  18. package/coverage/docs/assets/main.js.html +265 -0
  19. package/coverage/favicon.png +0 -0
  20. package/coverage/index.html +191 -0
  21. package/coverage/prettify.css +1 -0
  22. package/coverage/prettify.js +2 -0
  23. package/coverage/sort-arrow-sprite.png +0 -0
  24. package/coverage/sorter.js +196 -0
  25. package/coverage/src/device/blindtilt.ts.html +3238 -0
  26. package/coverage/src/device/bot.ts.html +2803 -0
  27. package/coverage/src/device/ceilinglight.ts.html +2338 -0
  28. package/coverage/src/device/colorbulb.ts.html +2824 -0
  29. package/coverage/src/device/contact.ts.html +1465 -0
  30. package/coverage/src/device/curtain.ts.html +2869 -0
  31. package/coverage/src/device/device.ts.html +2500 -0
  32. package/coverage/src/device/fan.ts.html +2242 -0
  33. package/coverage/src/device/hub.ts.html +1408 -0
  34. package/coverage/src/device/humidifier.ts.html +2116 -0
  35. package/coverage/src/device/index.html +416 -0
  36. package/coverage/src/device/iosensor.ts.html +1375 -0
  37. package/coverage/src/device/lightstrip.ts.html +2617 -0
  38. package/coverage/src/device/lock.ts.html +1963 -0
  39. package/coverage/src/device/meter.ts.html +1372 -0
  40. package/coverage/src/device/meterplus.ts.html +1384 -0
  41. package/coverage/src/device/meterpro.ts.html +1618 -0
  42. package/coverage/src/device/motion.ts.html +1264 -0
  43. package/coverage/src/device/plug.ts.html +1372 -0
  44. package/coverage/src/device/relayswitch.ts.html +2284 -0
  45. package/coverage/src/device/robotvacuumcleaner.ts.html +1810 -0
  46. package/coverage/src/device/waterdetector.ts.html +1294 -0
  47. package/coverage/src/homebridge-ui/index.html +116 -0
  48. package/coverage/src/homebridge-ui/server.ts.html +229 -0
  49. package/coverage/src/index.html +161 -0
  50. package/coverage/src/index.ts.html +124 -0
  51. package/coverage/src/irdevice/airconditioner.ts.html +1687 -0
  52. package/coverage/src/irdevice/airpurifier.ts.html +844 -0
  53. package/coverage/src/irdevice/camera.ts.html +475 -0
  54. package/coverage/src/irdevice/fan.ts.html +766 -0
  55. package/coverage/src/irdevice/index.html +251 -0
  56. package/coverage/src/irdevice/irdevice.ts.html +1117 -0
  57. package/coverage/src/irdevice/light.ts.html +826 -0
  58. package/coverage/src/irdevice/other.ts.html +2458 -0
  59. package/coverage/src/irdevice/tv.ts.html +1222 -0
  60. package/coverage/src/irdevice/vacuumcleaner.ts.html +466 -0
  61. package/coverage/src/irdevice/waterheater.ts.html +469 -0
  62. package/coverage/src/platform.ts.html +8776 -0
  63. package/coverage/src/settings.ts.html +934 -0
  64. package/coverage/src/utils.ts.html +2092 -0
  65. package/dist/device/blindtilt.d.ts.map +1 -1
  66. package/dist/device/blindtilt.js +12 -4
  67. package/dist/device/blindtilt.js.map +1 -1
  68. package/dist/device/bot.d.ts.map +1 -1
  69. package/dist/device/bot.js +12 -4
  70. package/dist/device/bot.js.map +1 -1
  71. package/dist/device/ceilinglight.d.ts.map +1 -1
  72. package/dist/device/ceilinglight.js +18 -7
  73. package/dist/device/ceilinglight.js.map +1 -1
  74. package/dist/device/colorbulb.d.ts.map +1 -1
  75. package/dist/device/colorbulb.js +18 -7
  76. package/dist/device/colorbulb.js.map +1 -1
  77. package/dist/device/contact.d.ts.map +1 -1
  78. package/dist/device/contact.js +6 -2
  79. package/dist/device/contact.js.map +1 -1
  80. package/dist/device/curtain.d.ts.map +1 -1
  81. package/dist/device/curtain.js +12 -4
  82. package/dist/device/curtain.js.map +1 -1
  83. package/dist/device/device.d.ts +5 -7
  84. package/dist/device/device.d.ts.map +1 -1
  85. package/dist/device/device.js +11 -5
  86. package/dist/device/device.js.map +1 -1
  87. package/dist/device/fan.d.ts.map +1 -1
  88. package/dist/device/fan.js +16 -6
  89. package/dist/device/fan.js.map +1 -1
  90. package/dist/device/hub.d.ts +2 -2
  91. package/dist/device/hub.d.ts.map +1 -1
  92. package/dist/device/hub.js +8 -3
  93. package/dist/device/hub.js.map +1 -1
  94. package/dist/device/humidifier.d.ts.map +1 -1
  95. package/dist/device/humidifier.js +16 -6
  96. package/dist/device/humidifier.js.map +1 -1
  97. package/dist/device/iosensor.d.ts.map +1 -1
  98. package/dist/device/iosensor.js +6 -2
  99. package/dist/device/iosensor.js.map +1 -1
  100. package/dist/device/lightstrip.d.ts.map +1 -1
  101. package/dist/device/lightstrip.js +16 -6
  102. package/dist/device/lightstrip.js.map +1 -1
  103. package/dist/device/lock.d.ts.map +1 -1
  104. package/dist/device/lock.js +12 -4
  105. package/dist/device/lock.js.map +1 -1
  106. package/dist/device/meter.d.ts.map +1 -1
  107. package/dist/device/meter.js +6 -2
  108. package/dist/device/meter.js.map +1 -1
  109. package/dist/device/meterplus.d.ts.map +1 -1
  110. package/dist/device/meterplus.js +6 -2
  111. package/dist/device/meterplus.js.map +1 -1
  112. package/dist/device/meterpro.d.ts.map +1 -1
  113. package/dist/device/meterpro.js +7 -4
  114. package/dist/device/meterpro.js.map +1 -1
  115. package/dist/device/motion.d.ts.map +1 -1
  116. package/dist/device/motion.js +6 -2
  117. package/dist/device/motion.js.map +1 -1
  118. package/dist/device/occupancy.d.ts +42 -0
  119. package/dist/device/occupancy.d.ts.map +1 -0
  120. package/dist/device/occupancy.js +349 -0
  121. package/dist/device/occupancy.js.map +1 -0
  122. package/dist/device/plug.d.ts.map +1 -1
  123. package/dist/device/plug.js +12 -4
  124. package/dist/device/plug.js.map +1 -1
  125. package/dist/device/relayswitch.d.ts.map +1 -1
  126. package/dist/device/relayswitch.js +12 -4
  127. package/dist/device/relayswitch.js.map +1 -1
  128. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  129. package/dist/device/robotvacuumcleaner.js +14 -5
  130. package/dist/device/robotvacuumcleaner.js.map +1 -1
  131. package/dist/device/waterdetector.d.ts.map +1 -1
  132. package/dist/device/waterdetector.js +6 -2
  133. package/dist/device/waterdetector.js.map +1 -1
  134. package/dist/homebridge-ui/public/index.html +1 -1
  135. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  136. package/dist/irdevice/airconditioner.js +2 -1
  137. package/dist/irdevice/airconditioner.js.map +1 -1
  138. package/dist/irdevice/airpurifier.d.ts +1 -1
  139. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  140. package/dist/irdevice/airpurifier.js +6 -5
  141. package/dist/irdevice/airpurifier.js.map +1 -1
  142. package/dist/irdevice/camera.d.ts.map +1 -1
  143. package/dist/irdevice/camera.js +2 -1
  144. package/dist/irdevice/camera.js.map +1 -1
  145. package/dist/irdevice/fan.d.ts.map +1 -1
  146. package/dist/irdevice/fan.js +2 -1
  147. package/dist/irdevice/fan.js.map +1 -1
  148. package/dist/irdevice/irdevice.d.ts +2 -6
  149. package/dist/irdevice/irdevice.d.ts.map +1 -1
  150. package/dist/irdevice/irdevice.js.map +1 -1
  151. package/dist/irdevice/light.d.ts.map +1 -1
  152. package/dist/irdevice/light.js +2 -1
  153. package/dist/irdevice/light.js.map +1 -1
  154. package/dist/irdevice/other.d.ts.map +1 -1
  155. package/dist/irdevice/other.js +2 -1
  156. package/dist/irdevice/other.js.map +1 -1
  157. package/dist/irdevice/tv.d.ts.map +1 -1
  158. package/dist/irdevice/tv.js +2 -1
  159. package/dist/irdevice/tv.js.map +1 -1
  160. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  161. package/dist/irdevice/vacuumcleaner.js +2 -1
  162. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  163. package/dist/irdevice/waterheater.d.ts.map +1 -1
  164. package/dist/irdevice/waterheater.js +2 -1
  165. package/dist/irdevice/waterheater.js.map +1 -1
  166. package/dist/platform.d.ts +2 -2
  167. package/dist/platform.d.ts.map +1 -1
  168. package/dist/platform.js +77 -78
  169. package/dist/platform.js.map +1 -1
  170. package/dist/settings.d.ts +6 -0
  171. package/dist/settings.d.ts.map +1 -1
  172. package/dist/settings.js +1 -0
  173. package/dist/settings.js.map +1 -1
  174. package/docs/index.html +20 -11
  175. package/docs/variables/default.html +1 -1
  176. package/eslint.config.js +0 -1
  177. package/package.json +7 -8
  178. package/src/device/blindtilt.ts +10 -4
  179. package/src/device/bot.ts +10 -4
  180. package/src/device/ceilinglight.ts +16 -7
  181. package/src/device/colorbulb.ts +16 -7
  182. package/src/device/contact.ts +5 -2
  183. package/src/device/curtain.ts +12 -6
  184. package/src/device/device.ts +14 -8
  185. package/src/device/fan.ts +14 -6
  186. package/src/device/hub.ts +10 -6
  187. package/src/device/humidifier.ts +14 -6
  188. package/src/device/iosensor.ts +5 -2
  189. package/src/device/lightstrip.ts +14 -6
  190. package/src/device/lock.ts +10 -4
  191. package/src/device/meter.ts +6 -3
  192. package/src/device/meterplus.ts +5 -2
  193. package/src/device/meterpro.ts +7 -5
  194. package/src/device/motion.ts +5 -2
  195. package/src/device/occupancy.ts +393 -0
  196. package/src/device/plug.ts +10 -4
  197. package/src/device/relayswitch.ts +10 -4
  198. package/src/device/robotvacuumcleaner.ts +12 -5
  199. package/src/device/waterdetector.ts +5 -2
  200. package/src/homebridge-ui/public/index.html +1 -1
  201. package/src/irdevice/airconditioner.ts +2 -1
  202. package/src/irdevice/airpurifier.ts +6 -5
  203. package/src/irdevice/camera.ts +2 -1
  204. package/src/irdevice/fan.ts +2 -1
  205. package/src/irdevice/irdevice.ts +2 -2
  206. package/src/irdevice/light.ts +2 -1
  207. package/src/irdevice/other.ts +2 -1
  208. package/src/irdevice/tv.ts +2 -1
  209. package/src/irdevice/vacuumcleaner.ts +2 -1
  210. package/src/irdevice/waterheater.ts +2 -1
  211. package/src/platform.ts +80 -88
  212. package/src/settings.ts +7 -0
  213. package/.github/npm-version-script-esm.js +0 -97
  214. package/.github/workflows/build.yml +0 -18
  215. package/.github/workflows/changerelease.yml +0 -11
  216. package/.github/workflows/labeler.yml +0 -16
  217. package/.github/workflows/release-drafter.yml +0 -14
  218. package/dist/device/airpurifier.d.ts +0 -54
  219. package/dist/device/airpurifier.d.ts.map +0 -1
  220. package/dist/device/airpurifier.js +0 -527
  221. package/dist/device/airpurifier.js.map +0 -1
  222. package/src/device/airpurifier.ts +0 -563
@@ -0,0 +1,393 @@
1
+ /* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
+ *
3
+ * occupancy.ts: @switchbot/homebridge-switchbot.
4
+ */
5
+ import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
6
+ import type { device, occupancySensorStatus, occupancySensorWebhookContext, presenceSensorServiceData, SwitchBotBLE } from 'node-switchbot'
7
+
8
+ import type { SwitchBotPlatform } from '../platform.js'
9
+ import type { devicesConfig, occupancyConfig } from '../settings.js'
10
+
11
+ /*
12
+ * For Testing Locally:
13
+ * import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
14
+ */
15
+ import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
16
+ import { interval, skipWhile, Subject } from 'rxjs'
17
+
18
+ import { formatDeviceIdAsMac } from '../utils.js'
19
+ import { deviceBase } from './device.js'
20
+
21
+ /**
22
+ * Platform Accessory
23
+ * An instance of this class is created for each accessory your platform registers
24
+ * Each accessory may expose multiple services of different service types.
25
+ */
26
+ export class Occupancy extends deviceBase {
27
+ // Services
28
+ private Battery: {
29
+ Name: CharacteristicValue
30
+ Service: Service
31
+ BatteryLevel: CharacteristicValue
32
+ StatusLowBattery: CharacteristicValue
33
+ }
34
+
35
+ private OccupancySensor: {
36
+ Name: CharacteristicValue
37
+ Service: Service
38
+ OccupancyDetected: CharacteristicValue
39
+ }
40
+
41
+ private LightSensor?: {
42
+ Name: CharacteristicValue
43
+ Service: Service
44
+ CurrentAmbientLightLevel: CharacteristicValue
45
+ }
46
+
47
+ // OpenAPI
48
+ deviceStatus!: occupancySensorStatus
49
+
50
+ // Webhook
51
+ webhookContext!: occupancySensorWebhookContext
52
+
53
+ // BLE
54
+ serviceData!: presenceSensorServiceData
55
+
56
+ // Updates
57
+ occcupancyUbpdateInProgress!: boolean
58
+ doOccupancyUpdate!: Subject<void>
59
+
60
+ constructor(
61
+ readonly platform: SwitchBotPlatform,
62
+ accessory: PlatformAccessory,
63
+ device: device & devicesConfig,
64
+ ) {
65
+ super(platform, accessory, device)
66
+ // Set category
67
+ accessory.category = this.hap.Categories.SENSOR
68
+
69
+ // this is subject we use to track when we need to POST changes to the SwitchBot API
70
+ this.doOccupancyUpdate = new Subject()
71
+ this.occcupancyUbpdateInProgress = false
72
+
73
+ // Initialize Occupancy Sensor property
74
+ accessory.context.OccupancySensor = accessory.context.OccupancySensor ?? {}
75
+ this.OccupancySensor = {
76
+ Name: `${accessory.displayName} Occupancy Sensor`,
77
+ Service: accessory.getService(this.hap.Service.OccupancySensor) ?? accessory.addService(this.hap.Service.OccupancySensor) as Service,
78
+ OccupancyDetected: accessory.context.OccupancyDetected ?? false,
79
+ }
80
+ accessory.context.OccupancySensor = this.OccupancySensor as object
81
+
82
+ // Initialize Occupancy Sensor Characteristics
83
+ this.OccupancySensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.OccupancySensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true).getCharacteristic(this.hap.Characteristic.OccupancyDetected).onGet(() => {
84
+ return this.OccupancySensor.OccupancyDetected
85
+ })
86
+
87
+ // Initialize Battery Service
88
+ accessory.context.Battery = accessory.context.Battery ?? {}
89
+ this.Battery = {
90
+ Name: `${accessory.displayName} Battery`,
91
+ Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
92
+ BatteryLevel: accessory.context.BatteryLevel ?? 100,
93
+ StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
94
+ }
95
+ accessory.context.Battery = this.Battery as object
96
+
97
+ // Initialize Battery Characteristics
98
+ this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE).getCharacteristic(this.hap.Characteristic.BatteryLevel).onGet(() => {
99
+ return this.Battery.BatteryLevel
100
+ })
101
+
102
+ this.Battery.Service.setCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery).getCharacteristic(this.hap.Characteristic.StatusLowBattery).onGet(() => {
103
+ return this.Battery.StatusLowBattery
104
+ })
105
+
106
+ // Initialize Light Sensor Service
107
+ if ((device as unknown as occupancyConfig).hide_lightsensor) {
108
+ if (this.LightSensor) {
109
+ this.debugLog('Removing Light Sensor Service')
110
+ this.LightSensor.Service = this.accessory.getService(this.hap.Service.LightSensor) as Service
111
+ accessory.removeService(this.LightSensor.Service)
112
+ }
113
+ } else {
114
+ accessory.context.LightSensor = accessory.context.LightSensor ?? {}
115
+ this.LightSensor = {
116
+ Name: `${accessory.displayName} Light Sensor`,
117
+ Service: accessory.getService(this.hap.Service.LightSensor) ?? this.accessory.addService(this.hap.Service.LightSensor) as Service,
118
+ CurrentAmbientLightLevel: accessory.context.CurrentAmbientLightLevel ?? 0.0001,
119
+ }
120
+ accessory.context.LightSensor = this.LightSensor as object
121
+
122
+ // Initialize LightSensor Characteristics
123
+ this.LightSensor.Service.setCharacteristic(this.hap.Characteristic.Name, this.LightSensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true)
124
+ };
125
+
126
+ // Retrieve initial values and updateHomekit
127
+ try {
128
+ this.debugLog('Retrieve initial values and update Homekit')
129
+ this.refreshStatus()
130
+ } catch (e: any) {
131
+ this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
132
+ }
133
+
134
+ // regisiter webhook event handler if enabled
135
+ try {
136
+ this.debugLog('Registering Webhook Event Handler')
137
+ this.registerWebhook()
138
+ } catch (e: any) {
139
+ this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
140
+ }
141
+
142
+ // regisiter platform BLE event handler if enabled
143
+ try {
144
+ this.debugLog('Registering Platform BLE Event Handler')
145
+ this.registerPlatformBLE()
146
+ } catch (e: any) {
147
+ this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
148
+ }
149
+
150
+ // Start an update interval
151
+ interval(this.deviceRefreshRate * 1000)
152
+ .pipe(skipWhile(() => this.occcupancyUbpdateInProgress))
153
+ .subscribe(async () => {
154
+ await this.refreshStatus()
155
+ })
156
+ }
157
+
158
+ async BLEparseStatus(): Promise<void> {
159
+ this.debugLog('BLEparseStatus')
160
+ this.debugLog(`(moveDetected) = BLE: (${this.serviceData.motionDetected}), current: (${this.OccupancySensor.OccupancyDetected})`)
161
+
162
+ // Movement
163
+ this.OccupancySensor.OccupancyDetected = this.serviceData.motionDetected
164
+ this.debugLog(`OccupancyDetected: ${this.OccupancySensor.OccupancyDetected}`)
165
+
166
+ // CurrentAmbientLightLevel
167
+ if (!(this.device as unknown as occupancyConfig).hide_lightsensor && this.LightSensor?.Service) {
168
+ const set_minLux = (this.device as unknown as occupancyConfig).set_minLux ?? 1
169
+ const set_maxLux = (this.device as unknown as occupancyConfig).set_maxLux ?? 6001
170
+ const lightLevel = this.serviceData.lightLevel ? set_maxLux : set_minLux
171
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
172
+ this.debugLog(`LightLevel: ${this.serviceData.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
173
+ }
174
+ // Battery Info
175
+ if ('battery' in this.serviceData) {
176
+ // BatteryLevel
177
+ this.Battery.BatteryLevel = Number(this.serviceData.battery)
178
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
179
+ // StatusLowBattery
180
+ this.Battery.StatusLowBattery = Number(this.Battery.BatteryLevel) < 10
181
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
182
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
183
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
184
+ }
185
+ }
186
+
187
+ async openAPIparseStatus(): Promise<void> {
188
+ this.debugLog('openAPIparseStatus')
189
+ this.debugLog(`(moveDetected) = OpenAPI: (${this.deviceStatus.Detected}), current: (${this.OccupancySensor.OccupancyDetected})`)
190
+
191
+ // Occupancy State
192
+ this.OccupancySensor.OccupancyDetected = this.deviceStatus.Detected
193
+ this.debugLog(`OccupancyDetected: ${this.OccupancySensor.OccupancyDetected}`)
194
+
195
+ // CurrentAmbientLightLevel
196
+ if (!(this.device as unknown as occupancyConfig).hide_lightsensor && this.LightSensor?.Service) {
197
+ const set_minLux = (this.device as unknown as occupancyConfig).set_minLux ?? 1
198
+ const set_maxLux = (this.device as unknown as occupancyConfig).set_maxLux ?? 6001
199
+ const lightLevel = this.deviceStatus.lightLevel ? set_maxLux : set_minLux
200
+ this.LightSensor.CurrentAmbientLightLevel = this.getLightLevel(lightLevel, set_minLux, set_maxLux, 2)
201
+ this.debugLog(`LightLevel: ${this.deviceStatus.lightLevel}, CurrentAmbientLightLevel: ${this.LightSensor.CurrentAmbientLightLevel}`)
202
+ }
203
+ // BatteryLevel
204
+ this.Battery.BatteryLevel = this.deviceStatus.battery
205
+ this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
206
+
207
+ // StatusLowBattery
208
+ this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
209
+ ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
210
+ : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
211
+ this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
212
+
213
+ // FirmwareVersion
214
+ if (this.deviceStatus.version) {
215
+ const version = String(this.deviceStatus.version)
216
+ this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`)
217
+ const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
218
+ this.accessory
219
+ .getService(this.hap.Service.AccessoryInformation)!
220
+ .setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
221
+ .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
222
+ .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
223
+ .updateValue(deviceVersion)
224
+ this.accessory.context.version = deviceVersion
225
+ this.debugLog(`version: ${this.accessory.context.version}`)
226
+ }
227
+ }
228
+
229
+ async parseStatusWebhook(): Promise<void> {
230
+ this.debugLog('parseStatusWebhook')
231
+ this.debugLog(`(detectionState) = Webhook: (${this.webhookContext.detectionState}), current: (${this.OccupancySensor.OccupancyDetected})`)
232
+
233
+ // OccupancyDetected
234
+ this.OccupancySensor.OccupancyDetected = this.webhookContext.detectionState === 'DETECTED'
235
+ this.debugLog(`OccupancyDetected: ${this.OccupancySensor.OccupancyDetected}`)
236
+ }
237
+
238
+ /**
239
+ * Asks the SwitchBot API for the latest device information
240
+ */
241
+ async refreshStatus(): Promise<void> {
242
+ if (!this.device.enableCloudService && this.OpenAPI) {
243
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
244
+ } else if (this.BLE) {
245
+ await this.BLERefreshStatus()
246
+ } else if (this.OpenAPI && this.platform.config.credentials?.token) {
247
+ await this.openAPIRefreshStatus()
248
+ } else {
249
+ await this.offlineOff()
250
+ this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
251
+ }
252
+ }
253
+
254
+ async BLERefreshStatus(): Promise<void> {
255
+ this.debugLog('BLERefreshStatus')
256
+ const switchBotBLE = await this.switchbotBLE()
257
+ if (switchBotBLE === undefined) {
258
+ await this.BLERefreshConnection(switchBotBLE)
259
+ } else {
260
+ // Start to monitor advertisement packets
261
+ (async () => {
262
+ // Start to monitor advertisement packets
263
+ const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as presenceSensorServiceData
264
+ // Update HomeKit
265
+ if (serviceData.model === SwitchBotBLEModel.PresenceSensor && serviceData.modelName === SwitchBotBLEModelName.PresenceSensor) {
266
+ this.serviceData = serviceData
267
+ if (serviceData !== undefined || serviceData !== null) {
268
+ await this.BLEparseStatus()
269
+ await this.updateHomeKitCharacteristics()
270
+ } else {
271
+ this.errorLog(`serviceData is either undefined or null, serviceData: ${JSON.stringify(serviceData)}`)
272
+ await this.BLERefreshConnection(switchBotBLE)
273
+ }
274
+ } else {
275
+ this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
276
+ await this.BLERefreshConnection(switchBotBLE)
277
+ }
278
+ })()
279
+ }
280
+ }
281
+
282
+ async registerPlatformBLE(): Promise<void> {
283
+ this.debugLog('registerPlatformBLE')
284
+ if (this.config.options?.BLE && !this.device.disablePlatformBLE) {
285
+ this.debugLog('is listening to Platform BLE.')
286
+ try {
287
+ const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
288
+ this.device.bleMac = formattedDeviceId
289
+ this.debugLog(`bleMac: ${this.device.bleMac}`)
290
+ this.platform.bleEventHandler[this.device.bleMac] = async (context: presenceSensorServiceData) => {
291
+ try {
292
+ this.serviceData = context
293
+ if (context !== undefined || context !== null) {
294
+ this.debugLog(`received BLE: ${JSON.stringify(context)}`)
295
+ await this.BLEparseStatus()
296
+ await this.updateHomeKitCharacteristics()
297
+ } else {
298
+ this.errorLog(`context is either undefined or null, context: ${JSON.stringify(context)}`)
299
+ await this.BLERefreshConnection(context)
300
+ }
301
+ } catch (e: any) {
302
+ this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
303
+ }
304
+ }
305
+ } catch (error) {
306
+ this.errorLog(`failed to format device ID as MAC, Error: ${error}`)
307
+ }
308
+ } else {
309
+ this.debugLog('is not listening to Platform BLE')
310
+ }
311
+ }
312
+
313
+ async openAPIRefreshStatus(): Promise<void> {
314
+ this.debugLog('openAPIRefreshStatus')
315
+ try {
316
+ const response = await this.deviceRefreshStatus()
317
+ const deviceStatus: any = response.body
318
+ this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
319
+ if (await this.successfulStatusCodes(deviceStatus)) {
320
+ this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
321
+ this.deviceStatus = deviceStatus.body
322
+ await this.openAPIparseStatus()
323
+ await this.updateHomeKitCharacteristics()
324
+ } else {
325
+ this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
326
+ }
327
+ } catch (e: any) {
328
+ await this.apiError(e)
329
+ this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
330
+ }
331
+ }
332
+
333
+ async registerWebhook() {
334
+ if (this.device.webhook) {
335
+ this.debugLog('is listening webhook.')
336
+ this.platform.webhookEventHandler[this.device.deviceId] = async (context: occupancySensorWebhookContext) => {
337
+ try {
338
+ this.webhookContext = context
339
+ if (context !== undefined || context !== null) {
340
+ this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
341
+ await this.parseStatusWebhook()
342
+ await this.updateHomeKitCharacteristics()
343
+ } else {
344
+ this.errorLog(`context is either undefined or null, context: ${JSON.stringify(context)}`)
345
+ }
346
+ } catch (e: any) {
347
+ this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
348
+ }
349
+ }
350
+ } else {
351
+ this.debugLog('is not listening webhook.')
352
+ }
353
+ }
354
+
355
+ /**
356
+ * Updates the status for each of the HomeKit Characteristics
357
+ */
358
+ async updateHomeKitCharacteristics(): Promise<void> {
359
+ // OccupancyDetected
360
+ await this.updateCharacteristic(this.OccupancySensor.Service, this.hap.Characteristic.OccupancyDetected, this.OccupancySensor.OccupancyDetected, 'OccupancyDetected')
361
+ // BatteryLevel
362
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel')
363
+ // StatusLowBattery
364
+ await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery')
365
+ // CurrentAmbientLightLevel
366
+ if (!(this.device as unknown as occupancyConfig).hide_lightsensor && this.LightSensor?.Service) {
367
+ await this.updateCharacteristic(this.LightSensor.Service, this.hap.Characteristic.CurrentAmbientLightLevel, this.LightSensor.CurrentAmbientLightLevel, 'CurrentAmbientLightLevel')
368
+ }
369
+ }
370
+
371
+ async BLERefreshConnection(switchbot: SwitchBotBLE): Promise<void> {
372
+ this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
373
+ if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
374
+ this.warnLog('Using OpenAPI Connection to Refresh Status')
375
+ await this.openAPIRefreshStatus()
376
+ }
377
+ }
378
+
379
+ async offlineOff(): Promise<void> {
380
+ if (this.device.offline) {
381
+ this.OccupancySensor.Service.updateCharacteristic(this.hap.Characteristic.OccupancyDetected, false)
382
+ }
383
+ }
384
+
385
+ async apiError(e: any): Promise<void> {
386
+ this.OccupancySensor.Service.updateCharacteristic(this.hap.Characteristic.OccupancyDetected, e)
387
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
388
+ this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
389
+ if (!(this.device as unknown as occupancyConfig).hide_lightsensor && this.LightSensor?.Service) {
390
+ this.LightSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentAmbientLightLevel, e)
391
+ }
392
+ }
393
+ }
@@ -163,7 +163,9 @@ export class Plug extends deviceBase {
163
163
  * Asks the SwitchBot API for the latest device information
164
164
  */
165
165
  async refreshStatus(): Promise<void> {
166
- if (this.BLE) {
166
+ if (!this.device.enableCloudService && this.OpenAPI) {
167
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
168
+ } else if (this.BLE) {
167
169
  await this.BLERefreshStatus()
168
170
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
169
171
  await this.openAPIRefreshStatus()
@@ -236,7 +238,8 @@ export class Plug extends deviceBase {
236
238
  async openAPIRefreshStatus(): Promise<void> {
237
239
  this.debugLog('openAPIRefreshStatus')
238
240
  try {
239
- const deviceStatus = await this.deviceRefreshStatus<plugStatus | plugMiniStatus>()
241
+ const response = await this.deviceRefreshStatus()
242
+ const deviceStatus: any = response.body
240
243
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
241
244
  if (await this.successfulStatusCodes(deviceStatus)) {
242
245
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -285,7 +288,9 @@ export class Plug extends deviceBase {
285
288
  */
286
289
 
287
290
  async pushChanges(): Promise<void> {
288
- if (this.BLE) {
291
+ if (!this.device.enableCloudService && this.OpenAPI) {
292
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
293
+ } else if (this.BLE) {
289
294
  await this.BLEpushChanges()
290
295
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
291
296
  await this.openAPIpushChanges()
@@ -360,7 +365,8 @@ export class Plug extends deviceBase {
360
365
  }
361
366
  this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
362
367
  try {
363
- const deviceStatus = await this.pushChangeRequest(bodyChange)
368
+ const response = await this.pushChangeRequest(bodyChange)
369
+ const deviceStatus: any = response.body
364
370
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
365
371
  if (await this.successfulStatusCodes(deviceStatus)) {
366
372
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -292,7 +292,9 @@ export class RelaySwitch extends deviceBase {
292
292
  * Asks the SwitchBot API for the latest device information
293
293
  */
294
294
  async refreshStatus(): Promise<void> {
295
- if (this.BLE) {
295
+ if (!this.device.enableCloudService && this.OpenAPI) {
296
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
297
+ } else if (this.BLE) {
296
298
  await this.BLERefreshStatus()
297
299
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
298
300
  await this.openAPIRefreshStatus()
@@ -364,7 +366,8 @@ export class RelaySwitch extends deviceBase {
364
366
  async openAPIRefreshStatus(): Promise<void> {
365
367
  this.debugLog('openAPIRefreshStatus')
366
368
  try {
367
- const deviceStatus = await this.deviceRefreshStatus<relaySwitch1Status | relaySwitch1PMStatus>()
369
+ const response = await this.deviceRefreshStatus()
370
+ const deviceStatus: any = response.body
368
371
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
369
372
  if (await this.successfulStatusCodes(deviceStatus)) {
370
373
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -409,7 +412,9 @@ export class RelaySwitch extends deviceBase {
409
412
  * RelaySwitch "command" "turnOn" "default" = set to ON state
410
413
  */
411
414
  async pushChanges(): Promise<void> {
412
- if (this.BLE) {
415
+ if (!this.device.enableCloudService && this.OpenAPI) {
416
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
417
+ } else if (this.BLE) {
413
418
  await this.BLEpushChanges()
414
419
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
415
420
  await this.openAPIpushChanges()
@@ -483,7 +488,8 @@ export class RelaySwitch extends deviceBase {
483
488
  }
484
489
  this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
485
490
  try {
486
- const deviceStatus = await this.pushChangeRequest(bodyChange)
491
+ const response = await this.pushChangeRequest(bodyChange)
492
+ const deviceStatus: any = response.body
487
493
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
488
494
  if (await this.successfulStatusCodes(deviceStatus)) {
489
495
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -252,7 +252,9 @@ export class RobotVacuumCleaner extends deviceBase {
252
252
  * Asks the SwitchBot API for the latest device information
253
253
  */
254
254
  async refreshStatus(): Promise<void> {
255
- if (this.BLE) {
255
+ if (!this.device.enableCloudService && this.OpenAPI) {
256
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
257
+ } else if (this.BLE) {
256
258
  await this.BLERefreshStatus()
257
259
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
258
260
  await this.openAPIRefreshStatus()
@@ -324,7 +326,8 @@ export class RobotVacuumCleaner extends deviceBase {
324
326
  async openAPIRefreshStatus(): Promise<void> {
325
327
  this.debugLog('openAPIRefreshStatus')
326
328
  try {
327
- const deviceStatus = await this.deviceRefreshStatus<robotVacuumCleanerS1Status | robotVacuumCleanerS1PlusStatus | floorCleaningRobotS10Status>()
329
+ const response = await this.deviceRefreshStatus()
330
+ const deviceStatus: any = response.body
328
331
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
329
332
  if (await this.successfulStatusCodes(deviceStatus)) {
330
333
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -371,7 +374,9 @@ export class RobotVacuumCleaner extends deviceBase {
371
374
  * Robot Vacuum Cleaner S1 "command" "PowLevel" "{0-3}" = set suction power level: 0 (Quiet), 1 (Standard), 2 (Strong), 3 (MAX)
372
375
  */
373
376
  async pushChanges(): Promise<void> {
374
- if (this.BLE) {
377
+ if (!this.device.enableCloudService && this.OpenAPI) {
378
+ this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`)
379
+ } else if (this.BLE) {
375
380
  await this.BLEpushChanges()
376
381
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
377
382
  await this.openAPIpushChanges()
@@ -444,7 +449,8 @@ export class RobotVacuumCleaner extends deviceBase {
444
449
  }
445
450
  this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
446
451
  try {
447
- const deviceStatus = await this.pushChangeRequest(bodyChange)
452
+ const response = await this.pushChangeRequest(bodyChange)
453
+ const deviceStatus: any = response.body
448
454
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
449
455
  if (await this.successfulStatusCodes(deviceStatus)) {
450
456
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -479,7 +485,8 @@ export class RobotVacuumCleaner extends deviceBase {
479
485
  }
480
486
  this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
481
487
  try {
482
- const deviceStatus = await this.pushChangeRequest(bodyChange)
488
+ const response = await this.pushChangeRequest(bodyChange)
489
+ const deviceStatus: any = response.body
483
490
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
484
491
  if (await this.successfulStatusCodes(deviceStatus)) {
485
492
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -246,7 +246,9 @@ export class WaterDetector extends deviceBase {
246
246
  * Asks the SwitchBot API for the latest device information
247
247
  */
248
248
  async refreshStatus(): Promise<void> {
249
- if (this.BLE) {
249
+ if (!this.device.enableCloudService && this.OpenAPI) {
250
+ this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
251
+ } else if (this.BLE) {
250
252
  await this.BLERefreshStatus()
251
253
  } else if (this.OpenAPI && this.platform.config.credentials?.token) {
252
254
  await this.openAPIRefreshStatus()
@@ -318,7 +320,8 @@ export class WaterDetector extends deviceBase {
318
320
  async openAPIRefreshStatus(): Promise<void> {
319
321
  this.debugLog('openAPIRefreshStatus')
320
322
  try {
321
- const deviceStatus = await this.deviceRefreshStatus<waterLeakDetectorStatus>()
323
+ const response = await this.deviceRefreshStatus()
324
+ const deviceStatus: any = response.body
322
325
  this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
323
326
  if (await this.successfulStatusCodes(deviceStatus)) {
324
327
  this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
@@ -71,7 +71,7 @@
71
71
  </tr>
72
72
  </tbody>
73
73
  </table>
74
- <p class="text-center">External Accessories Will Not Display Here.</p>
74
+ <p class="text-center">External accessories will not be displayed here.</p>
75
75
  </div>
76
76
  </div>
77
77
  <div id="pageSupport" class="mt-4" style="display: none">
@@ -316,7 +316,8 @@ export class AirConditioner extends irdeviceBase {
316
316
  if (this.device.connectionType === 'OpenAPI' && !this.deviceDisablePushDetail) {
317
317
  this.infoLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)}`)
318
318
  try {
319
- const deviceStatus = await this.pushChangeRequest(bodyChange)
319
+ const response = await this.pushChangeRequest(bodyChange)
320
+ const deviceStatus: any = response.body
320
321
  await this.pushStatusCodes(deviceStatus)
321
322
  if (await this.successfulStatusCodes(deviceStatus)) {
322
323
  await this.successfulPushChange(deviceStatus, bodyChange)
@@ -15,7 +15,7 @@ import { irdeviceBase } from './irdevice.js'
15
15
  * An instance of this class is created for each accessory your platform registers
16
16
  * Each accessory may expose multiple services of different service types.
17
17
  */
18
- export class AirPurifierIR extends irdeviceBase {
18
+ export class AirPurifier extends irdeviceBase {
19
19
  // Services
20
20
  private AirPurifier: {
21
21
  Name: CharacteristicValue
@@ -111,13 +111,13 @@ export class AirPurifierIR extends irdeviceBase {
111
111
  async TargetAirPurifierStateSet(value: CharacteristicValue): Promise<void> {
112
112
  switch (value) {
113
113
  case this.hap.Characteristic.CurrentAirPurifierState.PURIFYING_AIR:
114
- this.CurrentMode = AirPurifierIR.PURIFYING_AIR
114
+ this.CurrentMode = AirPurifier.PURIFYING_AIR
115
115
  break
116
116
  case this.hap.Characteristic.CurrentAirPurifierState.IDLE:
117
- this.CurrentMode = AirPurifierIR.IDLE
117
+ this.CurrentMode = AirPurifier.IDLE
118
118
  break
119
119
  case this.hap.Characteristic.CurrentAirPurifierState.INACTIVE:
120
- this.CurrentMode = AirPurifierIR.INACTIVE
120
+ this.CurrentMode = AirPurifier.INACTIVE
121
121
  break
122
122
  default:
123
123
  break
@@ -213,7 +213,8 @@ export class AirPurifierIR extends irdeviceBase {
213
213
  if (this.device.connectionType === 'OpenAPI') {
214
214
  this.infoLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)}`)
215
215
  try {
216
- const deviceStatus = await this.pushChangeRequest(bodyChange)
216
+ const response = await this.pushChangeRequest(bodyChange)
217
+ const deviceStatus: any = response.body
217
218
  await this.pushStatusCodes(deviceStatus)
218
219
  if (await this.successfulStatusCodes(deviceStatus)) {
219
220
  await this.successfulPushChange(deviceStatus, bodyChange)
@@ -100,7 +100,8 @@ export class Camera extends irdeviceBase {
100
100
  if (this.device.connectionType === 'OpenAPI') {
101
101
  this.infoLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)}`)
102
102
  try {
103
- const deviceStatus = await this.pushChangeRequest(bodyChange)
103
+ const response = await this.pushChangeRequest(bodyChange)
104
+ const deviceStatus: any = response.body
104
105
  await this.pushStatusCodes(deviceStatus)
105
106
  if (await this.successfulStatusCodes(deviceStatus)) {
106
107
  await this.successfulPushChange(deviceStatus, bodyChange)
@@ -191,7 +191,8 @@ export class IRFan extends irdeviceBase {
191
191
  if (this.device.connectionType === 'OpenAPI') {
192
192
  this.infoLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)}`)
193
193
  try {
194
- const deviceStatus = await this.pushChangeRequest(bodyChange)
194
+ const response = await this.pushChangeRequest(bodyChange)
195
+ const deviceStatus: any = response.body
195
196
  await this.pushStatusCodes(deviceStatus)
196
197
  if (await this.successfulStatusCodes(deviceStatus)) {
197
198
  await this.successfulPushChange(deviceStatus, bodyChange)
@@ -198,12 +198,12 @@ export abstract class irdeviceBase {
198
198
  }
199
199
  }
200
200
 
201
- async pushStatusCodes<T extends { statusCode: number }>(deviceStatus: T) {
201
+ async pushStatusCodes(deviceStatus: any) {
202
202
  this.debugWarnLog(`deviceStatus: ${JSON.stringify(deviceStatus)}`)
203
203
  this.debugWarnLog(`deviceStatus statusCode: ${deviceStatus.statusCode}`)
204
204
  }
205
205
 
206
- async successfulPushChange<T extends { statusCode: number }>(deviceStatus: T, bodyChange: any) {
206
+ async successfulPushChange(deviceStatus: any, bodyChange: any) {
207
207
  this.debugSuccessLog(`deviceStatus StatusCode: ${deviceStatus.statusCode}`)
208
208
  this.successLog(`request to SwitchBot API, body: ${JSON.stringify(bodyChange)} sent successfully`)
209
209
  }
@@ -198,7 +198,8 @@ export class Light extends irdeviceBase {
198
198
  if (this.device.connectionType === 'OpenAPI') {
199
199
  this.infoLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)}`)
200
200
  try {
201
- const deviceStatus = await this.pushChangeRequest(bodyChange)
201
+ const response = await this.pushChangeRequest(bodyChange)
202
+ const deviceStatus: any = response.body
202
203
  await this.pushStatusCodes(deviceStatus)
203
204
  if (await this.successfulStatusCodes(deviceStatus)) {
204
205
  await this.successfulPushChange(deviceStatus, bodyChange)
@@ -447,7 +447,8 @@ export class Others extends irdeviceBase {
447
447
  if (this.device.connectionType === 'OpenAPI') {
448
448
  this.infoLog(`Sending request to SwitchBot API, body: ${JSON.stringify(bodyChange)}`)
449
449
  try {
450
- const deviceStatus = await this.pushChangeRequest(bodyChange)
450
+ const response = await this.pushChangeRequest(bodyChange)
451
+ const deviceStatus: any = response.body
451
452
  await this.pushStatusCodes(deviceStatus)
452
453
  if (await this.successfulStatusCodes(deviceStatus)) {
453
454
  await this.successfulPushChange(deviceStatus, bodyChange)