@switchbot/homebridge-switchbot 3.5.1-beta.9 → 3.5.2-beta.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 (158) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/config.schema.json +19 -3
  3. package/dist/device/blindtilt.d.ts +6 -4
  4. package/dist/device/blindtilt.d.ts.map +1 -1
  5. package/dist/device/blindtilt.js +61 -47
  6. package/dist/device/blindtilt.js.map +1 -1
  7. package/dist/device/bot.d.ts +6 -3
  8. package/dist/device/bot.d.ts.map +1 -1
  9. package/dist/device/bot.js +60 -26
  10. package/dist/device/bot.js.map +1 -1
  11. package/dist/device/ceilinglight.d.ts +6 -3
  12. package/dist/device/ceilinglight.d.ts.map +1 -1
  13. package/dist/device/ceilinglight.js +48 -30
  14. package/dist/device/ceilinglight.js.map +1 -1
  15. package/dist/device/colorbulb.d.ts +6 -3
  16. package/dist/device/colorbulb.d.ts.map +1 -1
  17. package/dist/device/colorbulb.js +54 -37
  18. package/dist/device/colorbulb.js.map +1 -1
  19. package/dist/device/contact.d.ts +6 -3
  20. package/dist/device/contact.d.ts.map +1 -1
  21. package/dist/device/contact.js +46 -32
  22. package/dist/device/contact.js.map +1 -1
  23. package/dist/device/curtain.d.ts +6 -4
  24. package/dist/device/curtain.d.ts.map +1 -1
  25. package/dist/device/curtain.js +42 -28
  26. package/dist/device/curtain.js.map +1 -1
  27. package/dist/device/device.d.ts +7 -4
  28. package/dist/device/device.d.ts.map +1 -1
  29. package/dist/device/device.js +61 -152
  30. package/dist/device/device.js.map +1 -1
  31. package/dist/device/fan.d.ts +6 -3
  32. package/dist/device/fan.d.ts.map +1 -1
  33. package/dist/device/fan.js +54 -33
  34. package/dist/device/fan.js.map +1 -1
  35. package/dist/device/hub.d.ts +6 -3
  36. package/dist/device/hub.d.ts.map +1 -1
  37. package/dist/device/hub.js +50 -31
  38. package/dist/device/hub.js.map +1 -1
  39. package/dist/device/humidifier.d.ts +6 -3
  40. package/dist/device/humidifier.d.ts.map +1 -1
  41. package/dist/device/humidifier.js +48 -29
  42. package/dist/device/humidifier.js.map +1 -1
  43. package/dist/device/iosensor.d.ts +6 -3
  44. package/dist/device/iosensor.d.ts.map +1 -1
  45. package/dist/device/iosensor.js +45 -28
  46. package/dist/device/iosensor.js.map +1 -1
  47. package/dist/device/lightstrip.d.ts +6 -3
  48. package/dist/device/lightstrip.d.ts.map +1 -1
  49. package/dist/device/lightstrip.js +47 -29
  50. package/dist/device/lightstrip.js.map +1 -1
  51. package/dist/device/lock.d.ts +6 -3
  52. package/dist/device/lock.d.ts.map +1 -1
  53. package/dist/device/lock.js +39 -26
  54. package/dist/device/lock.js.map +1 -1
  55. package/dist/device/meter.d.ts +6 -3
  56. package/dist/device/meter.d.ts.map +1 -1
  57. package/dist/device/meter.js +44 -28
  58. package/dist/device/meter.js.map +1 -1
  59. package/dist/device/meterplus.d.ts +6 -3
  60. package/dist/device/meterplus.d.ts.map +1 -1
  61. package/dist/device/meterplus.js +43 -28
  62. package/dist/device/meterplus.js.map +1 -1
  63. package/dist/device/motion.d.ts +6 -3
  64. package/dist/device/motion.d.ts.map +1 -1
  65. package/dist/device/motion.js +38 -25
  66. package/dist/device/motion.js.map +1 -1
  67. package/dist/device/plug.d.ts +6 -3
  68. package/dist/device/plug.d.ts.map +1 -1
  69. package/dist/device/plug.js +31 -18
  70. package/dist/device/plug.js.map +1 -1
  71. package/dist/device/robotvacuumcleaner.d.ts +6 -3
  72. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  73. package/dist/device/robotvacuumcleaner.js +38 -23
  74. package/dist/device/robotvacuumcleaner.js.map +1 -1
  75. package/dist/device/waterdetector.d.ts +6 -3
  76. package/dist/device/waterdetector.d.ts.map +1 -1
  77. package/dist/device/waterdetector.js +44 -27
  78. package/dist/device/waterdetector.js.map +1 -1
  79. package/dist/homebridge-ui/public/index.html +2 -2
  80. package/dist/irdevice/airconditioner.d.ts +1 -3
  81. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  82. package/dist/irdevice/airconditioner.js +67 -177
  83. package/dist/irdevice/airconditioner.js.map +1 -1
  84. package/dist/irdevice/airpurifier.d.ts +0 -1
  85. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  86. package/dist/irdevice/airpurifier.js +24 -53
  87. package/dist/irdevice/airpurifier.js.map +1 -1
  88. package/dist/irdevice/camera.d.ts.map +1 -1
  89. package/dist/irdevice/camera.js +12 -17
  90. package/dist/irdevice/camera.js.map +1 -1
  91. package/dist/irdevice/fan.d.ts.map +1 -1
  92. package/dist/irdevice/fan.js +22 -38
  93. package/dist/irdevice/fan.js.map +1 -1
  94. package/dist/irdevice/irdevice.d.ts +22 -10
  95. package/dist/irdevice/irdevice.d.ts.map +1 -1
  96. package/dist/irdevice/irdevice.js +94 -100
  97. package/dist/irdevice/irdevice.js.map +1 -1
  98. package/dist/irdevice/light.d.ts.map +1 -1
  99. package/dist/irdevice/light.js +20 -38
  100. package/dist/irdevice/light.js.map +1 -1
  101. package/dist/irdevice/other.d.ts.map +1 -1
  102. package/dist/irdevice/other.js +79 -77
  103. package/dist/irdevice/other.js.map +1 -1
  104. package/dist/irdevice/tv.d.ts.map +1 -1
  105. package/dist/irdevice/tv.js +38 -53
  106. package/dist/irdevice/tv.js.map +1 -1
  107. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  108. package/dist/irdevice/vacuumcleaner.js +11 -16
  109. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  110. package/dist/irdevice/waterheater.d.ts.map +1 -1
  111. package/dist/irdevice/waterheater.js +11 -16
  112. package/dist/irdevice/waterheater.js.map +1 -1
  113. package/dist/platform.d.ts +4 -6
  114. package/dist/platform.d.ts.map +1 -1
  115. package/dist/platform.js +564 -665
  116. package/dist/platform.js.map +1 -1
  117. package/dist/settings.d.ts +10 -8
  118. package/dist/settings.d.ts.map +1 -1
  119. package/dist/settings.js.map +1 -1
  120. package/dist/types/bledevicestatus.d.ts +2 -1
  121. package/dist/types/bledevicestatus.d.ts.map +1 -1
  122. package/dist/types/devicestatus.d.ts +1 -1
  123. package/dist/types/devicestatus.d.ts.map +1 -1
  124. package/package.json +14 -14
  125. package/src/device/blindtilt.ts +65 -49
  126. package/src/device/bot.ts +80 -27
  127. package/src/device/ceilinglight.ts +58 -32
  128. package/src/device/colorbulb.ts +58 -44
  129. package/src/device/contact.ts +50 -32
  130. package/src/device/curtain.ts +52 -29
  131. package/src/device/device.ts +63 -135
  132. package/src/device/fan.ts +68 -34
  133. package/src/device/hub.ts +63 -34
  134. package/src/device/humidifier.ts +61 -34
  135. package/src/device/iosensor.ts +52 -31
  136. package/src/device/lightstrip.ts +53 -30
  137. package/src/device/lock.ts +56 -27
  138. package/src/device/meter.ts +61 -30
  139. package/src/device/meterplus.ts +57 -30
  140. package/src/device/motion.ts +51 -27
  141. package/src/device/plug.ts +39 -19
  142. package/src/device/robotvacuumcleaner.ts +54 -25
  143. package/src/device/waterdetector.ts +63 -29
  144. package/src/homebridge-ui/public/index.html +2 -2
  145. package/src/irdevice/airconditioner.ts +76 -165
  146. package/src/irdevice/airpurifier.ts +29 -49
  147. package/src/irdevice/camera.ts +13 -16
  148. package/src/irdevice/fan.ts +25 -35
  149. package/src/irdevice/irdevice.ts +97 -96
  150. package/src/irdevice/light.ts +21 -35
  151. package/src/irdevice/other.ts +79 -77
  152. package/src/irdevice/tv.ts +40 -51
  153. package/src/irdevice/vacuumcleaner.ts +12 -15
  154. package/src/irdevice/waterheater.ts +12 -15
  155. package/src/platform.ts +566 -696
  156. package/src/settings.ts +11 -8
  157. package/src/types/bledevicestatus.ts +4 -2
  158. package/src/types/devicestatus.ts +1 -1
