@switchbot/homebridge-switchbot 2.0.0-beta.9 → 2.0.1-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/CHANGELOG.md +10 -1
- package/README.md +3 -2
- package/config.schema.json +119 -19
- package/dist/device/bot.d.ts +34 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +657 -648
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +137 -0
- package/dist/device/ceilinglight.d.ts.map +1 -0
- package/dist/device/ceilinglight.js +1127 -0
- package/dist/device/ceilinglight.js.map +1 -0
- package/dist/device/colorbulb.d.ts +36 -14
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +472 -297
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +18 -8
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +306 -237
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +23 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +566 -502
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +24 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +453 -369
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +27 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +305 -148
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +22 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +367 -267
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +24 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +381 -213
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +18 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +279 -216
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +27 -17
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +295 -251
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +43 -19
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +506 -262
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +12 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +316 -234
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +154 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +11 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +133 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +160 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +11 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +137 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +11 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +145 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +12 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +143 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +9 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +132 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +132 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +13 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +530 -421
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +22 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +1 -0
- package/package.json +11 -9
- package/src/device/bot.ts +656 -659
- package/src/device/ceilinglight.ts +1208 -0
- package/src/device/colorbulb.ts +482 -334
- package/src/device/contact.ts +309 -241
- package/src/device/curtain.ts +571 -516
- package/src/device/humidifier.ts +456 -403
- package/src/device/lock.ts +314 -149
- package/src/device/meter.ts +378 -280
- package/src/device/meterplus.ts +391 -219
- package/src/device/motion.ts +285 -222
- package/src/device/plug.ts +299 -260
- package/src/device/striplight.ts +522 -289
- package/src/irdevice/airconditioner.ts +322 -245
- package/src/irdevice/airpurifier.ts +151 -103
- package/src/irdevice/camera.ts +131 -85
- package/src/irdevice/fan.ts +157 -106
- package/src/irdevice/light.ts +135 -103
- package/src/irdevice/other.ts +143 -97
- package/src/irdevice/tv.ts +142 -93
- package/src/irdevice/vacuumcleaner.ts +131 -89
- package/src/irdevice/waterheater.ts +130 -89
- package/src/platform.ts +528 -449
- package/src/settings.ts +23 -11
package/dist/device/colorbulb.js
CHANGED
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ColorBulb = void 0;
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
9
10
|
const rxjs_1 = require("rxjs");
|
|
10
11
|
const operators_1 = require("rxjs/operators");
|
|
11
12
|
const settings_1 = require("../settings");
|
|
@@ -19,24 +20,16 @@ class ColorBulb {
|
|
|
19
20
|
this.platform = platform;
|
|
20
21
|
this.accessory = accessory;
|
|
21
22
|
this.device = device;
|
|
23
|
+
// Connection
|
|
24
|
+
this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
|
|
25
|
+
this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
|
|
22
26
|
// default placeholders
|
|
23
27
|
this.logs(device);
|
|
24
28
|
this.scan(device);
|
|
25
29
|
this.refreshRate(device);
|
|
26
30
|
this.adaptiveLighting(device);
|
|
27
31
|
this.config(device);
|
|
28
|
-
|
|
29
|
-
this.On = false;
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
this.On = this.accessory.context.On;
|
|
33
|
-
}
|
|
34
|
-
this.Hue = 0;
|
|
35
|
-
this.Brightness = 0;
|
|
36
|
-
this.Saturation = 0;
|
|
37
|
-
this.ColorTemperature = 140;
|
|
38
|
-
this.minKelvin = 2000;
|
|
39
|
-
this.maxKelvin = 9000;
|
|
32
|
+
this.context();
|
|
40
33
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
41
34
|
this.doColorBulbUpdate = new rxjs_1.Subject();
|
|
42
35
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -59,7 +52,7 @@ class ColorBulb {
|
|
|
59
52
|
this.accessory.removeService(this.lightBulbService);
|
|
60
53
|
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
61
54
|
this.accessory.context.adaptiveLighting = false;
|
|
62
|
-
this.debugLog(
|
|
55
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
63
56
|
}
|
|
64
57
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
65
58
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
@@ -83,7 +76,6 @@ class ColorBulb {
|
|
|
83
76
|
})
|
|
84
77
|
.onSet(this.BrightnessSet.bind(this));
|
|
85
78
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
86
|
-
this.debugLog(`Color Bulb: ${accessory.displayName} Add ColorTemperature Characteristic`);
|
|
87
79
|
this.lightBulbService
|
|
88
80
|
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
89
81
|
.setProps({
|
|
@@ -119,14 +111,14 @@ class ColorBulb {
|
|
|
119
111
|
return this.Saturation;
|
|
120
112
|
})
|
|
121
113
|
.onSet(this.SaturationSet.bind(this));
|
|
122
|
-
this.debugLog(
|
|
114
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
123
115
|
if (this.adaptiveLightingShift !== -1) {
|
|
124
116
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
125
117
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
126
118
|
});
|
|
127
119
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
128
120
|
this.accessory.context.adaptiveLighting = true;
|
|
129
|
-
this.debugLog(
|
|
121
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
130
122
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
131
123
|
}
|
|
132
124
|
// Update Homekit
|
|
@@ -148,25 +140,36 @@ class ColorBulb {
|
|
|
148
140
|
await this.pushChanges();
|
|
149
141
|
}
|
|
150
142
|
catch (e) {
|
|
151
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
|
|
152
|
-
if (this.deviceLogging.includes('debug')) {
|
|
153
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
154
|
-
}
|
|
155
143
|
this.apiError(e);
|
|
144
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with ${this.device.connectionType} Connection,`
|
|
145
|
+
+ ` Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
156
146
|
}
|
|
157
147
|
this.colorBulbUpdateInProgress = false;
|
|
148
|
+
// Refresh the status from the API
|
|
149
|
+
(0, rxjs_1.interval)(15000)
|
|
150
|
+
.pipe((0, operators_1.skipWhile)(() => this.colorBulbUpdateInProgress))
|
|
151
|
+
.pipe((0, operators_1.take)(1))
|
|
152
|
+
.subscribe(async () => {
|
|
153
|
+
await this.refreshStatus();
|
|
154
|
+
});
|
|
158
155
|
});
|
|
159
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Parse the device status from the SwitchBot api
|
|
159
|
+
*/
|
|
160
160
|
async parseStatus() {
|
|
161
|
-
if (this.
|
|
161
|
+
/*if (this.BLE) {
|
|
162
|
+
await this.BLEparseStatus();
|
|
163
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
162
164
|
await this.openAPIparseStatus();
|
|
163
165
|
}
|
|
164
166
|
else {
|
|
165
|
-
|
|
167
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
168
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
166
169
|
}
|
|
167
170
|
}
|
|
168
171
|
async BLEparseStatus() {
|
|
169
|
-
this.debugLog(
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
170
173
|
// State
|
|
171
174
|
switch (this.state) {
|
|
172
175
|
case 'on':
|
|
@@ -175,9 +178,10 @@ class ColorBulb {
|
|
|
175
178
|
default:
|
|
176
179
|
this.On = false;
|
|
177
180
|
}
|
|
178
|
-
this.debugLog(
|
|
181
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
179
182
|
}
|
|
180
183
|
async openAPIparseStatus() {
|
|
184
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
181
185
|
switch (this.power) {
|
|
182
186
|
case 'on':
|
|
183
187
|
this.On = true;
|
|
@@ -185,52 +189,59 @@ class ColorBulb {
|
|
|
185
189
|
default:
|
|
186
190
|
this.On = false;
|
|
187
191
|
}
|
|
188
|
-
this.debugLog(
|
|
192
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
189
193
|
// Brightness
|
|
190
194
|
this.Brightness = Number(this.brightness);
|
|
191
|
-
this.debugLog(
|
|
195
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
192
196
|
// Color, Hue & Brightness
|
|
193
197
|
if (this.color) {
|
|
194
|
-
this.debugLog(
|
|
198
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${(0, super_stringify_1.default)(this.color)}`);
|
|
195
199
|
const [red, green, blue] = this.color.split(':');
|
|
196
|
-
this.debugLog(
|
|
197
|
-
this.debugLog(
|
|
198
|
-
this.debugLog(
|
|
200
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${(0, super_stringify_1.default)(red)}`);
|
|
201
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${(0, super_stringify_1.default)(green)}`);
|
|
202
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${(0, super_stringify_1.default)(blue)}`);
|
|
199
203
|
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
200
|
-
this.debugLog(
|
|
204
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
205
|
+
+ ` hs: ${(0, super_stringify_1.default)((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
201
206
|
// Hue
|
|
202
207
|
this.Hue = hue;
|
|
203
|
-
this.debugLog(
|
|
208
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
204
209
|
// Saturation
|
|
205
210
|
this.Saturation = saturation;
|
|
206
|
-
this.debugLog(
|
|
211
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
207
212
|
}
|
|
208
213
|
// ColorTemperature
|
|
209
214
|
if (!Number.isNaN(this.colorTemperature)) {
|
|
210
|
-
this.debugLog(
|
|
215
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
211
216
|
const mired = Math.round(1000000 / this.colorTemperature);
|
|
212
217
|
this.ColorTemperature = Number(mired);
|
|
213
218
|
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
214
|
-
this.debugLog(
|
|
219
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
215
220
|
}
|
|
216
221
|
}
|
|
222
|
+
/**
|
|
223
|
+
* Asks the SwitchBot API for the latest device information
|
|
224
|
+
*/
|
|
217
225
|
async refreshStatus() {
|
|
218
|
-
if (this.
|
|
219
|
-
|
|
226
|
+
/*if (this.BLE) {
|
|
227
|
+
await this.BLERefreshStatus();
|
|
228
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
229
|
+
await this.openAPIRefreshStatus();
|
|
220
230
|
}
|
|
221
231
|
else {
|
|
222
|
-
|
|
232
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
233
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
223
234
|
}
|
|
224
235
|
}
|
|
225
236
|
async BLERefreshStatus() {
|
|
226
|
-
this.debugLog(
|
|
237
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
227
238
|
const switchbot = await this.platform.connectBLE();
|
|
228
239
|
// Convert to BLE Address
|
|
229
240
|
this.device.bleMac = this.device
|
|
230
241
|
.deviceId.match(/.{1,2}/g)
|
|
231
242
|
.join(':')
|
|
232
243
|
.toLowerCase();
|
|
233
|
-
this.debugLog(
|
|
244
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
234
245
|
this.getCustomBLEAddress(switchbot);
|
|
235
246
|
// Start to monitor advertisement packets
|
|
236
247
|
if (switchbot !== false) {
|
|
@@ -243,13 +254,9 @@ class ColorBulb {
|
|
|
243
254
|
// Set an event hander
|
|
244
255
|
switchbot.onadvertisement = (ad) => {
|
|
245
256
|
this.address = ad.address;
|
|
246
|
-
|
|
247
|
-
this.
|
|
248
|
-
|
|
249
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
250
|
-
this.infoLog(`Color Bulb: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
251
|
-
}
|
|
252
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
257
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
258
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
253
260
|
this.serviceData = ad.serviceData;
|
|
254
261
|
//this.state = ad.serviceData.state;
|
|
255
262
|
//this.delay = ad.serviceData.delay;
|
|
@@ -258,19 +265,19 @@ class ColorBulb {
|
|
|
258
265
|
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
259
266
|
//this.overload = ad.serviceData.overload;
|
|
260
267
|
//this.currentPower = ad.serviceData.currentPower;
|
|
261
|
-
this.debugLog(
|
|
268
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
262
269
|
/*this.debugLog(
|
|
263
|
-
|
|
270
|
+
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
264
271
|
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
265
272
|
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
266
273
|
);*/
|
|
267
274
|
if (this.serviceData) {
|
|
268
275
|
this.connected = true;
|
|
269
|
-
this.debugLog(
|
|
276
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
270
277
|
}
|
|
271
278
|
else {
|
|
272
279
|
this.connected = false;
|
|
273
|
-
this.debugLog(
|
|
280
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
274
281
|
}
|
|
275
282
|
};
|
|
276
283
|
// Wait 2 seconds
|
|
@@ -280,69 +287,33 @@ class ColorBulb {
|
|
|
280
287
|
// Stop to monitor
|
|
281
288
|
switchbot.stopScan();
|
|
282
289
|
if (this.connected) {
|
|
283
|
-
this.
|
|
290
|
+
this.BLEparseStatus();
|
|
284
291
|
this.updateHomeKitCharacteristics();
|
|
285
292
|
}
|
|
286
293
|
else {
|
|
287
|
-
this.
|
|
288
|
-
if (this.platform.config.credentials?.token) {
|
|
289
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
290
|
-
this.SwitchToOpenAPI = true;
|
|
291
|
-
await this.openAPIRefreshStatus();
|
|
292
|
-
}
|
|
294
|
+
await this.BLERefreshConnection(switchbot);
|
|
293
295
|
}
|
|
294
296
|
})
|
|
295
297
|
.catch(async (e) => {
|
|
296
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
297
|
-
if (this.deviceLogging.includes('debug')) {
|
|
298
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
299
|
-
}
|
|
300
|
-
if (this.platform.config.credentials?.token) {
|
|
301
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
302
|
-
this.SwitchToOpenAPI = true;
|
|
303
|
-
await this.openAPIRefreshStatus();
|
|
304
|
-
}
|
|
305
298
|
this.apiError(e);
|
|
299
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
300
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
301
|
+
await this.BLERefreshConnection(switchbot);
|
|
306
302
|
});
|
|
307
303
|
}
|
|
308
304
|
else {
|
|
309
|
-
await this.
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
async getCustomBLEAddress(switchbot) {
|
|
313
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
314
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
315
|
-
(async () => {
|
|
316
|
-
// Start to monitor advertisement packets
|
|
317
|
-
await switchbot.startScan({
|
|
318
|
-
model: 'u',
|
|
319
|
-
});
|
|
320
|
-
// Set an event handler
|
|
321
|
-
switchbot.onadvertisement = (ad) => {
|
|
322
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
323
|
-
};
|
|
324
|
-
await switchbot.wait(10000);
|
|
325
|
-
// Stop to monitor
|
|
326
|
-
switchbot.stopScan();
|
|
327
|
-
})();
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
async BLEconnection(switchbot) {
|
|
331
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
332
|
-
if (this.platform.config.credentials?.token) {
|
|
333
|
-
this.warnLog(`Color Bulb: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
334
|
-
this.SwitchToOpenAPI = true;
|
|
335
|
-
await this.openAPIRefreshStatus();
|
|
305
|
+
await this.BLERefreshConnection(switchbot);
|
|
336
306
|
}
|
|
337
307
|
}
|
|
338
308
|
async openAPIRefreshStatus() {
|
|
309
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
339
310
|
try {
|
|
340
311
|
const t = Date.now();
|
|
341
312
|
const nonce = 'requestID';
|
|
342
313
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
343
314
|
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
344
315
|
const sign = signTerm.toString('base64');
|
|
345
|
-
this.debugLog(
|
|
316
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
346
317
|
const options = {
|
|
347
318
|
hostname: settings_1.HostDomain,
|
|
348
319
|
port: 443,
|
|
@@ -357,39 +328,38 @@ class ColorBulb {
|
|
|
357
328
|
},
|
|
358
329
|
};
|
|
359
330
|
const req = https_1.default.request(options, (res) => {
|
|
360
|
-
this.debugLog(
|
|
331
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
332
|
+
this.statusCode({ res });
|
|
361
333
|
let rawData = '';
|
|
362
334
|
res.on('data', (d) => {
|
|
363
335
|
rawData += d;
|
|
364
|
-
this.debugLog(
|
|
336
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
365
337
|
});
|
|
366
338
|
res.on('end', () => {
|
|
367
339
|
try {
|
|
368
340
|
this.deviceStatus = JSON.parse(rawData);
|
|
369
|
-
this.debugLog(
|
|
341
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
370
342
|
this.power = this.deviceStatus.body.power;
|
|
371
343
|
this.color = this.deviceStatus.body.color;
|
|
372
344
|
this.brightness = this.deviceStatus.body.brightness;
|
|
373
345
|
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
374
|
-
this.
|
|
346
|
+
this.openAPIparseStatus();
|
|
375
347
|
this.updateHomeKitCharacteristics();
|
|
376
348
|
}
|
|
377
349
|
catch (e) {
|
|
378
|
-
this.errorLog(
|
|
350
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
379
351
|
}
|
|
380
352
|
});
|
|
381
353
|
});
|
|
382
354
|
req.on('error', (e) => {
|
|
383
|
-
this.errorLog(
|
|
355
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
384
356
|
});
|
|
385
357
|
req.end();
|
|
386
358
|
}
|
|
387
359
|
catch (e) {
|
|
388
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
389
|
-
if (this.deviceLogging.includes('debug')) {
|
|
390
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
391
|
-
}
|
|
392
360
|
this.apiError(e);
|
|
361
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
362
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
393
363
|
}
|
|
394
364
|
}
|
|
395
365
|
/**
|
|
@@ -404,7 +374,60 @@ class ColorBulb {
|
|
|
404
374
|
*
|
|
405
375
|
*/
|
|
406
376
|
async pushChanges() {
|
|
377
|
+
/*if (this.BLE) {
|
|
378
|
+
await this.BLEpushChanges();
|
|
379
|
+
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
380
|
+
await this.openAPIpushChanges();
|
|
381
|
+
}
|
|
382
|
+
else {
|
|
383
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
384
|
+
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
385
|
+
}
|
|
386
|
+
(0, rxjs_1.interval)(5000)
|
|
387
|
+
.pipe((0, operators_1.take)(1))
|
|
388
|
+
.subscribe(async () => {
|
|
389
|
+
await this.refreshStatus();
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
async BLEpushChanges() {
|
|
393
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
394
|
+
if (this.On !== this.accessory.context.On) {
|
|
395
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges On: ${this.On} OnCached: ${this.accessory.context.On}`);
|
|
396
|
+
const switchbot = await this.platform.connectBLE();
|
|
397
|
+
// Convert to BLE Address
|
|
398
|
+
this.device.bleMac = this.device
|
|
399
|
+
.deviceId.match(/.{1,2}/g)
|
|
400
|
+
.join(':')
|
|
401
|
+
.toLowerCase();
|
|
402
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
403
|
+
switchbot
|
|
404
|
+
.discover({
|
|
405
|
+
model: 'u',
|
|
406
|
+
id: this.device.bleMac,
|
|
407
|
+
})
|
|
408
|
+
.then((device_list) => {
|
|
409
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
410
|
+
return this.turnOnOff(device_list);
|
|
411
|
+
})
|
|
412
|
+
.then(() => {
|
|
413
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
414
|
+
this.On = false;
|
|
415
|
+
})
|
|
416
|
+
.catch(async (e) => {
|
|
417
|
+
this.apiError(e);
|
|
418
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
419
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
420
|
+
await this.BLEPushConnection();
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
else {
|
|
424
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No BLEpushChanges.` + `On: ${this.On}, `
|
|
425
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
async openAPIpushChanges() {
|
|
407
429
|
try {
|
|
430
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
408
431
|
if (this.On !== this.accessory.context.On) {
|
|
409
432
|
// Make Push On request to the API
|
|
410
433
|
const t = Date.now();
|
|
@@ -414,7 +437,7 @@ class ColorBulb {
|
|
|
414
437
|
.update(Buffer.from(data, 'utf-8'))
|
|
415
438
|
.digest();
|
|
416
439
|
const sign = signTerm.toString('base64');
|
|
417
|
-
this.debugLog(
|
|
440
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
418
441
|
let command = '';
|
|
419
442
|
if (this.On) {
|
|
420
443
|
command = 'turnOn';
|
|
@@ -422,12 +445,12 @@ class ColorBulb {
|
|
|
422
445
|
else {
|
|
423
446
|
command = 'turnOff';
|
|
424
447
|
}
|
|
425
|
-
const body =
|
|
448
|
+
const body = (0, super_stringify_1.default)({
|
|
426
449
|
'command': `${command}`,
|
|
427
450
|
'parameter': 'default',
|
|
428
451
|
'commandType': 'command',
|
|
429
452
|
});
|
|
430
|
-
this.infoLog(
|
|
453
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
431
454
|
const options = {
|
|
432
455
|
hostname: settings_1.HostDomain,
|
|
433
456
|
port: 443,
|
|
@@ -443,18 +466,22 @@ class ColorBulb {
|
|
|
443
466
|
},
|
|
444
467
|
};
|
|
445
468
|
const req = https_1.default.request(options, res => {
|
|
446
|
-
this.debugLog(
|
|
469
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges statusCode: ${res.statusCode}`);
|
|
447
470
|
this.statusCode({ res });
|
|
448
471
|
res.on('data', d => {
|
|
449
|
-
this.debugLog(
|
|
472
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
450
473
|
});
|
|
451
474
|
});
|
|
452
475
|
req.on('error', (e) => {
|
|
453
|
-
this.errorLog(
|
|
476
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
454
477
|
});
|
|
455
478
|
req.write(body);
|
|
456
479
|
req.end();
|
|
457
|
-
this.debugLog(
|
|
480
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
481
|
+
}
|
|
482
|
+
else {
|
|
483
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` + `On: ${this.On}, `
|
|
484
|
+
+ `OnCached: ${this.accessory.context.On}`);
|
|
458
485
|
}
|
|
459
486
|
// Push Brightness Update
|
|
460
487
|
if (this.On) {
|
|
@@ -470,20 +497,19 @@ class ColorBulb {
|
|
|
470
497
|
}
|
|
471
498
|
}
|
|
472
499
|
catch (e) {
|
|
473
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
474
|
-
if (this.deviceLogging.includes('debug')) {
|
|
475
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
476
|
-
}
|
|
477
500
|
this.apiError(e);
|
|
501
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIpushChanges with ${this.device.connectionType}`
|
|
502
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
478
503
|
}
|
|
479
504
|
}
|
|
480
505
|
async pushHueSaturationChanges() {
|
|
481
506
|
try {
|
|
507
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
482
508
|
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
483
|
-
this.debugLog(
|
|
484
|
-
this.debugLog(
|
|
509
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${(0, super_stringify_1.default)(this.Hue)}`);
|
|
510
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${(0, super_stringify_1.default)(this.Saturation)}`);
|
|
485
511
|
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
486
|
-
this.debugLog(
|
|
512
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${(0, super_stringify_1.default)([red, green, blue])}`);
|
|
487
513
|
// Make Push Hue/Saturation request to the API
|
|
488
514
|
const t = Date.now();
|
|
489
515
|
const nonce = 'requestID';
|
|
@@ -492,13 +518,13 @@ class ColorBulb {
|
|
|
492
518
|
.update(Buffer.from(data, 'utf-8'))
|
|
493
519
|
.digest();
|
|
494
520
|
const sign = signTerm.toString('base64');
|
|
495
|
-
this.debugLog(
|
|
496
|
-
const body =
|
|
521
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
522
|
+
const body = (0, super_stringify_1.default)({
|
|
497
523
|
'command': 'setColor',
|
|
498
524
|
'parameter': `${red}:${green}:${blue}`,
|
|
499
525
|
'commandType': 'command',
|
|
500
526
|
});
|
|
501
|
-
this.infoLog(
|
|
527
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
502
528
|
const options = {
|
|
503
529
|
hostname: settings_1.HostDomain,
|
|
504
530
|
port: 443,
|
|
@@ -514,34 +540,32 @@ class ColorBulb {
|
|
|
514
540
|
},
|
|
515
541
|
};
|
|
516
542
|
const req = https_1.default.request(options, res => {
|
|
517
|
-
this.debugLog(
|
|
543
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges statusCode: ${res.statusCode}`);
|
|
518
544
|
res.on('data', d => {
|
|
519
|
-
this.debugLog(
|
|
545
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
520
546
|
});
|
|
521
547
|
});
|
|
522
548
|
req.on('error', (e) => {
|
|
523
|
-
this.errorLog(
|
|
549
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
524
550
|
});
|
|
525
551
|
req.write(body);
|
|
526
552
|
req.end();
|
|
527
|
-
this.debugLog(
|
|
553
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
528
554
|
}
|
|
529
555
|
else {
|
|
530
|
-
this.debugLog(
|
|
531
|
-
`
|
|
532
|
-
+ ` SaturationCached: ${this.accessory.context.Saturation}`);
|
|
556
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, `
|
|
557
|
+
+ `HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
533
558
|
}
|
|
534
559
|
}
|
|
535
560
|
catch (e) {
|
|
536
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
537
|
-
if (this.deviceLogging.includes('debug')) {
|
|
538
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
539
|
-
}
|
|
540
561
|
this.apiError(e);
|
|
562
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushHueSaturationChanges with ${this.device.connectionType}`
|
|
563
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
541
564
|
}
|
|
542
565
|
}
|
|
543
566
|
async pushColorTemperatureChanges() {
|
|
544
567
|
try {
|
|
568
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
|
|
545
569
|
if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
546
570
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
547
571
|
this.cacheKelvin = kelvin;
|
|
@@ -553,13 +577,13 @@ class ColorBulb {
|
|
|
553
577
|
.update(Buffer.from(data, 'utf-8'))
|
|
554
578
|
.digest();
|
|
555
579
|
const sign = signTerm.toString('base64');
|
|
556
|
-
this.debugLog(
|
|
557
|
-
const body =
|
|
580
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
581
|
+
const body = (0, super_stringify_1.default)({
|
|
558
582
|
'command': 'setColorTemperature',
|
|
559
583
|
'parameter': `${kelvin}`,
|
|
560
584
|
'commandType': 'command',
|
|
561
585
|
});
|
|
562
|
-
this.infoLog(
|
|
586
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
563
587
|
const options = {
|
|
564
588
|
hostname: settings_1.HostDomain,
|
|
565
589
|
port: 443,
|
|
@@ -575,34 +599,33 @@ class ColorBulb {
|
|
|
575
599
|
},
|
|
576
600
|
};
|
|
577
601
|
const req = https_1.default.request(options, res => {
|
|
578
|
-
this.debugLog(
|
|
602
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
579
603
|
res.on('data', d => {
|
|
580
|
-
this.debugLog(
|
|
604
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
581
605
|
});
|
|
582
606
|
});
|
|
583
607
|
req.on('error', (e) => {
|
|
584
|
-
this.errorLog(
|
|
608
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
585
609
|
});
|
|
586
610
|
req.write(body);
|
|
587
611
|
req.end();
|
|
588
|
-
this.debugLog(
|
|
612
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
589
613
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
590
614
|
}
|
|
591
615
|
else {
|
|
592
|
-
this.debugLog(
|
|
616
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
|
|
593
617
|
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
594
618
|
}
|
|
595
619
|
}
|
|
596
620
|
catch (e) {
|
|
597
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
598
|
-
if (this.deviceLogging.includes('debug')) {
|
|
599
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
600
|
-
}
|
|
601
621
|
this.apiError(e);
|
|
622
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushColorTemperatureChanges with ${this.device.connectionType}`
|
|
623
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
602
624
|
}
|
|
603
625
|
}
|
|
604
626
|
async pushBrightnessChanges() {
|
|
605
627
|
try {
|
|
628
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
606
629
|
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
607
630
|
// Make Push On request to the API
|
|
608
631
|
const t = Date.now();
|
|
@@ -612,13 +635,13 @@ class ColorBulb {
|
|
|
612
635
|
.update(Buffer.from(data, 'utf-8'))
|
|
613
636
|
.digest();
|
|
614
637
|
const sign = signTerm.toString('base64');
|
|
615
|
-
this.debugLog(
|
|
616
|
-
const body =
|
|
638
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
639
|
+
const body = (0, super_stringify_1.default)({
|
|
617
640
|
'command': 'setBrightness',
|
|
618
641
|
'parameter': `${this.Brightness}`,
|
|
619
642
|
'commandType': 'command',
|
|
620
643
|
});
|
|
621
|
-
this.infoLog(
|
|
644
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. body: ${body},`);
|
|
622
645
|
const options = {
|
|
623
646
|
hostname: settings_1.HostDomain,
|
|
624
647
|
port: 443,
|
|
@@ -634,112 +657,290 @@ class ColorBulb {
|
|
|
634
657
|
},
|
|
635
658
|
};
|
|
636
659
|
const req = https_1.default.request(options, res => {
|
|
637
|
-
this.debugLog(
|
|
660
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges statusCode: ${res.statusCode}`);
|
|
638
661
|
res.on('data', d => {
|
|
639
|
-
this.debugLog(
|
|
662
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
640
663
|
});
|
|
641
664
|
});
|
|
642
665
|
req.on('error', (e) => {
|
|
643
|
-
this.errorLog(
|
|
666
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
644
667
|
});
|
|
645
668
|
req.write(body);
|
|
646
669
|
req.end();
|
|
647
|
-
this.debugLog(
|
|
670
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges: ${(0, super_stringify_1.default)(req)}`);
|
|
648
671
|
}
|
|
649
672
|
else {
|
|
650
|
-
this.debugLog(
|
|
673
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` + `Brightness: ${this.Brightness}, `
|
|
651
674
|
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
652
675
|
}
|
|
653
676
|
}
|
|
654
677
|
catch (e) {
|
|
655
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
656
|
-
if (this.deviceLogging.includes('debug')) {
|
|
657
|
-
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
658
|
-
}
|
|
659
678
|
this.apiError(e);
|
|
679
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushBrightnessChanges with ${this.device.connectionType}`
|
|
680
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
660
681
|
}
|
|
661
682
|
}
|
|
683
|
+
/**
|
|
684
|
+
* Handle requests to set the value of the "On" characteristic
|
|
685
|
+
*/
|
|
686
|
+
async OnSet(value) {
|
|
687
|
+
if (this.On === this.accessory.context.On) {
|
|
688
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
|
|
689
|
+
}
|
|
690
|
+
else {
|
|
691
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
692
|
+
}
|
|
693
|
+
this.On = value;
|
|
694
|
+
this.doColorBulbUpdate.next();
|
|
695
|
+
}
|
|
696
|
+
/**
|
|
697
|
+
* Handle requests to set the value of the "Brightness" characteristic
|
|
698
|
+
*/
|
|
699
|
+
async BrightnessSet(value) {
|
|
700
|
+
if (this.Brightness === this.accessory.context.Brightness) {
|
|
701
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
|
|
702
|
+
}
|
|
703
|
+
else if (this.On) {
|
|
704
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
705
|
+
}
|
|
706
|
+
else {
|
|
707
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
708
|
+
}
|
|
709
|
+
this.Brightness = value;
|
|
710
|
+
this.doColorBulbUpdate.next();
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
714
|
+
*/
|
|
715
|
+
async ColorTemperatureSet(value) {
|
|
716
|
+
if (this.ColorTemperature === this.accessory.context.ColorTemperature) {
|
|
717
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
|
|
718
|
+
}
|
|
719
|
+
else if (this.On) {
|
|
720
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
721
|
+
}
|
|
722
|
+
else {
|
|
723
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
724
|
+
}
|
|
725
|
+
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
726
|
+
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
727
|
+
// Check and increase/decrease kelvin to range of device
|
|
728
|
+
const k = Math.min(Math.max(kelvin, this.minKelvin), this.maxKelvin);
|
|
729
|
+
if (!this.accessory.context.On || this.cacheKelvin === k) {
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
732
|
+
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
733
|
+
const hs = (0, settings_1.m2hs)(value);
|
|
734
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
735
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
736
|
+
this.ColorTemperature = value;
|
|
737
|
+
this.doColorBulbUpdate.next();
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Handle requests to set the value of the "Hue" characteristic
|
|
741
|
+
*/
|
|
742
|
+
async HueSet(value) {
|
|
743
|
+
if (this.Hue === this.accessory.context.Hue) {
|
|
744
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
|
|
745
|
+
}
|
|
746
|
+
else if (this.On) {
|
|
747
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
748
|
+
}
|
|
749
|
+
else {
|
|
750
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
751
|
+
}
|
|
752
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
753
|
+
this.Hue = value;
|
|
754
|
+
this.doColorBulbUpdate.next();
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Handle requests to set the value of the "Saturation" characteristic
|
|
758
|
+
*/
|
|
759
|
+
async SaturationSet(value) {
|
|
760
|
+
if (this.Saturation === this.accessory.context.Saturation) {
|
|
761
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
|
|
762
|
+
}
|
|
763
|
+
else if (this.On) {
|
|
764
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
765
|
+
}
|
|
766
|
+
else {
|
|
767
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
768
|
+
}
|
|
769
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
770
|
+
this.Saturation = value;
|
|
771
|
+
this.doColorBulbUpdate.next();
|
|
772
|
+
}
|
|
662
773
|
async updateHomeKitCharacteristics() {
|
|
663
774
|
if (this.On === undefined) {
|
|
664
|
-
this.debugLog(
|
|
775
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
665
776
|
}
|
|
666
777
|
else {
|
|
667
778
|
this.accessory.context.On = this.On;
|
|
668
779
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
669
|
-
this.debugLog(
|
|
780
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
670
781
|
}
|
|
671
782
|
if (this.Brightness === undefined) {
|
|
672
|
-
this.debugLog(
|
|
783
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
673
784
|
}
|
|
674
785
|
else {
|
|
675
786
|
this.accessory.context.Brightness = this.Brightness;
|
|
676
787
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
677
|
-
this.debugLog(
|
|
788
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
678
789
|
}
|
|
679
790
|
if (this.ColorTemperature === undefined) {
|
|
680
|
-
this.debugLog(
|
|
791
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
681
792
|
}
|
|
682
793
|
else {
|
|
683
794
|
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
684
795
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
685
|
-
this.debugLog(
|
|
796
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
686
797
|
}
|
|
687
798
|
if (this.Hue === undefined) {
|
|
688
|
-
this.debugLog(
|
|
799
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
689
800
|
}
|
|
690
801
|
else {
|
|
691
802
|
this.accessory.context.Hue = this.Hue;
|
|
692
803
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
693
|
-
this.debugLog(
|
|
804
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
694
805
|
}
|
|
695
806
|
if (this.Saturation === undefined) {
|
|
696
|
-
this.debugLog(
|
|
807
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
697
808
|
}
|
|
698
809
|
else {
|
|
699
810
|
this.accessory.context.Saturation = this.Saturation;
|
|
700
811
|
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
701
|
-
this.debugLog(
|
|
812
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
702
813
|
}
|
|
703
814
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
815
|
+
async adaptiveLighting(device) {
|
|
816
|
+
if (device.colorbulb?.adaptiveLightingShift) {
|
|
817
|
+
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
818
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
819
|
+
}
|
|
820
|
+
else {
|
|
821
|
+
this.adaptiveLightingShift = 0;
|
|
822
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
async getCustomBLEAddress(switchbot) {
|
|
826
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
827
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
828
|
+
(async () => {
|
|
829
|
+
// Start to monitor advertisement packets
|
|
830
|
+
await switchbot.startScan({
|
|
831
|
+
model: 'u',
|
|
832
|
+
});
|
|
833
|
+
// Set an event handler
|
|
834
|
+
switchbot.onadvertisement = (ad) => {
|
|
835
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
|
|
836
|
+
};
|
|
837
|
+
await switchbot.wait(10000);
|
|
838
|
+
// Stop to monitor
|
|
839
|
+
switchbot.stopScan();
|
|
840
|
+
})();
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
async BLEPushConnection() {
|
|
844
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
845
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
846
|
+
await this.openAPIpushChanges();
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
async BLERefreshConnection(switchbot) {
|
|
850
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
851
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
852
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
853
|
+
await this.openAPIRefreshStatus();
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
async turnOnOff(device_list) {
|
|
857
|
+
return await this.retry({
|
|
858
|
+
max: await this.maxRetry(),
|
|
859
|
+
fn: () => {
|
|
860
|
+
if (this.On) {
|
|
861
|
+
return device_list[0].turnOn({ id: this.device.bleMac });
|
|
862
|
+
}
|
|
863
|
+
else {
|
|
864
|
+
return device_list[0].turnOff({ id: this.device.bleMac });
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
async retry({ max, fn }) {
|
|
870
|
+
return fn().catch(async (err) => {
|
|
871
|
+
if (max === 0) {
|
|
872
|
+
throw err;
|
|
873
|
+
}
|
|
874
|
+
this.infoLog(err);
|
|
875
|
+
this.infoLog('Retrying');
|
|
876
|
+
await this.switchbot.wait(1000);
|
|
877
|
+
return this.retry({ max: max - 1, fn });
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
async maxRetry() {
|
|
881
|
+
let maxRetry;
|
|
882
|
+
if (this.device.bot?.maxRetry) {
|
|
883
|
+
maxRetry = this.device.bot?.maxRetry;
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
maxRetry = 5;
|
|
887
|
+
}
|
|
888
|
+
return maxRetry;
|
|
889
|
+
}
|
|
890
|
+
minStep(device) {
|
|
891
|
+
if (device.colorbulb?.set_minStep) {
|
|
892
|
+
this.set_minStep = device.colorbulb?.set_minStep;
|
|
893
|
+
}
|
|
894
|
+
else {
|
|
895
|
+
this.set_minStep = 1;
|
|
896
|
+
}
|
|
897
|
+
return this.set_minStep;
|
|
898
|
+
}
|
|
899
|
+
async scan(device) {
|
|
900
|
+
if (device.scanDuration) {
|
|
901
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
902
|
+
if (this.BLE) {
|
|
903
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
908
|
+
if (this.BLE) {
|
|
909
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
910
|
+
}
|
|
911
|
+
}
|
|
711
912
|
}
|
|
712
913
|
async statusCode({ res }) {
|
|
713
914
|
switch (res.statusCode) {
|
|
714
915
|
case 151:
|
|
715
|
-
this.errorLog(
|
|
916
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
716
917
|
break;
|
|
717
918
|
case 152:
|
|
718
|
-
this.errorLog(
|
|
919
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
719
920
|
break;
|
|
720
921
|
case 160:
|
|
721
|
-
this.errorLog(
|
|
922
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
722
923
|
break;
|
|
723
924
|
case 161:
|
|
724
|
-
this.errorLog(
|
|
925
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
725
926
|
this.offlineOff();
|
|
726
927
|
break;
|
|
727
928
|
case 171:
|
|
728
|
-
this.errorLog(
|
|
929
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
729
930
|
this.offlineOff();
|
|
730
931
|
break;
|
|
731
932
|
case 190:
|
|
732
|
-
this.errorLog(
|
|
733
|
-
` Or command: ${
|
|
933
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
934
|
+
` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
|
|
734
935
|
break;
|
|
735
936
|
case 100:
|
|
736
937
|
if (this.platform.debugMode) {
|
|
737
|
-
this.debugLog(
|
|
938
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
738
939
|
}
|
|
739
940
|
break;
|
|
740
941
|
default:
|
|
741
942
|
if (this.platform.debugMode) {
|
|
742
|
-
this.debugLog(
|
|
943
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
743
944
|
}
|
|
744
945
|
}
|
|
745
946
|
}
|
|
@@ -747,68 +948,87 @@ class ColorBulb {
|
|
|
747
948
|
if (this.device.offline) {
|
|
748
949
|
this.On = false;
|
|
749
950
|
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
951
|
+
await this.updateHomeKitCharacteristics();
|
|
750
952
|
}
|
|
751
953
|
}
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
this.
|
|
757
|
-
this.
|
|
758
|
-
this.doColorBulbUpdate.next();
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Handle requests to set the value of the "Brightness" characteristic
|
|
762
|
-
*/
|
|
763
|
-
async BrightnessSet(value) {
|
|
764
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
|
|
765
|
-
this.Brightness = value;
|
|
766
|
-
this.doColorBulbUpdate.next();
|
|
954
|
+
apiError(e) {
|
|
955
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
956
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
957
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
958
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
959
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
|
|
767
960
|
}
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
this.debugLog(
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
const k = Math.min(Math.max(kelvin, this.minKelvin), this.maxKelvin);
|
|
777
|
-
if (!this.accessory.context.On || this.cacheKelvin === k) {
|
|
778
|
-
return;
|
|
961
|
+
FirmwareRevision(accessory, device) {
|
|
962
|
+
let FirmwareRevision;
|
|
963
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
964
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
965
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
966
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
967
|
+
if (accessory.context.FirmwareRevision) {
|
|
968
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
779
969
|
}
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
970
|
+
else if (device.firmware) {
|
|
971
|
+
FirmwareRevision = device.firmware;
|
|
972
|
+
}
|
|
973
|
+
else {
|
|
974
|
+
FirmwareRevision = this.platform.version;
|
|
975
|
+
}
|
|
976
|
+
return FirmwareRevision;
|
|
786
977
|
}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
this.
|
|
978
|
+
context() {
|
|
979
|
+
if (this.On === undefined) {
|
|
980
|
+
this.On = false;
|
|
981
|
+
}
|
|
982
|
+
else {
|
|
983
|
+
this.On = this.accessory.context.On;
|
|
984
|
+
}
|
|
985
|
+
if (this.Hue === undefined) {
|
|
986
|
+
this.Hue = 0;
|
|
987
|
+
}
|
|
988
|
+
else {
|
|
989
|
+
this.Hue = this.accessory.context.Hue;
|
|
990
|
+
}
|
|
991
|
+
if (this.Brightness === undefined) {
|
|
992
|
+
this.Brightness = 0;
|
|
993
|
+
}
|
|
994
|
+
else {
|
|
995
|
+
this.Brightness = this.accessory.context.Brightness;
|
|
996
|
+
}
|
|
997
|
+
if (this.Brightness === undefined) {
|
|
998
|
+
this.Saturation = 0;
|
|
999
|
+
}
|
|
1000
|
+
else {
|
|
1001
|
+
this.Saturation = this.accessory.context.Saturation;
|
|
1002
|
+
}
|
|
1003
|
+
if (this.ColorTemperature === undefined) {
|
|
1004
|
+
this.ColorTemperature = 140;
|
|
1005
|
+
}
|
|
1006
|
+
else {
|
|
1007
|
+
this.ColorTemperature = this.accessory.context.ColorTemperature;
|
|
1008
|
+
}
|
|
1009
|
+
this.minKelvin = 2000;
|
|
1010
|
+
this.maxKelvin = 9000;
|
|
795
1011
|
}
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
1012
|
+
async refreshRate(device) {
|
|
1013
|
+
if (device.refreshRate) {
|
|
1014
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1015
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1016
|
+
}
|
|
1017
|
+
else if (this.platform.config.options.refreshRate) {
|
|
1018
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
1019
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1020
|
+
}
|
|
804
1021
|
}
|
|
805
1022
|
async config(device) {
|
|
806
1023
|
let config = {};
|
|
807
1024
|
if (device.colorbulb) {
|
|
808
1025
|
config = device.colorbulb;
|
|
809
1026
|
}
|
|
810
|
-
if (device.
|
|
811
|
-
config['
|
|
1027
|
+
if (device.connectionType !== undefined) {
|
|
1028
|
+
config['connectionType'] = device.connectionType;
|
|
1029
|
+
}
|
|
1030
|
+
if (device.external !== undefined) {
|
|
1031
|
+
config['external'] = device.external;
|
|
812
1032
|
}
|
|
813
1033
|
if (device.logging !== undefined) {
|
|
814
1034
|
config['logging'] = device.logging;
|
|
@@ -823,85 +1043,26 @@ class ColorBulb {
|
|
|
823
1043
|
config['offline'] = device.offline;
|
|
824
1044
|
}
|
|
825
1045
|
if (Object.entries(config).length !== 0) {
|
|
826
|
-
this.infoLog(
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
async refreshRate(device) {
|
|
830
|
-
if (device.refreshRate) {
|
|
831
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
832
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
833
|
-
}
|
|
834
|
-
else if (this.platform.config.options.refreshRate) {
|
|
835
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
836
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
async scan(device) {
|
|
840
|
-
if (device.scanDuration) {
|
|
841
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
842
|
-
if (device.ble) {
|
|
843
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
848
|
-
if (this.device.ble) {
|
|
849
|
-
this.debugLog(`Bot: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
850
|
-
}
|
|
1046
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
|
|
851
1047
|
}
|
|
852
1048
|
}
|
|
853
1049
|
async logs(device) {
|
|
854
1050
|
if (this.platform.debugMode) {
|
|
855
1051
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
856
|
-
this.debugLog(
|
|
1052
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
857
1053
|
}
|
|
858
1054
|
else if (device.logging) {
|
|
859
1055
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
860
|
-
this.debugLog(
|
|
1056
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
861
1057
|
}
|
|
862
1058
|
else if (this.platform.config.options?.logging) {
|
|
863
1059
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
864
|
-
this.debugLog(
|
|
1060
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
865
1061
|
}
|
|
866
1062
|
else {
|
|
867
1063
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
868
|
-
this.debugLog(
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
FirmwareRevision(accessory, device) {
|
|
872
|
-
let FirmwareRevision;
|
|
873
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
874
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
875
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
876
|
-
if (accessory.context.FirmwareRevision) {
|
|
877
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
1064
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
878
1065
|
}
|
|
879
|
-
else if (device.firmware) {
|
|
880
|
-
FirmwareRevision = device.firmware;
|
|
881
|
-
}
|
|
882
|
-
else {
|
|
883
|
-
FirmwareRevision = this.platform.version;
|
|
884
|
-
}
|
|
885
|
-
return FirmwareRevision;
|
|
886
|
-
}
|
|
887
|
-
async adaptiveLighting(device) {
|
|
888
|
-
if (device.colorbulb?.adaptiveLightingShift) {
|
|
889
|
-
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
890
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
891
|
-
}
|
|
892
|
-
else {
|
|
893
|
-
this.adaptiveLightingShift = 0;
|
|
894
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
minStep(device) {
|
|
898
|
-
if (device.colorbulb?.set_minStep) {
|
|
899
|
-
this.set_minStep = device.colorbulb?.set_minStep;
|
|
900
|
-
}
|
|
901
|
-
else {
|
|
902
|
-
this.set_minStep = 1;
|
|
903
|
-
}
|
|
904
|
-
return this.set_minStep;
|
|
905
1066
|
}
|
|
906
1067
|
/**
|
|
907
1068
|
* Logging for Device
|
|
@@ -916,11 +1077,25 @@ class ColorBulb {
|
|
|
916
1077
|
this.platform.log.warn(String(...log));
|
|
917
1078
|
}
|
|
918
1079
|
}
|
|
1080
|
+
debugWarnLog(...log) {
|
|
1081
|
+
if (this.enablingDeviceLogging()) {
|
|
1082
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
1083
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
}
|
|
919
1087
|
errorLog(...log) {
|
|
920
1088
|
if (this.enablingDeviceLogging()) {
|
|
921
1089
|
this.platform.log.error(String(...log));
|
|
922
1090
|
}
|
|
923
1091
|
}
|
|
1092
|
+
debugErrorLog(...log) {
|
|
1093
|
+
if (this.enablingDeviceLogging()) {
|
|
1094
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
1095
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
}
|
|
924
1099
|
debugLog(...log) {
|
|
925
1100
|
if (this.enablingDeviceLogging()) {
|
|
926
1101
|
if (this.deviceLogging === 'debug') {
|