@switchbot/homebridge-switchbot 1.7.1-beta.4 → 1.7.1-beta.8

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 (42) hide show
  1. package/config.schema.json +45 -32
  2. package/dist/devices/bots.d.ts +2 -2
  3. package/dist/devices/bots.d.ts.map +1 -1
  4. package/dist/devices/bots.js +10 -28
  5. package/dist/devices/bots.js.map +1 -1
  6. package/dist/devices/colorbulb.d.ts +5 -1
  7. package/dist/devices/colorbulb.d.ts.map +1 -1
  8. package/dist/devices/colorbulb.js +12 -8
  9. package/dist/devices/colorbulb.js.map +1 -1
  10. package/dist/devices/contact.d.ts +4 -2
  11. package/dist/devices/contact.d.ts.map +1 -1
  12. package/dist/devices/contact.js +13 -34
  13. package/dist/devices/contact.js.map +1 -1
  14. package/dist/devices/curtains.d.ts +5 -2
  15. package/dist/devices/curtains.d.ts.map +1 -1
  16. package/dist/devices/curtains.js +11 -6
  17. package/dist/devices/curtains.js.map +1 -1
  18. package/dist/devices/humidifiers.d.ts +7 -2
  19. package/dist/devices/humidifiers.d.ts.map +1 -1
  20. package/dist/devices/humidifiers.js +22 -35
  21. package/dist/devices/humidifiers.js.map +1 -1
  22. package/dist/devices/meters.d.ts +12 -12
  23. package/dist/devices/meters.d.ts.map +1 -1
  24. package/dist/devices/meters.js +49 -100
  25. package/dist/devices/meters.js.map +1 -1
  26. package/dist/devices/motion.d.ts +3 -4
  27. package/dist/devices/motion.d.ts.map +1 -1
  28. package/dist/devices/motion.js +5 -27
  29. package/dist/devices/motion.js.map +1 -1
  30. package/dist/devices/plugs.d.ts +2 -1
  31. package/dist/devices/plugs.d.ts.map +1 -1
  32. package/dist/devices/plugs.js +2 -1
  33. package/dist/devices/plugs.js.map +1 -1
  34. package/package.json +1 -1
  35. package/src/devices/bots.ts +12 -30
  36. package/src/devices/colorbulb.ts +17 -9
  37. package/src/devices/contact.ts +17 -35
  38. package/src/devices/curtains.ts +16 -8
  39. package/src/devices/humidifiers.ts +29 -36
  40. package/src/devices/meters.ts +63 -110
  41. package/src/devices/motion.ts +8 -30
  42. package/src/devices/plugs.ts +4 -2
@@ -2,7 +2,7 @@ import { interval, Subject } from 'rxjs';
2
2
  import { skipWhile } from 'rxjs/operators';
3
3
  import { SwitchBotPlatform } from '../platform';
4
4
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
5
- import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse } from '../settings';
5
+ import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus } from '../settings';
6
6
 
7
7
  /**
8
8
  * Platform Accessory
@@ -23,6 +23,8 @@ export class Motion {
23
23
 
24
24
  // OpenAPI Others
25
25
  deviceStatus!: deviceStatusResponse;
26
+ moveDetected: deviceStatus['moveDetected'];
27
+ brightness: deviceStatus['brightness'];
26
28
 
27
29
  // BLE Others
28
30
  connected?: boolean;
@@ -43,8 +45,6 @@ export class Motion {
43
45
  // Updates
44
46
  motionUbpdateInProgress!: boolean;
45
47
  doMotionUpdate!: Subject<void>;
46
- moveDetected: boolean | undefined;
47
- brightness: string | number | undefined;
48
48
 
49
49
  constructor(
50
50
  private readonly platform: SwitchBotPlatform,
@@ -115,7 +115,7 @@ export class Motion {
115
115
  this.debugLog(`Motion Sensor: ${accessory.displayName} Removing Battery Service`);
116
116
  this.batteryService = this.accessory.getService(this.platform.Service.Battery);
117
117
  accessory.removeService(this.batteryService!);
118
- } else if (!this.batteryService) {
118
+ } else if (device.ble && !this.batteryService) {
119
119
  this.debugLog(`Motion Sensor: ${accessory.displayName} Add Battery Service`);
120
120
  (this.batteryService =
121
121
  this.accessory.getService(this.platform.Service.Battery) ||
@@ -285,34 +285,12 @@ export class Motion {
285
285
  }
286
286
  }
287
287
 
288
- public async connectBLE() {
289
- let switchbot: any;
290
- try {
291
- // eslint-disable-next-line @typescript-eslint/no-var-requires
292
- const Switchbot = require('node-switchbot');
293
- switchbot = new Switchbot();
294
- // Convert to BLE Address
295
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
296
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
297
- } catch (e: any) {
298
- switchbot = false;
299
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot}`);
300
- if (this.deviceLogging === 'debug') {
301
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
302
- + ` Error Message: ${JSON.stringify(e.message)}`);
303
- }
304
- if (this.platform.debugMode) {
305
- this.errorLog(`Motion Sensor: ${this.accessory.displayName} 'node-switchbot' found: ${switchbot},`
306
- + ` Error: ${JSON.stringify(e)}`);
307
- }
308
- }
309
- return switchbot;
310
- }
311
-
312
288
  private async BLERefreshStatus() {
313
289
  this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE RefreshStatus`);
314
- // eslint-disable-next-line @typescript-eslint/no-var-requires
315
- const switchbot = await this.connectBLE();
290
+ const switchbot = await this.platform.connectBLE();
291
+ // Convert to BLE Address
292
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
293
+ this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
316
294
  // Start to monitor advertisement packets
317
295
  if (switchbot !== false) {
318
296
  switchbot.startScan({
@@ -4,7 +4,7 @@ import { interval, Subject } from 'rxjs';
4
4
  import { SwitchBotPlatform } from '../platform';
5
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
6
6
  import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
7
- import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload } from '../settings';
7
+ import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
8
8
 
9
9
  export class Plug {
10
10
  // Services
@@ -15,6 +15,7 @@ export class Plug {
15
15
  OnCached!: CharacteristicValue;
16
16
 
17
17
  // OpenAPI Others
18
+ power: deviceStatus['power'];
18
19
  deviceStatus!: deviceStatusResponse;
19
20
 
20
21
  // Config
@@ -164,7 +165,7 @@ export class Plug {
164
165
  }
165
166
 
166
167
  parseStatus() {
167
- switch (this.deviceStatus.body.power) {
168
+ switch (this.power) {
168
169
  case 'on':
169
170
  this.On = true;
170
171
  break;
@@ -178,6 +179,7 @@ export class Plug {
178
179
  try {
179
180
  this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
180
181
  this.debugLog(`Plug: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
182
+ this.power = this.deviceStatus.body.power;
181
183
  this.parseStatus();
182
184
  this.updateHomeKitCharacteristics();
183
185
  } catch (e: any) {