@@ -36,6 +36,15 @@ export class WaterDetector extends deviceBase {
36
36
  LeakDetected: CharacteristicValue;
37
37
  };
38
38
 
39
+ // OpenAPI
40
+ deviceStatus!: waterLeakDetectorStatus;
41
+
42
+ //Webhook
43
+ webhookContext!: waterLeakDetectorWebhookContext;
44
+
45
+ // BLE
46
+ serviceData!: waterLeakDetectorServiceData;
47
+
39
48
  // Updates
40
49
  WaterDetectorUpdateInProgress!: boolean;
41
50
  doWaterDetectorUpdate: Subject<void>;
@@ -46,6 +55,9 @@ export class WaterDetector extends deviceBase {
46
55
  device: device & devicesConfig,
47
56
  ) {
48
57
  super(platform, accessory, device);
58
+ // Set category
59
+ accessory.category = this.hap.Categories.SENSOR;
60
+
49
61
  // this is subject we use to track when we need to POST changes to the SwitchBot API
50
62
  this.doWaterDetectorUpdate = new Subject();
51
63
  this.WaterDetectorUpdateInProgress = false;
@@ -79,11 +91,11 @@ export class WaterDetector extends deviceBase {
79
91
  // Initialize Leak Sensor Service
80
92
  if (device.waterdetector?.hide_leak) {
81
93
  if (this.LeakSensor) {
82
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leak Sensor Service`);
94
+ this.debugLog('Removing Leak Sensor Service');
83
95
  this.LeakSensor.Service = this.accessory.getService(this.hap.Service.LeakSensor) as Service;
84
96
  accessory.removeService(this.LeakSensor.Service);
85
97
  } else {
86
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Leak Sensor Service Not Found`);
98
+ this.debugLog('Leak Sensor Service Not Found');
87
99
  }
88
100
  } else {
89
101
  accessory.context.LeakSensor = accessory.context.LeakSensor ?? {};
@@ -106,13 +118,11 @@ export class WaterDetector extends deviceBase {
106
118
  }
107
119
 
108
120
  // Retrieve initial values and updateHomekit
109
- this.debugLog('retrieve initial values and Update Homekit');
121
+ this.debugLog('Retrieve initial values and update Homekit');
110
122
  this.refreshStatus();
111
123
 
112
- // Retrieve initial values and updateHomekit
113
- this.updateHomeKitCharacteristics();
114
-
115
124
  //regisiter webhook event handler
125
+ this.debugLog('Registering Webhook Event Handler');
116
126
  this.registerWebhook();
117
127
 
118
128
  // Start an update interval
@@ -124,18 +134,24 @@ export class WaterDetector extends deviceBase {
124
134
  });
125
135
  }
