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