@switchbot/homebridge-switchbot 1.12.7-beta.5 → 1.12.7
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/CHANGELOG.md +12 -0
- package/config.schema.json +6 -6
- package/dist/device/bot.js +2 -2
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +0 -6
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +74 -89
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/curtain.js +1 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.js +2 -2
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +1 -21
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +0 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +1 -14
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +76 -0
- package/dist/device/meterplus.d.ts.map +1 -0
- package/dist/device/meterplus.js +464 -0
- package/dist/device/meterplus.js.map +1 -0
- package/dist/device/plug.js +1 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +90 -0
- package/dist/device/striplight.d.ts.map +1 -0
- package/dist/device/striplight.js +487 -0
- package/dist/device/striplight.js.map +1 -0
- package/dist/platform.d.ts +2 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +119 -9
- package/dist/platform.js.map +1 -1
- package/package.json +76 -76
- package/src/device/bot.ts +2 -2
- package/src/device/colorbulb.ts +74 -89
- package/src/device/curtain.ts +1 -1
- package/src/device/humidifier.ts +2 -2
- package/src/device/lock.ts +1 -21
- package/src/device/meter.ts +1 -13
- package/src/device/meterplus.ts +518 -0
- package/src/device/plug.ts +1 -1
- package/src/device/striplight.ts +583 -0
- package/src/platform.ts +127 -9
package/package.json
CHANGED
|
@@ -1,80 +1,80 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
"displayName": "Homebridge SwitchBot",
|
|
3
|
+
"name": "@switchbot/homebridge-switchbot",
|
|
4
|
+
"version": "1.12.7",
|
|
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.4.0",
|
|
17
|
+
"node": "^14.19.0 || ^16.14.0"
|
|
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
|
+
"postpublish": "npm run clean",
|
|
28
|
+
"clean": "rimraf ./dist",
|
|
29
|
+
"test": "eslint src/**.ts"
|
|
30
|
+
},
|
|
31
|
+
"funding": [
|
|
32
|
+
{
|
|
33
|
+
"type": "Paypal",
|
|
34
|
+
"url": "https://paypal.me/donavanbecker"
|
|
11
35
|
},
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
"engines": {
|
|
16
|
-
"homebridge": "^1.4.0",
|
|
17
|
-
"node": "^14.19.0 || ^16.14.0"
|
|
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
|
-
"postpublish": "npm run clean",
|
|
28
|
-
"clean": "rimraf ./dist",
|
|
29
|
-
"test": "eslint src/**.ts"
|
|
30
|
-
},
|
|
31
|
-
"funding": [
|
|
32
|
-
{
|
|
33
|
-
"type": "Paypal",
|
|
34
|
-
"url": "https://paypal.me/donavanbecker"
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
"type": "GitHub",
|
|
38
|
-
"url": "https://github.com/sponsors/donavanbecker"
|
|
39
|
-
}
|
|
40
|
-
],
|
|
41
|
-
"publishConfig": {
|
|
42
|
-
"access": "public"
|
|
43
|
-
},
|
|
44
|
-
"keywords": [
|
|
45
|
-
"homebridge-plugin",
|
|
46
|
-
"switchbot",
|
|
47
|
-
"humidifier",
|
|
48
|
-
"humidity",
|
|
49
|
-
"temperature",
|
|
50
|
-
"bot",
|
|
51
|
-
"curtains",
|
|
52
|
-
"windows",
|
|
53
|
-
"ble",
|
|
54
|
-
"ir"
|
|
55
|
-
],
|
|
56
|
-
"dependencies": {
|
|
57
|
-
"@homebridge/plugin-ui-utils": "^0.0.19",
|
|
58
|
-
"axios": "^0.26.0",
|
|
59
|
-
"rxjs": "^7.5.4"
|
|
60
|
-
},
|
|
61
|
-
"devDependencies": {
|
|
62
|
-
"@types/node": "^17.0.21",
|
|
63
|
-
"@typescript-eslint/eslint-plugin": "^5.13.0",
|
|
64
|
-
"@typescript-eslint/parser": "^5.13.0",
|
|
65
|
-
"eslint": "^8.10.0",
|
|
66
|
-
"eslint-config-prettier": "8.5.0",
|
|
67
|
-
"eslint-plugin-prettier": "4.0.0",
|
|
68
|
-
"homebridge": "^1.4.0",
|
|
69
|
-
"nodemon": "^2.0.15",
|
|
70
|
-
"npm-check-updates": "^12.5.2",
|
|
71
|
-
"prettier": "2.5.1",
|
|
72
|
-
"rimraf": "^3.0.2",
|
|
73
|
-
"ts-node": "^10.6.0",
|
|
74
|
-
"typescript": "^4.6.2",
|
|
75
|
-
"typescript-axios-wb": "^1.0.3"
|
|
76
|
-
},
|
|
77
|
-
"optionalDependencies": {
|
|
78
|
-
"node-switchbot": "^1.2.1-beta.0"
|
|
36
|
+
{
|
|
37
|
+
"type": "GitHub",
|
|
38
|
+
"url": "https://github.com/sponsors/donavanbecker"
|
|
79
39
|
}
|
|
40
|
+
],
|
|
41
|
+
"publishConfig": {
|
|
42
|
+
"access": "public"
|
|
43
|
+
},
|
|
44
|
+
"keywords": [
|
|
45
|
+
"homebridge-plugin",
|
|
46
|
+
"switchbot",
|
|
47
|
+
"humidifier",
|
|
48
|
+
"humidity",
|
|
49
|
+
"temperature",
|
|
50
|
+
"bot",
|
|
51
|
+
"curtains",
|
|
52
|
+
"windows",
|
|
53
|
+
"ble",
|
|
54
|
+
"ir"
|
|
55
|
+
],
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@homebridge/plugin-ui-utils": "^0.0.19",
|
|
58
|
+
"axios": "^0.26.0",
|
|
59
|
+
"rxjs": "^7.5.4"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@types/node": "^17.0.21",
|
|
63
|
+
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
64
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
65
|
+
"eslint": "^8.10.0",
|
|
66
|
+
"eslint-config-prettier": "8.5.0",
|
|
67
|
+
"eslint-plugin-prettier": "4.0.0",
|
|
68
|
+
"homebridge": "^1.4.0",
|
|
69
|
+
"nodemon": "^2.0.15",
|
|
70
|
+
"npm-check-updates": "^12.5.2",
|
|
71
|
+
"prettier": "2.5.1",
|
|
72
|
+
"rimraf": "^3.0.2",
|
|
73
|
+
"ts-node": "^10.7.0",
|
|
74
|
+
"typescript": "^4.6.2",
|
|
75
|
+
"typescript-axios-wb": "^1.0.3"
|
|
76
|
+
},
|
|
77
|
+
"optionalDependencies": {
|
|
78
|
+
"node-switchbot": "^1.2.0"
|
|
79
|
+
}
|
|
80
80
|
}
|
package/src/device/bot.ts
CHANGED
|
@@ -95,7 +95,7 @@ export class Bot {
|
|
|
95
95
|
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-BOT-S1')
|
|
96
96
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
97
97
|
|
|
98
|
-
// get the
|
|
98
|
+
// get the service if it exists, otherwise create a new service
|
|
99
99
|
// you can create multiple services for each accessory
|
|
100
100
|
if (device.bot?.deviceType === 'switch') {
|
|
101
101
|
this.removeFanService(accessory);
|
|
@@ -602,7 +602,7 @@ export class Bot {
|
|
|
602
602
|
.deviceId!.match(/.{1,2}/g)!
|
|
603
603
|
.join(':')
|
|
604
604
|
.toLowerCase();
|
|
605
|
-
this.debugLog(`
|
|
605
|
+
this.debugLog(`Bot: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
606
606
|
//if (switchbot !== false) {
|
|
607
607
|
if (this.botMode === 'press') {
|
|
608
608
|
this.debugLog(`Bot: ${this.accessory.displayName} Bot Mode: ${this.botMode}`);
|
package/src/device/colorbulb.ts
CHANGED
|
@@ -82,7 +82,7 @@ export class ColorBulb {
|
|
|
82
82
|
accessory
|
|
83
83
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
84
84
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
85
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
85
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'W1401400')
|
|
86
86
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
87
87
|
|
|
88
88
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
@@ -94,7 +94,7 @@ export class ColorBulb {
|
|
|
94
94
|
this.accessory.removeService(this.lightBulbService);
|
|
95
95
|
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
96
96
|
this.accessory.context.adaptiveLighting = false;
|
|
97
|
-
this.debugLog(
|
|
97
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -162,7 +162,7 @@ export class ColorBulb {
|
|
|
162
162
|
})
|
|
163
163
|
.onSet(this.SaturationSet.bind(this));
|
|
164
164
|
|
|
165
|
-
this.debugLog(
|
|
165
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
166
166
|
if (this.adaptiveLightingShift !== -1) {
|
|
167
167
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
168
168
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
@@ -170,7 +170,7 @@ export class ColorBulb {
|
|
|
170
170
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
171
171
|
this.accessory.context.adaptiveLighting = true;
|
|
172
172
|
this.debugLog(
|
|
173
|
-
|
|
173
|
+
`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
174
174
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
175
175
|
);
|
|
176
176
|
}
|
|
@@ -198,9 +198,9 @@ export class ColorBulb {
|
|
|
198
198
|
try {
|
|
199
199
|
await this.pushChanges();
|
|
200
200
|
} catch (e: any) {
|
|
201
|
-
this.errorLog(
|
|
201
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
|
|
202
202
|
if (this.deviceLogging.includes('debug')) {
|
|
203
|
-
this.errorLog(
|
|
203
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
204
204
|
}
|
|
205
205
|
this.apiError(e);
|
|
206
206
|
}
|
|
@@ -216,43 +216,43 @@ export class ColorBulb {
|
|
|
216
216
|
default:
|
|
217
217
|
this.On = false;
|
|
218
218
|
}
|
|
219
|
-
this.debugLog(
|
|
219
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
220
220
|
|
|
221
221
|
// Brightness
|
|
222
222
|
this.Brightness = Number(this.brightness);
|
|
223
|
-
this.debugLog(
|
|
223
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
224
224
|
|
|
225
225
|
// Color, Hue & Brightness
|
|
226
226
|
if (this.color) {
|
|
227
|
-
this.debugLog(
|
|
227
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
228
228
|
const [red, green, blue] = this.color!.split(':');
|
|
229
|
-
this.debugLog(
|
|
230
|
-
this.debugLog(
|
|
231
|
-
this.debugLog(
|
|
229
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
230
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
231
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
232
232
|
|
|
233
233
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
234
234
|
this.debugLog(
|
|
235
|
-
|
|
235
|
+
`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
236
236
|
);
|
|
237
237
|
|
|
238
238
|
// Hue
|
|
239
239
|
this.Hue = hue;
|
|
240
|
-
this.debugLog(
|
|
240
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
241
241
|
|
|
242
242
|
// Saturation
|
|
243
243
|
this.Saturation = saturation;
|
|
244
|
-
this.debugLog(
|
|
244
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
// ColorTemperature
|
|
248
248
|
if (!Number.isNaN(this.colorTemperature)) {
|
|
249
|
-
this.debugLog(
|
|
249
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
250
250
|
const mired = Math.round(1000000 / this.colorTemperature!);
|
|
251
251
|
|
|
252
252
|
this.ColorTemperature = Number(mired);
|
|
253
253
|
|
|
254
254
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
255
|
-
this.debugLog(
|
|
255
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
256
256
|
}
|
|
257
257
|
|
|
258
258
|
}
|
|
@@ -260,7 +260,7 @@ export class ColorBulb {
|
|
|
260
260
|
async refreshStatus(): Promise<void> {
|
|
261
261
|
try {
|
|
262
262
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
263
|
-
this.debugLog(
|
|
263
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
264
264
|
this.power = this.deviceStatus.body.power;
|
|
265
265
|
this.color = this.deviceStatus.body.color;
|
|
266
266
|
this.brightness = this.deviceStatus.body.brightness;
|
|
@@ -269,10 +269,10 @@ export class ColorBulb {
|
|
|
269
269
|
this.parseStatus();
|
|
270
270
|
this.updateHomeKitCharacteristics();
|
|
271
271
|
} catch (e: any) {
|
|
272
|
-
this.errorLog(
|
|
272
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
273
273
|
if (this.deviceLogging.includes('debug')) {
|
|
274
274
|
this.errorLog(
|
|
275
|
-
|
|
275
|
+
`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
276
276
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
277
277
|
);
|
|
278
278
|
}
|
|
@@ -289,11 +289,6 @@ export class ColorBulb {
|
|
|
289
289
|
* Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
|
|
290
290
|
* Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
|
|
291
291
|
* Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
|
|
292
|
-
* Strip Light - "command" "turnOn" "default" = set to ON state |
|
|
293
|
-
* Strip Light - "command" "turnOff" "default" = set to OFF state |
|
|
294
|
-
* Strip Light - "command" "toggle" "default" = toggle state |
|
|
295
|
-
* Strip Light - "command" "setBrightness" "`{1-100}`" = set brightness |
|
|
296
|
-
* Strip Light - "command" "setColor" "`"{0-255}:{0-255}:{0-255}"`" = set RGB color value |
|
|
297
292
|
*
|
|
298
293
|
*/
|
|
299
294
|
async pushChanges(): Promise<void> {
|
|
@@ -312,13 +307,13 @@ export class ColorBulb {
|
|
|
312
307
|
}
|
|
313
308
|
|
|
314
309
|
this.infoLog(
|
|
315
|
-
|
|
310
|
+
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
316
311
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
317
312
|
);
|
|
318
313
|
|
|
319
314
|
// Make the API request
|
|
320
315
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
321
|
-
this.debugLog(
|
|
316
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
322
317
|
this.statusCode(push);
|
|
323
318
|
this.OnCached = this.On;
|
|
324
319
|
this.accessory.context.On = this.OnCached;
|
|
@@ -338,10 +333,10 @@ export class ColorBulb {
|
|
|
338
333
|
await this.pushHueSaturationChanges();
|
|
339
334
|
}
|
|
340
335
|
} catch (e: any) {
|
|
341
|
-
this.errorLog(
|
|
336
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
342
337
|
if (this.deviceLogging.includes('debug')) {
|
|
343
338
|
this.errorLog(
|
|
344
|
-
|
|
339
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
345
340
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
346
341
|
);
|
|
347
342
|
}
|
|
@@ -352,11 +347,11 @@ export class ColorBulb {
|
|
|
352
347
|
async pushHueSaturationChanges(): Promise<void> {
|
|
353
348
|
try {
|
|
354
349
|
if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
|
|
355
|
-
this.debugLog(
|
|
356
|
-
this.debugLog(
|
|
350
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
351
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
357
352
|
|
|
358
353
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
359
|
-
this.debugLog(
|
|
354
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
360
355
|
|
|
361
356
|
const payload = {
|
|
362
357
|
commandType: 'command',
|
|
@@ -365,27 +360,27 @@ export class ColorBulb {
|
|
|
365
360
|
} as payload;
|
|
366
361
|
|
|
367
362
|
this.infoLog(
|
|
368
|
-
|
|
363
|
+
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
369
364
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
370
365
|
);
|
|
371
366
|
|
|
372
367
|
// Make the API request
|
|
373
368
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
374
|
-
this.debugLog(
|
|
369
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
375
370
|
this.statusCode(push);
|
|
376
371
|
this.HueCached = this.Hue;
|
|
377
372
|
this.SaturationCached = this.Saturation;
|
|
378
373
|
} else {
|
|
379
374
|
this.debugLog(
|
|
380
|
-
|
|
375
|
+
`Color Bulb: ${this.accessory.displayName} No Changes.` +
|
|
381
376
|
`Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`,
|
|
382
377
|
);
|
|
383
378
|
}
|
|
384
379
|
} catch (e: any) {
|
|
385
|
-
this.errorLog(
|
|
380
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
386
381
|
if (this.deviceLogging.includes('debug')) {
|
|
387
382
|
this.errorLog(
|
|
388
|
-
|
|
383
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
389
384
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
390
385
|
);
|
|
391
386
|
}
|
|
@@ -406,26 +401,26 @@ export class ColorBulb {
|
|
|
406
401
|
} as payload;
|
|
407
402
|
|
|
408
403
|
this.infoLog(
|
|
409
|
-
|
|
404
|
+
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
410
405
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
411
406
|
);
|
|
412
407
|
|
|
413
408
|
// Make the API request
|
|
414
409
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
415
|
-
this.debugLog(
|
|
410
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
416
411
|
this.statusCode(push);
|
|
417
412
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
418
413
|
} else {
|
|
419
414
|
this.debugLog(
|
|
420
|
-
|
|
415
|
+
`Color Bulb: ${this.accessory.displayName} No Changes.` +
|
|
421
416
|
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`,
|
|
422
417
|
);
|
|
423
418
|
}
|
|
424
419
|
} catch (e: any) {
|
|
425
|
-
this.errorLog(
|
|
420
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
426
421
|
if (this.deviceLogging.includes('debug')) {
|
|
427
422
|
this.errorLog(
|
|
428
|
-
|
|
423
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
429
424
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
430
425
|
);
|
|
431
426
|
}
|
|
@@ -443,26 +438,26 @@ export class ColorBulb {
|
|
|
443
438
|
} as payload;
|
|
444
439
|
|
|
445
440
|
this.infoLog(
|
|
446
|
-
|
|
441
|
+
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
447
442
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
448
443
|
);
|
|
449
444
|
|
|
450
445
|
// Make the API request
|
|
451
446
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
452
|
-
this.debugLog(
|
|
447
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
453
448
|
this.statusCode(push);
|
|
454
449
|
this.BrightnessCached = this.Brightness;
|
|
455
450
|
} else {
|
|
456
451
|
this.debugLog(
|
|
457
|
-
|
|
452
|
+
`Color Bulb: ${this.accessory.displayName} No Changes.` +
|
|
458
453
|
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
459
454
|
);
|
|
460
455
|
}
|
|
461
456
|
} catch (e: any) {
|
|
462
|
-
this.errorLog(
|
|
457
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
463
458
|
if (this.deviceLogging.includes('debug')) {
|
|
464
459
|
this.errorLog(
|
|
465
|
-
|
|
460
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
466
461
|
` Error Message: ${JSON.stringify(e.message)}`,
|
|
467
462
|
);
|
|
468
463
|
}
|
|
@@ -472,34 +467,34 @@ export class ColorBulb {
|
|
|
472
467
|
|
|
473
468
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
474
469
|
if (this.On === undefined) {
|
|
475
|
-
this.debugLog(
|
|
470
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
476
471
|
} else {
|
|
477
472
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
478
|
-
this.debugLog(
|
|
473
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
479
474
|
}
|
|
480
475
|
if (this.Brightness === undefined) {
|
|
481
|
-
this.debugLog(
|
|
476
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
482
477
|
} else {
|
|
483
478
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
484
|
-
this.debugLog(
|
|
479
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
485
480
|
}
|
|
486
481
|
if (this.ColorTemperature === undefined) {
|
|
487
|
-
this.debugLog(
|
|
482
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
488
483
|
} else {
|
|
489
484
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
490
|
-
this.debugLog(
|
|
485
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
491
486
|
}
|
|
492
487
|
if (this.Hue === undefined) {
|
|
493
|
-
this.debugLog(
|
|
488
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
494
489
|
} else {
|
|
495
490
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
496
|
-
this.debugLog(
|
|
491
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
497
492
|
}
|
|
498
493
|
if (this.Saturation === undefined) {
|
|
499
|
-
this.debugLog(
|
|
494
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
500
495
|
} else {
|
|
501
496
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
502
|
-
this.debugLog(
|
|
497
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
503
498
|
}
|
|
504
499
|
}
|
|
505
500
|
|
|
@@ -515,36 +510,36 @@ export class ColorBulb {
|
|
|
515
510
|
statusCode(push: AxiosResponse<{ statusCode: number }>): void {
|
|
516
511
|
switch (push.data.statusCode) {
|
|
517
512
|
case 151:
|
|
518
|
-
this.errorLog(
|
|
513
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
519
514
|
break;
|
|
520
515
|
case 152:
|
|
521
|
-
this.errorLog(
|
|
516
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
|
|
522
517
|
break;
|
|
523
518
|
case 160:
|
|
524
|
-
this.errorLog(
|
|
519
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
|
|
525
520
|
break;
|
|
526
521
|
case 161:
|
|
527
|
-
this.errorLog(
|
|
522
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
|
|
528
523
|
this.offlineOff();
|
|
529
524
|
break;
|
|
530
525
|
case 171:
|
|
531
|
-
this.errorLog(
|
|
526
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
532
527
|
this.offlineOff();
|
|
533
528
|
break;
|
|
534
529
|
case 190:
|
|
535
530
|
this.errorLog(
|
|
536
|
-
|
|
531
|
+
`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
537
532
|
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
538
533
|
);
|
|
539
534
|
break;
|
|
540
535
|
case 100:
|
|
541
536
|
if (this.platform.debugMode) {
|
|
542
|
-
this.debugLog(
|
|
537
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
|
|
543
538
|
}
|
|
544
539
|
break;
|
|
545
540
|
default:
|
|
546
541
|
if (this.platform.debugMode) {
|
|
547
|
-
this.debugLog(
|
|
542
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
|
|
548
543
|
}
|
|
549
544
|
}
|
|
550
545
|
}
|
|
@@ -560,7 +555,7 @@ export class ColorBulb {
|
|
|
560
555
|
* Handle requests to set the value of the "On" characteristic
|
|
561
556
|
*/
|
|
562
557
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
563
|
-
this.debugLog(
|
|
558
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
|
|
564
559
|
|
|
565
560
|
this.On = value;
|
|
566
561
|
this.doColorBulbUpdate.next();
|
|
@@ -570,7 +565,7 @@ export class ColorBulb {
|
|
|
570
565
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
571
566
|
*/
|
|
572
567
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
573
|
-
this.debugLog(
|
|
568
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
|
|
574
569
|
|
|
575
570
|
this.Brightness = value;
|
|
576
571
|
this.doColorBulbUpdate.next();
|
|
@@ -580,7 +575,7 @@ export class ColorBulb {
|
|
|
580
575
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
581
576
|
*/
|
|
582
577
|
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
583
|
-
this.debugLog(
|
|
578
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
584
579
|
|
|
585
580
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
586
581
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -605,7 +600,7 @@ export class ColorBulb {
|
|
|
605
600
|
* Handle requests to set the value of the "Hue" characteristic
|
|
606
601
|
*/
|
|
607
602
|
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
608
|
-
this.debugLog(
|
|
603
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
|
|
609
604
|
|
|
610
605
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
611
606
|
|
|
@@ -617,7 +612,7 @@ export class ColorBulb {
|
|
|
617
612
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
618
613
|
*/
|
|
619
614
|
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
620
|
-
this.debugLog(
|
|
615
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
|
|
621
616
|
|
|
622
617
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
623
618
|
|
|
@@ -625,16 +620,6 @@ export class ColorBulb {
|
|
|
625
620
|
this.doColorBulbUpdate.next();
|
|
626
621
|
}
|
|
627
622
|
|
|
628
|
-
model(device: device & devicesConfig): string {
|
|
629
|
-
let model: string;
|
|
630
|
-
if (device.deviceType === 'Strip Light') {
|
|
631
|
-
model = 'W1701100';
|
|
632
|
-
} else {
|
|
633
|
-
model = 'W1401400';
|
|
634
|
-
}
|
|
635
|
-
return model;
|
|
636
|
-
}
|
|
637
|
-
|
|
638
623
|
async config(device: device & devicesConfig): Promise<void> {
|
|
639
624
|
let config = {};
|
|
640
625
|
if (device.colorbulb) {
|
|
@@ -656,43 +641,43 @@ export class ColorBulb {
|
|
|
656
641
|
config['offline'] = device.offline;
|
|
657
642
|
}
|
|
658
643
|
if (Object.entries(config).length !== 0) {
|
|
659
|
-
this.infoLog(
|
|
644
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
660
645
|
}
|
|
661
646
|
}
|
|
662
647
|
|
|
663
648
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
664
649
|
if (device.refreshRate) {
|
|
665
650
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
666
|
-
this.debugLog(
|
|
651
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
667
652
|
} else if (this.platform.config.options!.refreshRate) {
|
|
668
653
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
669
|
-
this.debugLog(
|
|
654
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
670
655
|
}
|
|
671
656
|
}
|
|
672
657
|
|
|
673
658
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
674
659
|
if (this.platform.debugMode) {
|
|
675
660
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
676
|
-
this.debugLog(
|
|
661
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
677
662
|
} else if (device.logging) {
|
|
678
663
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
679
|
-
this.debugLog(
|
|
664
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
680
665
|
} else if (this.platform.config.options?.logging) {
|
|
681
666
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
682
|
-
this.debugLog(
|
|
667
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
683
668
|
} else {
|
|
684
669
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
685
|
-
this.debugLog(
|
|
670
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
686
671
|
}
|
|
687
672
|
}
|
|
688
673
|
|
|
689
674
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
690
675
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
691
676
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
692
|
-
this.debugLog(
|
|
677
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
693
678
|
} else {
|
|
694
679
|
this.adaptiveLightingShift = 0;
|
|
695
|
-
this.debugLog(
|
|
680
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
696
681
|
}
|
|
697
682
|
}
|
|
698
683
|
|