126
136
 
127
- async BLEparseStatus(serviceData: waterLeakDetectorServiceData): Promise<void> {
137
+ async BLEparseStatus(): Promise<void> {
128
138
  await this.debugLog('BLEparseStatus');
139
+ await this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}),`
140
+ + ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
141
+
142
+ //LeakSensor
129
143
  if (this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
144
+
130
145
  // StatusActive
131
- this.LeakSensor.StatusActive = serviceData.state;
146
+ this.LeakSensor.StatusActive = this.serviceData.state;
132
147
  await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
148
+
133
149
  // LeakDetected
134
- this.LeakSensor.LeakDetected = serviceData.status;
150
+ this.LeakSensor.LeakDetected = this.serviceData.status;
135
151
  this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
136
152
  }
137
153
  // BatteryLevel
138
- this.Battery.BatteryLevel = Number(serviceData.battery);
154
+ this.Battery.BatteryLevel = this.serviceData.battery;
139
155
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
140
156
  // StatusLowBattery
141
157
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
@@ -143,27 +159,36 @@ export class WaterDetector extends deviceBase {
143
159
  await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
144
160
  }
145
161
 
146
- async openAPIparseStatus(deviceStatus: waterLeakDetectorStatus): Promise<void> {
162
+ async openAPIparseStatus(): Promise<void> {
147
163
  await this.debugLog('openAPIparseStatus');
164
+ await this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}),`
165
+ + ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
166
+
167
+ //LeakSensor
148
168
  if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
169
+
149
170
  // StatusActive
150
- this.LeakSensor.StatusActive = deviceStatus.battery === 0 ? false : true;
171
+ this.LeakSensor.StatusActive = this.deviceStatus.battery === 0 ? false : true;
151
172
  await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
173
+
152
174
  // LeakDetected
153
- this.LeakSensor.LeakDetected = deviceStatus.status;
175
+ this.LeakSensor.LeakDetected = this.deviceStatus.status;
154
176
  this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
155
177
  }
178
+
156
179
  // BatteryLevel
157
- this.Battery.BatteryLevel = Number(deviceStatus.battery);
180
+ this.Battery.BatteryLevel = this.deviceStatus.battery;
158
181
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
182
+
159
183
  // StatusLowBattery
160
184
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
161
185
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
162
186
  await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
