@switchbot/homebridge-switchbot 1.2.1-beta.5 → 1.2.3

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 (38) hide show
  1. package/.github/workflows/nodejs.yml +1 -1
  2. package/CHANGELOG.md +19 -2
  3. package/config.schema.json +1 -1
  4. package/dist/devices/bots.d.ts +1 -0
  5. package/dist/devices/bots.d.ts.map +1 -1
  6. package/dist/devices/bots.js +21 -4
  7. package/dist/devices/bots.js.map +1 -1
  8. package/dist/devices/contact.d.ts +1 -0
  9. package/dist/devices/contact.d.ts.map +1 -1
  10. package/dist/devices/contact.js +21 -4
  11. package/dist/devices/contact.js.map +1 -1
  12. package/dist/devices/curtains.d.ts +1 -0
  13. package/dist/devices/curtains.d.ts.map +1 -1
  14. package/dist/devices/curtains.js +21 -4
  15. package/dist/devices/curtains.js.map +1 -1
  16. package/dist/devices/humidifiers.d.ts +1 -0
  17. package/dist/devices/humidifiers.d.ts.map +1 -1
  18. package/dist/devices/humidifiers.js +21 -4
  19. package/dist/devices/humidifiers.js.map +1 -1
  20. package/dist/devices/meters.d.ts +1 -0
  21. package/dist/devices/meters.d.ts.map +1 -1
  22. package/dist/devices/meters.js +34 -9
  23. package/dist/devices/meters.js.map +1 -1
  24. package/dist/devices/motion.d.ts +1 -0
  25. package/dist/devices/motion.d.ts.map +1 -1
  26. package/dist/devices/motion.js +21 -4
  27. package/dist/devices/motion.js.map +1 -1
  28. package/dist/platform.d.ts.map +1 -1
  29. package/dist/platform.js +6 -0
  30. package/dist/platform.js.map +1 -1
  31. package/package.json +66 -66
  32. package/src/devices/bots.ts +21 -4
  33. package/src/devices/contact.ts +21 -4
  34. package/src/devices/curtains.ts +21 -4
  35. package/src/devices/humidifiers.ts +21 -4
  36. package/src/devices/meters.ts +32 -9
  37. package/src/devices/motion.ts +21 -4
  38. package/src/platform.ts +6 -0
