@switchbot/homebridge-switchbot 1.6.0 → 1.6.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.
package/package.json CHANGED
@@ -1,72 +1,74 @@
1
1
  {
2
- "displayName": "Homebridge SwitchBot",
3
- "name": "@switchbot/homebridge-switchbot",
4
- "version": "1.6.0",
5
- "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
6
- "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
7
- "license": "ISC",
8
- "repository": {
9
- "type": "git",
10
- "url": "git://github.com/OpenWonderLabs/homebridge-switchbot.git"
11
- },
12
- "bugs": {
13
- "url": "https://github.com/OpenWonderLabs/homebridge-switchbot/issues"
14
- },
15
- "engines": {
16
- "homebridge": "^1.3.9",
17
- "node": "^14.18.2 || ^16.13.1"
18
- },
19
- "main": "dist/index.js",
20
- "scripts": {
21
- "check": "npm install && npm outdated",
22
- "update": "ncu -u && npm update && npm install",
23
- "lint": "eslint src/**.ts",
24
- "watch": "npm run build && npm link && nodemon",
25
- "build": "rimraf ./dist && tsc",
26
- "prepublishOnly": "npm run lint && npm run build"
27
- },
28
- "funding": [
29
- {
30
- "type": "Paypal",
31
- "url": "https://paypal.me/donavanbecker"
2
+ "displayName": "Homebridge SwitchBot",
3
+ "name": "@switchbot/homebridge-switchbot",
4
+ "version": "1.6.2-beta.0",
5
+ "description": "The [Homebridge](https://homebridge.io) SwitchBot plugin allows you to access your [SwitchBot](https://www.switch-bot.com) device(s) from HomeKit.",
6
+ "author": "SwitchBot <support@wondertechlabs.com> (https://github.com/SwitchBot)",
7
+ "license": "ISC",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git://github.com/OpenWonderLabs/homebridge-switchbot.git"
32
11
  },
33
- {
34
- "type": "GitHub",
35
- "url": "https://github.com/sponsors/donavanbecker"
12
+ "bugs": {
13
+ "url": "https://github.com/OpenWonderLabs/homebridge-switchbot/issues"
14
+ },
15
+ "engines": {
16
+ "homebridge": "^1.3.9",
17
+ "node": "^14.18.2 || ^16.13.1"
18
+ },
19
+ "main": "dist/index.js",
20
+ "scripts": {
21
+ "check": "npm install && npm outdated",
22
+ "update": "ncu -u && npm update && npm install",
23
+ "lint": "eslint src/**.ts",
24
+ "watch": "npm run build && npm link && nodemon",
25
+ "build": "rimraf ./dist && tsc",
26
+ "prepublishOnly": "npm run lint && npm run build"
27
+ },
28
+ "funding": [
29
+ {
30
+ "type": "Paypal",
31
+ "url": "https://paypal.me/donavanbecker"
32
+ },
33
+ {
34
+ "type": "GitHub",
35
+ "url": "https://github.com/sponsors/donavanbecker"
36
+ }
37
+ ],
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "keywords": [
42
+ "homebridge-plugin",
43
+ "switchbot",
44
+ "humidifier",
45
+ "humidity",
46
+ "temperature",
47
+ "bot",
48
+ "curtains",
49
+ "windows",
50
+ "ble",
51
+ "ir"
52
+ ],
53
+ "dependencies": {
54
+ "@homebridge/plugin-ui-utils": "^0.0.19",
55
+ "axios": "^0.24.0",
56
+ "rxjs": "^7.5.1"
57
+ },
58
+ "devDependencies": {
59
+ "@types/node": "^17.0.6",
60
+ "@typescript-eslint/eslint-plugin": "^5.8.1",
61
+ "@typescript-eslint/parser": "^5.8.1",
62
+ "eslint": "^8.6.0",
63
+ "homebridge": "^1.3.9",
64
+ "nodemon": "^2.0.15",
65
+ "npm-check-updates": "^12.1.0",
66
+ "rimraf": "^3.0.2",
67
+ "ts-node": "^10.4.0",
68
+ "typescript": "^4.5.4",
69
+ "typescript-axios-wb": "^1.0.3"
70
+ },
71
+ "optionalDependencies": {
72
+ "node-switchbot": "^1.1.2"
36
73
  }
37
- ],
38
- "publishConfig": {
39
- "access": "public"
40
- },
41
- "keywords": [
42
- "homebridge-plugin",
43
- "switchbot",
44
- "humidifier",
45
- "humidity",
46
- "temperature",
47
- "bot",
48
- "curtains",
49
- "windows",
50
- "ble",
51
- "ir"
52
- ],
53
- "dependencies": {
54
- "@homebridge/plugin-ui-utils": "^0.0.19",
55
- "axios": "^0.24.0",
56
- "node-switchbot": "^1.1.2",
57
- "rxjs": "^7.5.1"
58
- },
59
- "devDependencies": {
60
- "@types/node": "^17.0.5",
61
- "@typescript-eslint/eslint-plugin": "^5.8.1",
62
- "@typescript-eslint/parser": "^5.8.1",
63
- "eslint": "^8.5.0",
64
- "homebridge": "^1.3.9",
65
- "nodemon": "^2.0.15",
66
- "npm-check-updates": "^12.0.5",
67
- "rimraf": "^3.0.2",
68
- "ts-node": "^10.4.0",
69
- "typescript": "^4.5.4",
70
- "typescript-axios-wb": "^1.0.3"
71
- }
72
74
  }
@@ -1,6 +1,5 @@
1
1
 
2
2
  import { AxiosResponse } from 'axios';
3
- import Switchbot from 'node-switchbot';
4
3
  import { interval, Subject } from 'rxjs';
5
4
  import { SwitchBotPlatform } from '../platform';
6
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
@@ -325,10 +324,16 @@ export class Bot {
325
324
  }
326
325
 
327
326
  private connectBLE() {
328
- const switchbot = new Switchbot();
329
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
330
- this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
331
- return switchbot;
327
+ let Switchbot: any;
328
+ try {
329
+ Switchbot = require('node-switchbot');
330
+ const switchbot = new Switchbot();
331
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
332
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
333
+ return switchbot;
334
+ } catch (e) {
335
+ Switchbot = false;
336
+ }
332
337
  }
333
338
 
334
339
  private async BLERefreshStatus() {
@@ -36,9 +36,10 @@ export class ColorBulb {
36
36
  set_minStep?: number;
37
37
  deviceLogging!: string;
38
38
  deviceRefreshRate!: number;
39
+ adaptiveLightingShift?: number;
39
40
 
40
41
  // Adaptive Lighting
41
- AdaptiveLightingController: ControllerConstructor | Controller<ControllerServiceMap>;
42
+ AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
42
43
  minKelvin: number;
43
44
  maxKelvin: number;
44
45
 
@@ -55,6 +56,7 @@ export class ColorBulb {
55
56
  // default placeholders
56
57
  this.logs();
57
58
  this.refreshRate();
59
+ this.adaptiveLighting();
58
60
  if (this.On === undefined) {
59
61
  this.On = false;
60
62
  } else {
@@ -68,7 +70,8 @@ export class ColorBulb {
68
70
  this.maxKelvin = 9000;
69
71
 
70
72
  // ColorBulb Config
71
- this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep}`);
73
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} Config: (ble: ${device.ble}, set_minStep: ${device.colorbulb?.set_minStep},`
74
+ + ` adaptiveLighting: ${device.colorbulb?.adaptiveLightingShift})`);
72
75
 
73
76
  // this is subject we use to track when we need to POST changes to the SwitchBot API
74
77
  this.doColorBulbUpdate = new Subject();
@@ -85,12 +88,20 @@ export class ColorBulb {
85
88
  .setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
86
89
  .setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
87
90
 
88
- // get the Television service if it exists, otherwise create a new Television service
91
+ // get the Lightbulb service if it exists, otherwise create a new Lightbulb service
89
92
  // you can create multiple services for each accessory
90
93
  (this.service =
91
94
  accessory.getService(this.platform.Service.Lightbulb) ||
92
95
  accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
93
96
 
97
+
98
+ if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
99
+ this.accessory.removeService(this.service);
100
+ this.service = this.accessory.addService(this.platform.Service.Lightbulb);
101
+ this.accessory.context.adaptiveLighting = false;
102
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
103
+ }
104
+
94
105
  // To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
95
106
  // when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
96
107
  // accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Outlet, 'NAME', 'USER_DEFINED_SUBTYPE');
@@ -153,11 +164,17 @@ export class ColorBulb {
153
164
  })
154
165
  .onSet(this.SaturationSet.bind(this));
155
166
 
156
- const adaptiveLightingShift = device.colorbulb?.adaptiveLightingShift || 0;
157
- this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
158
- customTemperatureAdjustment: adaptiveLightingShift,
159
- });
160
- this.accessory.configureController(this.AdaptiveLightingController);
167
+
168
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
169
+ if (this.adaptiveLightingShift !== -1) {
170
+ this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
171
+ customTemperatureAdjustment: this.adaptiveLightingShift,
172
+ });
173
+ this.accessory.configureController(this.AdaptiveLightingController);
174
+ this.accessory.context.adaptiveLighting = true;
175
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
176
+ + ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
177
+ }
161
178
 