187
+
163
188
  // FirmwareVersion
164
- const version = deviceStatus.version.toString();
165
- await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
166
- if (deviceStatus.version) {
189
+ if (this.deviceStatus.version) {
190
+ const version = this.deviceStatus.version.toString();
191
+ await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`);
167
192
  const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
168
193
  this.accessory
169
194
  .getService(this.hap.Service.AccessoryInformation)!
@@ -171,26 +196,32 @@ export class WaterDetector extends deviceBase {
171
196
  .setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
172
197
  .getCharacteristic(this.hap.Characteristic.FirmwareRevision)
173
198
  .updateValue(deviceVersion);
174
- this.accessory.context.deviceVersion = deviceVersion;
175
- await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
199
+ this.accessory.context.version = deviceVersion;
200
+ await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
176
201
  }
177
202
  }
178
203
 
179
- async parseStatusWebhook(context: waterLeakDetectorWebhookContext): Promise<void> {
204
+ async parseStatusWebhook(): Promise<void> {
180
205
  await this.debugLog('parseStatusWebhook');
181
- await this.debugLog(`(detectionState, battery) = Webhook: (${context.detectionState}, ${context.battery}),`
206
+ await this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}),`
182
207
  + ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
208
+
209
+ //LeakSensor
183
210
  if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
211
+
184
212
  // StatusActive
185
- this.LeakSensor.StatusActive = context.detectionState ? true : false;
213
+ this.LeakSensor.StatusActive = this.webhookContext.detectionState ? true : false;
186
214
  await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
215
+
187
216
  // LeakDetected
188
- this.LeakSensor.LeakDetected = context.detectionState;
217
+ this.LeakSensor.LeakDetected = this.webhookContext.detectionState;
189
218
  await this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
190
219
  }
220
+
191
221
  // BatteryLevel
192
- this.Battery.BatteryLevel = Number(context.battery);
222
+ this.Battery.BatteryLevel = this.webhookContext.battery;
193
223
  await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
224
+
194
225
  // StatusLowBattery
195
226
  this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
196
227
  ? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
@@ -223,10 +254,11 @@ export class WaterDetector extends deviceBase {
223
254
  // Start to monitor advertisement packets
224
255
  (async () => {
225
256
  // Start to monitor advertisement packets
226
- const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as waterLeakDetectorServiceData;
257
+ const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
227
258
  // Update HomeKit
228
259
  if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
229
- await this.BLEparseStatus(serviceData);
260
+ this.serviceData = serviceData;
261
+ await this.BLEparseStatus();
230
262
  await this.updateHomeKitCharacteristics();
231
263
  } else {
232
264
  await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
@@ -244,7 +276,8 @@ export class WaterDetector extends deviceBase {
244
276
  await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
245
277
  if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
246
278
  await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
247
- await this.openAPIparseStatus(deviceStatus.body);
279
+ this.deviceStatus = deviceStatus.body;
280
+ await this.openAPIparseStatus();
248
281
  await this.updateHomeKitCharacteristics();
249
282
  } else {
250
283
  await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
@@ -262,7 +295,8 @@ export class WaterDetector extends deviceBase {
262
295
  this.platform.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
263
296
  try {
264
297
  await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
265
- await this.parseStatusWebhook(context);
298
+ this.webhookContext = context;
299
+ await this.parseStatusWebhook();
266
300
  await this.updateHomeKitCharacteristics();
267
301
  } catch (e: any) {
268
302
  await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
@@ -294,7 +328,7 @@ export class WaterDetector extends deviceBase {
294
328
  }
295
329
 
296
330
  async BLERefreshConnection(switchbot: any): Promise<void> {
297
- await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
331
+ await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
298
332
  if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
299
333
  await this.warnLog('Using OpenAPI Connection to Refresh Status');
300
334
  await this.openAPIRefreshStatus();
@@ -51,7 +51,7 @@
51
51
  <tbody>
52
52
  <tr>
53
53
  <th scope="row">Device ID</th>
54
- <td id="deviceID"></td>
54
+ <td id="deviceId"></td>
55
55
  </tr>
56
56
  <tr>
57
57
  <th scope="row">Model</th>
@@ -166,7 +166,7 @@
166
166
  const thisAcc = cachedAccessories.find((x) => x.UUID === UUID);
167
167
  const context = thisAcc.context;
168
168
  document.getElementById('displayName').innerHTML = thisAcc.displayName;
169
- document.getElementById('deviceID').innerHTML = context.deviceID;
169
+ document.getElementById('deviceId').innerHTML = context.deviceId;
170
170
  document.getElementById('model').innerHTML = context.model;
171
171
  document.getElementById('version').innerHTML = context.version;
172
172
  document.getElementById('deviceType').innerHTML = context.deviceType;