@@ -29,6 +29,7 @@ export class Meter {
29
29
  deviceStatus!: deviceStatusResponse;
30
30
 
31
31
  // BLE Others
32
+ connected?: boolean;
32
33
  switchbot!: switchbot;
33
34
  serviceData!: serviceData;
34
35
  battery!: serviceData['battery'];
@@ -190,8 +191,14 @@ export class Meter {
190
191
 
191
192
  // Current Temperature
192
193
  if (!this.device.meter?.hide_temperature) {
193
- this.CurrentTemperature = Number(this.temperature);
194
- this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c, fahrenheit: ${this.fahrenheit}`);
194
+ if (this.device.meter?.unit === 1) {
195
+ this.CurrentTemperature = this.toFahrenheit(this.temperature!.c);
196
+ } else if (this.device.meter?.unit === 0) {
197
+ this.CurrentTemperature = this.toCelsius(this.temperature!.c);
198
+ } else {
199
+ this.CurrentTemperature = Number(this.temperature?.c);
200
+ }
201
+ this.platform.debug(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
195
202
  }
196
203
  }
197
204
 
@@ -242,7 +249,7 @@ export class Meter {
242
249
  private connectBLE() {
243
250
  const switchbot = new Switchbot();
244
251
  this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
245
- this.platform.log.error(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
252
+ this.platform.device(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
246
253
  return switchbot;
247
254
  }
248
255
 
@@ -252,7 +259,7 @@ export class Meter {
252
259
  const switchbot = this.connectBLE();
253
260
  // Start to monitor advertisement packets
254
261
  switchbot.startScan({
255
- model: 'e',
262
+ model: 'T',
256
263
  id: this.device.bleMac,
257
264
  }).then(() => {
258
265
  // Set an event hander
@@ -264,16 +271,32 @@ export class Meter {
264
271
  this.battery = ad.serviceData.battery;
265
272
  this.platform.device(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
266
273
  this.platform.device(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
267
- + `temperature: ${ad.serviceData.temperature}, fahrenheit: ${ad.serviceData.fahrenheit}, humidity: ${ad.serviceData.humidity}, `
268
- + `battery: ${ad.serviceData.battery}`);
274
+ + `temperature: ${JSON.stringify(ad.serviceData.temperature)}, fahrenheit: ${ad.serviceData.fahrenheit}, `
275
+ + `humidity: ${ad.serviceData.humidity}, battery: ${ad.serviceData.battery}`);
276
+
277
+ if (this.serviceData) {
278
+ this.connected = true;
279
+ this.platform.device(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
280
+ } else {
281
+ this.connected = false;
282
+ this.platform.device(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
283
+ }
269
284
  };
270
285
  // Wait 10 seconds
271
286
  return switchbot.wait(10000);
272
- }).then(() => {
287
+ }).then(async () => {
273
288
  // Stop to monitor
274
289
  switchbot.stopScan();
275
- this.parseStatus();
276
- this.updateHomeKitCharacteristics();
290
+ if (this.connected) {
291
+ this.parseStatus();
292
+ this.updateHomeKitCharacteristics();
293
+ } else {
294
+ this.platform.log.error(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
295
+ if (this.platform.config.credentials?.openToken) {
296
+ this.platform.log.warn(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
297
+ await this.openAPIRefreshStatus();
298
+ }
299
+ }
277
300
  }).catch(async (e: any) => {
278
301
  this.platform.log.error(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
279
302
  if (this.deviceDebug) {
@@ -26,6 +26,7 @@ export class Motion {
26
26
  deviceStatus!: deviceStatusResponse;
27
27
 
28
28
  // BLE Others
29
+ connected?: boolean;
29
30
  switchbot!: switchbot;
30
31
  serviceData!: serviceData;
31
32
  battery!: serviceData['battery'];
@@ -163,7 +164,7 @@ export class Motion {
163
164
  private connectBLE() {
164
165
  const switchbot = new Switchbot();
165
166
  this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
166
- this.platform.log.error(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
167
+ this.platform.device(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
167
168
  return switchbot;
168
169
  }
169
170
 
@@ -185,14 +186,30 @@ export class Motion {
185
186
  this.platform.device(`Motion Sensor: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
186
187
  this.platform.device(`Motion Sensor: ${this.accessory.displayName} movement: ${ad.serviceData.movement}, lightLevel: `
187
188
  + `${ad.serviceData.lightLevel}, battery: ${ad.serviceData.battery}`);
189
+
190
+ if (this.serviceData) {
191
+ this.connected = true;
192
+ this.platform.device(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
193
+ } else {
194
+ this.connected = false;
195
+ this.platform.device(`Motion Sensor: ${this.accessory.displayName} connected: ${this.connected}`);
196
+ }
188
197
  };
189
198
  // Wait 10 seconds
190
199
  return switchbot.wait(10000);
191
- }).then(() => {
200
+ }).then(async () => {
192
201
  // Stop to monitor
193
202
  switchbot.stopScan();
194
- this.parseStatus();
195
- this.updateHomeKitCharacteristics();
203
+ if (this.connected) {
204
+ this.parseStatus();
205
+ this.updateHomeKitCharacteristics();
206
+ } else {
207
+ this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
208
+ if (this.platform.config.credentials?.openToken) {
209
+ this.platform.log.warn(`Motion Sensor: ${this.accessory.displayName} Using OpenAPI Connection`);
210
+ await this.openAPIRefreshStatus();
211
+ }
212
+ }
196
213
  }).catch(async (e: any) => {
197
214
  this.platform.log.error(`Motion Sensor: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
198
215
  if (this.deviceDebug) {
package/src/platform.ts CHANGED
@@ -192,6 +192,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
192
192
  const devices = deviceLists.map((v: any) => v);
193
193
  for (const device of devices) {
194
194
  if (device.deviceType) {
195
+ if (device.configDeviceName) {
196
+ device.deviceName = device.configDeviceName;
197
+ }
195
198
  this.createDevice(device);
196
199
  }
197
200
  }
@@ -209,6 +212,9 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
209
212
  this.debug(`SwitchBot Devices: ${JSON.stringify(devices)}`);
210
213
  for (const device of devices) {
211
214
  if (device.deviceType) {
215
+ if (device.configDeviceName) {
216
+ device.deviceName = device.configDeviceName;
217
+ }
212
218
  this.createDevice(device);
213
219
  }
214
220
  }