162
179
  // Update Homekit
163
180
  this.updateHomeKitCharacteristics();
@@ -230,6 +247,16 @@ export class ColorBulb {
230
247
  }
231
248
  }
232
249
 
250
+ adaptiveLighting() {
251
+ if (this.device.colorbulb?.adaptiveLightingShift) {
252
+ this.adaptiveLightingShift = this.device.colorbulb.adaptiveLightingShift;
253
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
254
+ } else {
255
+ this.adaptiveLightingShift = 0;
256
+ this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
257
+ }
258
+ }
259
+
233
260
  private minStep(): number {
234
261
  if (this.device.colorbulb?.set_minStep) {
235
262
  this.set_minStep = this.device.colorbulb?.set_minStep;
@@ -1,4 +1,3 @@
1
- import Switchbot from 'node-switchbot';
2
1
  import { interval, Subject } from 'rxjs';
3
2
  import { skipWhile } from 'rxjs/operators';
4
3
  import { SwitchBotPlatform } from '../platform';
@@ -275,10 +274,16 @@ export class Contact {
275
274
  }
276
275
 
277
276
  private connectBLE() {
278
- const switchbot = new Switchbot();
279
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
280
- this.debugLog(`Contact Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
281
- return switchbot;
277
+ let Switchbot: any;
278
+ try {
279
+ Switchbot = require('node-switchbot');
280
+ const switchbot = new Switchbot();
281
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
282
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
283
+ return switchbot;
284
+ } catch (e) {
285
+ Switchbot = false;
286
+ }
282
287
  }
283
288
 
284
289
  private async BLERefreshStatus() {
@@ -1,6 +1,5 @@
1
1
 
2
2
  import { AxiosResponse } from 'axios';
3
- import Switchbot from 'node-switchbot';
4
3
  import { interval, Subject } from 'rxjs';
5
4
  import { SwitchBotPlatform } from '../platform';
6
5
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
@@ -255,10 +254,16 @@ export class Curtain {
255
254
  }
256
255
 
257
256
  private connectBLE() {
258
- const switchbot = new Switchbot();
259
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
260
- this.debugLog(`Curtain: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
261
- return switchbot;
257
+ let Switchbot: any;
258
+ try {
259
+ Switchbot = require('node-switchbot');
260
+ const switchbot = new Switchbot();
261
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
262
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
263
+ return switchbot;
264
+ } catch (e) {
265
+ Switchbot = false;
266
+ }
262
267
  }
263
268
 
264
269
  private minStep(): number {
@@ -1,5 +1,4 @@
1
1
  import { AxiosResponse } from 'axios';
2
- import Switchbot from 'node-switchbot';
3
2
  import { interval, Subject } from 'rxjs';
4
3
  import { SwitchBotPlatform } from '../platform';
5
4
  import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
@@ -341,10 +340,16 @@ export class Humidifier {
341
340
  }
342
341
 
343
342
  private connectBLE() {
344
- const switchbot = new Switchbot();
345
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
346
- this.debugLog(`Humidifier: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
347
- return switchbot;
343
+ let Switchbot: any;
344
+ try {
345
+ Switchbot = require('node-switchbot');
346
+ const switchbot = new Switchbot();
347
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
348
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
349
+ return switchbot;
350
+ } catch (e) {
351
+ Switchbot = false;
352
+ }
348
353
  }
349
354
 
350
355
  private async BLERefreshStatus() {
@@ -1,4 +1,3 @@
1
- import Switchbot from 'node-switchbot';
2
1
  import { interval, Subject } from 'rxjs';
3
2
  import { skipWhile } from 'rxjs/operators';
4
3
  import { SwitchBotPlatform } from '../platform';
@@ -305,12 +304,19 @@ export class Meter {
305
304
  }
306
305
 
307
306
  private connectBLE() {
308
- const switchbot = new Switchbot();
309
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
310
- this.debugLog(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
311
- return switchbot;
307
+ let Switchbot: any;
308
+ try {
309
+ Switchbot = require('node-switchbot');
310
+ const switchbot = new Switchbot();
311
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
312
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
313
+ return switchbot;
314
+ } catch (e) {
315
+ Switchbot = false;
316
+ }
312
317
  }
313
318
 
319
+
314
320
  private BLErefreshStatus() {
315
321
  this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
316
322
  // eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -1,4 +1,3 @@
1
- import Switchbot from 'node-switchbot';
2
1
  import { interval, Subject } from 'rxjs';
3
2
  import { skipWhile } from 'rxjs/operators';
4
3
  import { SwitchBotPlatform } from '../platform';
@@ -194,10 +193,25 @@ export class Motion {
194
193
  }
195
194
 
196
195
  private async openAPIparseStatus() {
197
- if (this.platform.config.credentials?.openToken) {
198
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
199
- this.MotionDetected = Boolean(this.deviceStatus.body.moveDetected);
200
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
196
+ try {
197
+ if (this.platform.config.credentials?.openToken) {
198
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} OpenAPI parseStatus`);
199
+ if (typeof this.deviceStatus.body.moveDetected === 'boolean') {
200
+ this.MotionDetected = this.deviceStatus.body.moveDetected;
201
+ }
202
+ this.debugLog(`Motion Sensor: ${this.accessory.displayName} MotionDetected: ${this.MotionDetected}`);
203
+ }
204
+ } catch (e: any) {
205
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed parseStatus with OpenAPI Connection`);
206
+ if (this.deviceLogging === 'debug') {
207
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed parseStatus with OpenAPI Connection,`
208
+ + ` Error Message: ${JSON.stringify(e.message)}`);
209
+ }
210
+ if (this.platform.debugMode) {
211
+ this.errorLog(`Motion Sensor: ${this.accessory.displayName} failed parseStatus with OpenAPI Connection,`
212
+ + ` Error: ${JSON.stringify(e)}`);
213
+ }
214
+ this.apiError(e);
201
215
  }
202
216
  }
203
217
 
@@ -213,10 +227,16 @@ export class Motion {
213
227
  }
214
228
 
215
229
  private connectBLE() {
216
- const switchbot = new Switchbot();
217
- this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
218
- this.debugLog(`Motion Sensor: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
219
- return switchbot;
230
+ let Switchbot: any;
231
+ try {
232
+ Switchbot = require('node-switchbot');
233
+ const switchbot = new Switchbot();
234
+ this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
235
+ this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
236
+ return switchbot;
237
+ } catch (e) {
238
+ Switchbot = false;
239
+ }
220
240
  }
221
241
 
222
242
  private async BLERefreshStatus() {