@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.9.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/.eslintrc +1 -1
- package/.vscode/settings.json +1 -1
- package/CHANGELOG.md +8 -0
- package/config.schema.json +9 -0
- package/dist/devices/bots.d.ts +37 -34
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +196 -243
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +50 -50
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +131 -145
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +29 -27
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +115 -138
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +31 -29
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +176 -211
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +33 -33
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +189 -214
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +31 -30
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +100 -124
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +26 -25
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +102 -120
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +23 -23
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +63 -81
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -22
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +6 -6
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +79 -105
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +5 -5
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +42 -56
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +5 -5
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +27 -31
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +5 -5
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +38 -45
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +5 -5
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +33 -37
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +5 -5
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +29 -34
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +5 -5
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +76 -91
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +5 -5
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +27 -31
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +5 -5
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +27 -31
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +12 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +172 -241
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +2 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/package.json +71 -72
- package/src/devices/bots.ts +455 -929
- package/src/devices/colorbulb.ts +246 -473
- package/src/devices/contact.ts +208 -381
- package/src/devices/curtains.ts +321 -613
- package/src/devices/humidifiers.ts +323 -594
- package/src/devices/meters.ts +186 -331
- package/src/devices/motion.ts +184 -327
- package/src/devices/plugs.ts +107 -175
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +149 -360
- package/src/irdevices/airpurifiers.ts +80 -178
- package/src/irdevices/cameras.ts +51 -109
- package/src/irdevices/fans.ts +77 -174
- package/src/irdevices/lights.ts +57 -110
- package/src/irdevices/others.ts +62 -137
- package/src/irdevices/tvs.ts +124 -249
- package/src/irdevices/vacuumcleaners.ts +52 -112
- package/src/irdevices/waterheaters.ts +53 -115
- package/src/platform.ts +357 -768
- package/src/settings.ts +24 -17
|
@@ -1,28 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
-
}) : (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
-
}) : function(o, v) {
|
|
12
|
-
o["default"] = v;
|
|
13
|
-
});
|
|
14
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
-
if (mod && mod.__esModule) return mod;
|
|
16
|
-
var result = {};
|
|
17
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
-
__setModuleDefault(result, mod);
|
|
19
|
-
return result;
|
|
20
|
-
};
|
|
21
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
3
|
exports.ColorBulb = void 0;
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const settings_1 = require("../settings");
|
|
26
7
|
/**
|
|
27
8
|
* Platform Accessory
|
|
28
9
|
* An instance of this class is created for each accessory your platform registers
|
|
@@ -51,24 +32,22 @@ class ColorBulb {
|
|
|
51
32
|
this.minKelvin = 2000;
|
|
52
33
|
this.maxKelvin = 9000;
|
|
53
34
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
54
|
-
this.doColorBulbUpdate = new
|
|
35
|
+
this.doColorBulbUpdate = new rxjs_1.Subject();
|
|
55
36
|
this.colorBulbUpdateInProgress = false;
|
|
56
37
|
// Retrieve initial values and updateHomekit
|
|
57
38
|
this.refreshStatus();
|
|
58
39
|
// set accessory information
|
|
59
40
|
accessory
|
|
60
41
|
.getService(this.platform.Service.AccessoryInformation)
|
|
61
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
62
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
42
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
43
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
|
|
63
44
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
64
45
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
65
46
|
// you can create multiple services for each accessory
|
|
66
47
|
(this.service =
|
|
67
48
|
accessory.getService(this.platform.Service.Lightbulb) ||
|
|
68
|
-
accessory.addService(this.platform.Service.Lightbulb)),
|
|
69
|
-
|
|
70
|
-
if (this.adaptiveLightingShift === -1 &&
|
|
71
|
-
this.accessory.context.adaptiveLighting) {
|
|
49
|
+
accessory.addService(this.platform.Service.Lightbulb)), `${accessory.displayName} Light Bulb`;
|
|
50
|
+
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
72
51
|
this.accessory.removeService(this.service);
|
|
73
52
|
this.service = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
74
53
|
this.accessory.context.adaptiveLighting = false;
|
|
@@ -81,12 +60,10 @@ class ColorBulb {
|
|
|
81
60
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
82
61
|
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
83
62
|
// handle on / off events using the On characteristic
|
|
84
|
-
this.service
|
|
85
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
63
|
+
this.service.getCharacteristic(this.platform.Characteristic.On)
|
|
86
64
|
.onSet(this.OnSet.bind(this));
|
|
87
65
|
// handle Brightness events using the Brightness characteristic
|
|
88
|
-
this.service
|
|
89
|
-
.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
66
|
+
this.service.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
90
67
|
.setProps({
|
|
91
68
|
minStep: this.minStep(device),
|
|
92
69
|
minValue: 0,
|
|
@@ -98,8 +75,7 @@ class ColorBulb {
|
|
|
98
75
|
})
|
|
99
76
|
.onSet(this.BrightnessSet.bind(this));
|
|
100
77
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
101
|
-
this.service
|
|
102
|
-
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
78
|
+
this.service.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
103
79
|
.setProps({
|
|
104
80
|
minValue: 140,
|
|
105
81
|
maxValue: 500,
|
|
@@ -110,8 +86,7 @@ class ColorBulb {
|
|
|
110
86
|
})
|
|
111
87
|
.onSet(this.ColorTemperatureSet.bind(this));
|
|
112
88
|
// handle Hue events using the Hue characteristic
|
|
113
|
-
this.service
|
|
114
|
-
.getCharacteristic(this.platform.Characteristic.Hue)
|
|
89
|
+
this.service.getCharacteristic(this.platform.Characteristic.Hue)
|
|
115
90
|
.setProps({
|
|
116
91
|
minValue: 0,
|
|
117
92
|
maxValue: 360,
|
|
@@ -122,8 +97,7 @@ class ColorBulb {
|
|
|
122
97
|
})
|
|
123
98
|
.onSet(this.HueSet.bind(this));
|
|
124
99
|
// handle Hue events using the Hue characteristic
|
|
125
|
-
this.service
|
|
126
|
-
.getCharacteristic(this.platform.Characteristic.Saturation)
|
|
100
|
+
this.service.getCharacteristic(this.platform.Characteristic.Saturation)
|
|
127
101
|
.setProps({
|
|
128
102
|
minValue: 0,
|
|
129
103
|
maxValue: 100,
|
|
@@ -135,39 +109,41 @@ class ColorBulb {
|
|
|
135
109
|
.onSet(this.SaturationSet.bind(this));
|
|
136
110
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
137
111
|
if (this.adaptiveLightingShift !== -1) {
|
|
138
|
-
this.AdaptiveLightingController =
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
});
|
|
112
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
|
|
113
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
114
|
+
});
|
|
142
115
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
143
116
|
this.accessory.context.adaptiveLighting = true;
|
|
144
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
|
|
145
|
-
` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
117
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
|
|
118
|
+
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
146
119
|
}
|
|
147
120
|
// Update Homekit
|
|
148
121
|
this.updateHomeKitCharacteristics();
|
|
149
122
|
// Start an update interval
|
|
150
|
-
|
|
151
|
-
.
|
|
152
|
-
.pipe(operators.skipWhile(() => this.colorBulbUpdateInProgress))
|
|
123
|
+
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
124
|
+
.pipe((0, operators_1.skipWhile)(() => this.colorBulbUpdateInProgress))
|
|
153
125
|
.subscribe(() => {
|
|
154
126
|
this.refreshStatus();
|
|
155
127
|
});
|
|
156
128
|
// Watch for Bulb change events
|
|
157
129
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
158
130
|
this.doColorBulbUpdate
|
|
159
|
-
.pipe(
|
|
131
|
+
.pipe((0, operators_1.tap)(() => {
|
|
160
132
|
this.colorBulbUpdateInProgress = true;
|
|
161
|
-
}),
|
|
133
|
+
}), (0, operators_1.debounceTime)(this.platform.config.options.pushRate * 1000))
|
|
162
134
|
.subscribe(async () => {
|
|
163
135
|
try {
|
|
164
136
|
await this.pushChanges();
|
|
165
137
|
}
|
|
166
138
|
catch (e) {
|
|
167
139
|
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
|
|
168
|
-
if (this.deviceLogging
|
|
169
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
|
|
170
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
140
|
+
if (this.deviceLogging === 'debug') {
|
|
141
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
|
|
142
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
143
|
+
}
|
|
144
|
+
if (this.platform.debugMode) {
|
|
145
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,`
|
|
146
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
171
147
|
}
|
|
172
148
|
this.apiError(e);
|
|
173
149
|
}
|
|
@@ -176,7 +152,7 @@ class ColorBulb {
|
|
|
176
152
|
}
|
|
177
153
|
parseStatus() {
|
|
178
154
|
switch (this.power) {
|
|
179
|
-
case
|
|
155
|
+
case 'on':
|
|
180
156
|
this.On = true;
|
|
181
157
|
break;
|
|
182
158
|
default:
|
|
@@ -189,12 +165,12 @@ class ColorBulb {
|
|
|
189
165
|
// Color, Hue & Brightness
|
|
190
166
|
if (this.color) {
|
|
191
167
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
192
|
-
const [red, green, blue] = this.color.split(
|
|
168
|
+
const [red, green, blue] = this.color.split(':');
|
|
193
169
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
194
170
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
195
171
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
196
|
-
const [hue, saturation] =
|
|
197
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(
|
|
172
|
+
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
173
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
198
174
|
// Hue
|
|
199
175
|
this.Hue = hue;
|
|
200
176
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
@@ -213,7 +189,7 @@ class ColorBulb {
|
|
|
213
189
|
}
|
|
214
190
|
async refreshStatus() {
|
|
215
191
|
try {
|
|
216
|
-
this.deviceStatus = (await this.platform.axios.get(`${
|
|
192
|
+
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
217
193
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
218
194
|
this.power = this.deviceStatus.body.power;
|
|
219
195
|
this.color = this.deviceStatus.body.color;
|
|
@@ -224,41 +200,45 @@ class ColorBulb {
|
|
|
224
200
|
}
|
|
225
201
|
catch (e) {
|
|
226
202
|
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
227
|
-
if (this.deviceLogging
|
|
228
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
229
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
203
|
+
if (this.deviceLogging === 'debug') {
|
|
204
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
205
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
206
|
+
}
|
|
207
|
+
if (this.platform.debugMode) {
|
|
208
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
209
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
230
210
|
}
|
|
231
211
|
this.apiError(e);
|
|
232
212
|
}
|
|
233
213
|
}
|
|
234
214
|
/**
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
215
|
+
* Pushes the requested changes to the SwitchBot API
|
|
216
|
+
* deviceType commandType Command command parameter Description
|
|
217
|
+
* Color Bulb - "command" "turnOff" "default" = set to OFF state
|
|
218
|
+
* Color Bulb - "command" "turnOn" "default" = set to ON state
|
|
219
|
+
* Color Bulb - "command" "toggle" "default" = toggle state
|
|
220
|
+
* Color Bulb - "command" "setBrightness" "{1-100}" = set brightness
|
|
221
|
+
* Color Bulb - "command" "setColor" "{0-255}:{0-255}:{0-255}" = set RGB color value
|
|
222
|
+
* Color Bulb - "command" "setColorTemperature" "{2700-6500}" = set color temperature
|
|
223
|
+
*/
|
|
244
224
|
async pushChanges() {
|
|
245
225
|
try {
|
|
246
226
|
if (this.On !== this.OnCached) {
|
|
247
227
|
// Push On Update
|
|
248
228
|
const payload = {
|
|
249
|
-
commandType:
|
|
250
|
-
parameter:
|
|
229
|
+
commandType: 'command',
|
|
230
|
+
parameter: 'default',
|
|
251
231
|
};
|
|
252
232
|
if (this.On) {
|
|
253
|
-
payload.command =
|
|
233
|
+
payload.command = 'turnOn';
|
|
254
234
|
}
|
|
255
235
|
else {
|
|
256
|
-
payload.command =
|
|
236
|
+
payload.command = 'turnOff';
|
|
257
237
|
}
|
|
258
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
259
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
238
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
239
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
260
240
|
// Make the API request
|
|
261
|
-
const push = await this.platform.axios.post(`${
|
|
241
|
+
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
262
242
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
263
243
|
this.statusCode(push);
|
|
264
244
|
this.OnCached = this.On;
|
|
@@ -279,49 +259,52 @@ class ColorBulb {
|
|
|
279
259
|
}
|
|
280
260
|
catch (e) {
|
|
281
261
|
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
282
|
-
if (this.deviceLogging
|
|
283
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
284
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
262
|
+
if (this.deviceLogging === 'debug') {
|
|
263
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
264
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
265
|
+
}
|
|
266
|
+
if (this.platform.debugMode) {
|
|
267
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
268
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
285
269
|
}
|
|
286
270
|
this.apiError(e);
|
|
287
271
|
}
|
|
288
272
|
}
|
|
289
273
|
async pushHueSaturationChanges() {
|
|
290
274
|
try {
|
|
291
|
-
if (this.Hue !== this.HueCached ||
|
|
292
|
-
this.Saturation !== this.SaturationCached) {
|
|
275
|
+
if ((this.Hue !== this.HueCached) || (this.Saturation !== this.SaturationCached)) {
|
|
293
276
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
294
277
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
295
|
-
const [red, green, blue] =
|
|
296
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([
|
|
297
|
-
red,
|
|
298
|
-
green,
|
|
299
|
-
blue,
|
|
300
|
-
])}`);
|
|
278
|
+
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
279
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
301
280
|
const payload = {
|
|
302
|
-
commandType:
|
|
303
|
-
command:
|
|
281
|
+
commandType: 'command',
|
|
282
|
+
command: 'setColor',
|
|
304
283
|
parameter: `${red}:${green}:${blue}`,
|
|
305
284
|
};
|
|
306
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
307
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
285
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
286
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
308
287
|
// Make the API request
|
|
309
|
-
const push = await this.platform.axios.post(`${
|
|
288
|
+
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
310
289
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
311
290
|
this.statusCode(push);
|
|
312
291
|
this.HueCached = this.Hue;
|
|
313
292
|
this.SaturationCached = this.Saturation;
|
|
314
293
|
}
|
|
315
294
|
else {
|
|
316
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
317
|
-
`Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
|
|
295
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
296
|
+
+ `Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
|
|
318
297
|
}
|
|
319
298
|
}
|
|
320
299
|
catch (e) {
|
|
321
300
|
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
322
|
-
if (this.deviceLogging
|
|
323
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
324
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
301
|
+
if (this.deviceLogging === 'debug') {
|
|
302
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
303
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
304
|
+
}
|
|
305
|
+
if (this.platform.debugMode) {
|
|
306
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
307
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
325
308
|
}
|
|
326
309
|
this.apiError(e);
|
|
327
310
|
}
|
|
@@ -332,28 +315,32 @@ class ColorBulb {
|
|
|
332
315
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
333
316
|
this.cacheKelvin = kelvin;
|
|
334
317
|
const payload = {
|
|
335
|
-
commandType:
|
|
336
|
-
command:
|
|
318
|
+
commandType: 'command',
|
|
319
|
+
command: 'setColorTemperature',
|
|
337
320
|
parameter: `${kelvin}`,
|
|
338
321
|
};
|
|
339
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
340
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
322
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
323
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
341
324
|
// Make the API request
|
|
342
|
-
const push = await this.platform.axios.post(`${
|
|
325
|
+
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
343
326
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
344
327
|
this.statusCode(push);
|
|
345
328
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
346
329
|
}
|
|
347
330
|
else {
|
|
348
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
349
|
-
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
|
|
331
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
332
|
+
+ `ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
|
|
350
333
|
}
|
|
351
334
|
}
|
|
352
335
|
catch (e) {
|
|
353
336
|
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
354
|
-
if (this.deviceLogging
|
|
355
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
356
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
337
|
+
if (this.deviceLogging === 'debug') {
|
|
338
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
339
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
340
|
+
}
|
|
341
|
+
if (this.platform.debugMode) {
|
|
342
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
343
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
357
344
|
}
|
|
358
345
|
this.apiError(e);
|
|
359
346
|
}
|
|
@@ -362,28 +349,32 @@ class ColorBulb {
|
|
|
362
349
|
try {
|
|
363
350
|
if (this.Brightness !== this.BrightnessCached) {
|
|
364
351
|
const payload = {
|
|
365
|
-
commandType:
|
|
366
|
-
command:
|
|
352
|
+
commandType: 'command',
|
|
353
|
+
command: 'setBrightness',
|
|
367
354
|
parameter: `${this.Brightness}`,
|
|
368
355
|
};
|
|
369
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
370
|
-
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
356
|
+
this.infoLog(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
357
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
371
358
|
// Make the API request
|
|
372
|
-
const push = await this.platform.axios.post(`${
|
|
359
|
+
const push = (await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
373
360
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
374
361
|
this.statusCode(push);
|
|
375
362
|
this.BrightnessCached = this.Brightness;
|
|
376
363
|
}
|
|
377
364
|
else {
|
|
378
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
379
|
-
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
|
|
365
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} No Changes.`
|
|
366
|
+
+ `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
|
|
380
367
|
}
|
|
381
368
|
}
|
|
382
369
|
catch (e) {
|
|
383
370
|
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
384
|
-
if (this.deviceLogging
|
|
385
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
386
|
-
` Error Message: ${JSON.stringify(e.message)}`);
|
|
371
|
+
if (this.deviceLogging === 'debug') {
|
|
372
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
373
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
374
|
+
}
|
|
375
|
+
if (this.platform.debugMode) {
|
|
376
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,`
|
|
377
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
387
378
|
}
|
|
388
379
|
this.apiError(e);
|
|
389
380
|
}
|
|
@@ -453,8 +444,8 @@ class ColorBulb {
|
|
|
453
444
|
this.offlineOff();
|
|
454
445
|
break;
|
|
455
446
|
case 190:
|
|
456
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
457
|
-
` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
447
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,`
|
|
448
|
+
+ ` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
458
449
|
break;
|
|
459
450
|
case 100:
|
|
460
451
|
if (this.platform.debugMode) {
|
|
@@ -470,9 +461,7 @@ class ColorBulb {
|
|
|
470
461
|
offlineOff() {
|
|
471
462
|
if (this.device.offline) {
|
|
472
463
|
this.On = false;
|
|
473
|
-
this.service
|
|
474
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
475
|
-
.updateValue(this.On);
|
|
464
|
+
this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
476
465
|
}
|
|
477
466
|
}
|
|
478
467
|
/**
|
|
@@ -504,15 +493,15 @@ class ColorBulb {
|
|
|
504
493
|
return;
|
|
505
494
|
}
|
|
506
495
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
507
|
-
const hs =
|
|
496
|
+
const hs = (0, settings_1.m2hs)(value);
|
|
508
497
|
this.service.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
509
498
|
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
510
499
|
this.ColorTemperature = value;
|
|
511
500
|
this.doColorBulbUpdate.next();
|
|
512
501
|
}
|
|
513
502
|
/**
|
|
514
|
-
|
|
515
|
-
|
|
503
|
+
* Handle requests to set the value of the "Hue" characteristic
|
|
504
|
+
*/
|
|
516
505
|
HueSet(value) {
|
|
517
506
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
|
|
518
507
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
@@ -520,8 +509,8 @@ class ColorBulb {
|
|
|
520
509
|
this.doColorBulbUpdate.next();
|
|
521
510
|
}
|
|
522
511
|
/**
|
|
523
|
-
|
|
524
|
-
|
|
512
|
+
* Handle requests to set the value of the "Saturation" characteristic
|
|
513
|
+
*/
|
|
525
514
|
SaturationSet(value) {
|
|
526
515
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
|
|
527
516
|
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
@@ -534,16 +523,16 @@ class ColorBulb {
|
|
|
534
523
|
config = device.colorbulb;
|
|
535
524
|
}
|
|
536
525
|
if (device.ble) {
|
|
537
|
-
config[
|
|
526
|
+
config['ble'] = device.ble;
|
|
538
527
|
}
|
|
539
528
|
if (device.logging !== undefined) {
|
|
540
|
-
config[
|
|
529
|
+
config['logging'] = device.logging;
|
|
541
530
|
}
|
|
542
531
|
if (device.refreshRate !== undefined) {
|
|
543
|
-
config[
|
|
532
|
+
config['refreshRate'] = device.refreshRate;
|
|
544
533
|
}
|
|
545
534
|
if (device.scanDuration !== undefined) {
|
|
546
|
-
config[
|
|
535
|
+
config['scanDuration'] = device.scanDuration;
|
|
547
536
|
}
|
|
548
537
|
if (Object.entries(config).length !== 0) {
|
|
549
538
|
this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
@@ -551,19 +540,17 @@ class ColorBulb {
|
|
|
551
540
|
}
|
|
552
541
|
refreshRate(device) {
|
|
553
542
|
if (device.refreshRate) {
|
|
554
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
555
|
-
device.refreshRate;
|
|
543
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
556
544
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
557
545
|
}
|
|
558
546
|
else if (this.platform.config.options.refreshRate) {
|
|
559
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
560
|
-
this.platform.config.options.refreshRate;
|
|
547
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
561
548
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
562
549
|
}
|
|
563
550
|
}
|
|
564
551
|
logs(device) {
|
|
565
552
|
if (this.platform.debugMode) {
|
|
566
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
553
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
567
554
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
568
555
|
}
|
|
569
556
|
else if (device.logging) {
|
|
@@ -571,12 +558,11 @@ class ColorBulb {
|
|
|
571
558
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
572
559
|
}
|
|
573
560
|
else if (this.platform.config.options?.logging) {
|
|
574
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
575
|
-
this.platform.config.options?.logging;
|
|
561
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
576
562
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
577
563
|
}
|
|
578
564
|
else {
|
|
579
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
565
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
580
566
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
581
567
|
}
|
|
582
568
|
}
|
|
@@ -600,8 +586,8 @@ class ColorBulb {
|
|
|
600
586
|
return this.set_minStep;
|
|
601
587
|
}
|
|
602
588
|
/**
|
|
603
|
-
|
|
604
|
-
|
|
589
|
+
* Logging for Device
|
|
590
|
+
*/
|
|
605
591
|
infoLog(...log) {
|
|
606
592
|
if (this.enablingDeviceLogging()) {
|
|
607
593
|
this.platform.log.info(String(...log));
|
|
@@ -619,8 +605,8 @@ class ColorBulb {
|
|
|
619
605
|
}
|
|
620
606
|
debugLog(...log) {
|
|
621
607
|
if (this.enablingDeviceLogging()) {
|
|
622
|
-
if (this.deviceLogging ===
|
|
623
|
-
this.platform.log.info(
|
|
608
|
+
if (this.deviceLogging === 'debug') {
|
|
609
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
624
610
|
}
|
|
625
611
|
else {
|
|
626
612
|
this.platform.log.debug(String(...log));
|
|
@@ -628,7 +614,7 @@ class ColorBulb {
|
|
|
628
614
|
}
|
|
629
615
|
}
|
|
630
616
|
enablingDeviceLogging() {
|
|
631
|
-
return
|
|
617
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
632
618
|
}
|
|
633
619
|
}
|
|
634
620
|
exports.ColorBulb = ColorBulb;
|