@switchbot/homebridge-switchbot 4.1.1-beta.2 → 4.1.1-beta.3
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/dist/device/blindtilt.js +102 -102
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.js +85 -85
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.js +98 -98
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.js +140 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.js +44 -44
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.js +82 -82
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +11 -11
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +41 -41
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.js +96 -96
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.js +43 -43
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.js +84 -84
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.js +44 -44
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.js +119 -119
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.js +75 -75
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.js +44 -44
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.js +42 -42
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/meterpro.js +42 -42
- package/dist/device/meterpro.js.map +1 -1
- package/dist/device/motion.js +42 -42
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.js +60 -60
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.js +74 -74
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.js +44 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.js +31 -31
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.js +10 -10
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.js +9 -9
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.js +11 -11
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.js +11 -11
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.js +9 -9
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +55 -55
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.js +33 -33
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.js +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.js +228 -228
- package/dist/platform.js.map +1 -1
- package/package.json +1 -1
- package/src/device/blindtilt.ts +102 -102
- package/src/device/bot.ts +85 -85
- package/src/device/ceilinglight.ts +98 -98
- package/src/device/colorbulb.ts +140 -140
- package/src/device/contact.ts +44 -44
- package/src/device/curtain.ts +82 -82
- package/src/device/device.ts +41 -41
- package/src/device/fan.ts +96 -96
- package/src/device/hub.ts +43 -43
- package/src/device/humidifier.ts +84 -84
- package/src/device/iosensor.ts +44 -44
- package/src/device/lightstrip.ts +119 -119
- package/src/device/lock.ts +75 -75
- package/src/device/meter.ts +44 -44
- package/src/device/meterplus.ts +42 -42
- package/src/device/meterpro.ts +42 -42
- package/src/device/motion.ts +42 -42
- package/src/device/plug.ts +60 -60
- package/src/device/robotvacuumcleaner.ts +74 -74
- package/src/device/waterdetector.ts +44 -44
- package/src/irdevice/airconditioner.ts +31 -31
- package/src/irdevice/airpurifier.ts +10 -10
- package/src/irdevice/camera.ts +9 -9
- package/src/irdevice/fan.ts +11 -11
- package/src/irdevice/irdevice.ts +11 -11
- package/src/irdevice/light.ts +9 -9
- package/src/irdevice/other.ts +55 -55
- package/src/irdevice/tv.ts +33 -33
- package/src/irdevice/vacuumcleaner.ts +9 -9
- package/src/irdevice/waterheater.ts +9 -9
- package/src/platform.ts +228 -228
|
@@ -148,7 +148,7 @@ export class CeilingLight extends deviceBase {
|
|
|
148
148
|
}
|
|
149
149
|
catch (e) {
|
|
150
150
|
await this.apiError(e);
|
|
151
|
-
|
|
151
|
+
this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
152
152
|
}
|
|
153
153
|
this.ceilingLightUpdateInProgress = false;
|
|
154
154
|
});
|
|
@@ -157,36 +157,36 @@ export class CeilingLight extends deviceBase {
|
|
|
157
157
|
* Parse the device status from the SwitchBotBLE API
|
|
158
158
|
*/
|
|
159
159
|
async BLEparseStatus() {
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
this.debugLog('BLEparseStatus');
|
|
161
|
+
this.debugLog(`(power, brightness, colorTemperature) = BLE:(${this.serviceData.state}, ${this.serviceData.brightness}, ${this.serviceData.color_temperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
162
162
|
// On
|
|
163
163
|
this.LightBulb.On = this.serviceData.state;
|
|
164
|
-
|
|
164
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
165
165
|
// ColorTemperature
|
|
166
166
|
const miredColorTemperature = Math.round(1000000 / this.serviceData.color_temperature);
|
|
167
167
|
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
168
|
-
|
|
168
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
169
169
|
}
|
|
170
170
|
/**
|
|
171
171
|
* Parse the device status from the SwitchBot OpenAPI
|
|
172
172
|
*/
|
|
173
173
|
async openAPIparseStatus() {
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
this.debugLog('openAPIparseStatus');
|
|
175
|
+
this.debugLog(`(power, brightness, colorTemperature) = OpenAPI:(${this.deviceStatus.power}, ${this.deviceStatus.brightness}, ${this.deviceStatus.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
176
176
|
// On
|
|
177
177
|
this.LightBulb.On = this.deviceStatus.power;
|
|
178
|
-
|
|
178
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
179
179
|
// Brightness
|
|
180
180
|
this.LightBulb.Brightness = this.deviceStatus.brightness;
|
|
181
|
-
|
|
181
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
182
182
|
// ColorTemperature
|
|
183
183
|
const miredColorTemperature = Math.round(1000000 / this.deviceStatus.colorTemperature);
|
|
184
184
|
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
185
|
-
|
|
185
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
186
186
|
// Firmware Version
|
|
187
187
|
if (this.deviceStatus.version) {
|
|
188
188
|
const version = this.deviceStatus.version.toString();
|
|
189
|
-
|
|
189
|
+
this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
190
190
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
191
191
|
this.accessory
|
|
192
192
|
.getService(this.hap.Service.AccessoryInformation)
|
|
@@ -195,29 +195,29 @@ export class CeilingLight extends deviceBase {
|
|
|
195
195
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
196
196
|
.updateValue(deviceVersion);
|
|
197
197
|
this.accessory.context.version = deviceVersion;
|
|
198
|
-
|
|
198
|
+
this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
199
199
|
}
|
|
200
200
|
}
|
|
201
201
|
async parseStatusWebhook() {
|
|
202
|
-
|
|
203
|
-
|
|
202
|
+
this.debugLog('parseStatusWebhook');
|
|
203
|
+
this.debugLog(`(powerState, brightness, colorTemperature) = Webhook:(${this.webhookContext.powerState}, ${this.webhookContext.brightness}, ${this.webhookContext.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
204
204
|
// On
|
|
205
205
|
this.LightBulb.On = this.webhookContext.powerState === 'ON';
|
|
206
|
-
|
|
206
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
207
207
|
// Brightness
|
|
208
208
|
this.LightBulb.Brightness = this.webhookContext.brightness;
|
|
209
|
-
|
|
209
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
210
210
|
// ColorTemperature
|
|
211
211
|
const miredColorTemperature = Math.round(1000000 / this.webhookContext.colorTemperature);
|
|
212
212
|
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
213
|
-
|
|
213
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* Asks the SwitchBot API for the latest device information
|
|
217
217
|
*/
|
|
218
218
|
async refreshStatus() {
|
|
219
219
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
220
|
-
|
|
220
|
+
this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
221
221
|
}
|
|
222
222
|
else if (this.BLE) {
|
|
223
223
|
await this.BLERefreshStatus();
|
|
@@ -227,11 +227,11 @@ export class CeilingLight extends deviceBase {
|
|
|
227
227
|
}
|
|
228
228
|
else {
|
|
229
229
|
await this.offlineOff();
|
|
230
|
-
|
|
230
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
async BLERefreshStatus() {
|
|
234
|
-
|
|
234
|
+
this.debugLog('BLERefreshStatus');
|
|
235
235
|
const switchBotBLE = await this.switchbotBLE();
|
|
236
236
|
if (switchBotBLE === undefined) {
|
|
237
237
|
await this.BLERefreshConnection(switchBotBLE);
|
|
@@ -247,79 +247,79 @@ export class CeilingLight extends deviceBase {
|
|
|
247
247
|
await this.updateHomeKitCharacteristics();
|
|
248
248
|
}
|
|
249
249
|
else {
|
|
250
|
-
|
|
250
|
+
this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`);
|
|
251
251
|
await this.BLERefreshConnection(switchBotBLE);
|
|
252
252
|
}
|
|
253
253
|
})();
|
|
254
254
|
}
|
|
255
255
|
}
|
|
256
256
|
async registerPlatformBLE() {
|
|
257
|
-
|
|
257
|
+
this.debugLog('registerPlatformBLE');
|
|
258
258
|
if (this.config.options?.BLE) {
|
|
259
|
-
|
|
259
|
+
this.debugLog('is listening to Platform BLE.');
|
|
260
260
|
try {
|
|
261
261
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
262
262
|
this.device.bleMac = formattedDeviceId;
|
|
263
|
-
|
|
263
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
264
264
|
this.platform.bleEventHandler[this.device.bleMac] = async (context) => {
|
|
265
265
|
try {
|
|
266
|
-
|
|
266
|
+
this.debugLog(`received BLE: ${JSON.stringify(context)}`);
|
|
267
267
|
this.serviceData = context;
|
|
268
268
|
await this.BLEparseStatus();
|
|
269
269
|
await this.updateHomeKitCharacteristics();
|
|
270
270
|
}
|
|
271
271
|
catch (e) {
|
|
272
|
-
|
|
272
|
+
this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
273
273
|
}
|
|
274
274
|
};
|
|
275
275
|
}
|
|
276
276
|
catch (error) {
|
|
277
|
-
|
|
277
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
278
278
|
}
|
|
279
279
|
}
|
|
280
280
|
else {
|
|
281
|
-
|
|
281
|
+
this.debugLog('is not listening to Platform BLE');
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
async openAPIRefreshStatus() {
|
|
285
|
-
|
|
285
|
+
this.debugLog('openAPIRefreshStatus');
|
|
286
286
|
try {
|
|
287
|
-
const
|
|
288
|
-
const deviceStatus =
|
|
289
|
-
|
|
287
|
+
const response = await this.deviceRefreshStatus();
|
|
288
|
+
const deviceStatus = response.body;
|
|
289
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
290
290
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
291
|
-
|
|
291
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
292
292
|
this.deviceStatus = deviceStatus.body;
|
|
293
293
|
await this.openAPIparseStatus();
|
|
294
294
|
await this.updateHomeKitCharacteristics();
|
|
295
295
|
}
|
|
296
296
|
else {
|
|
297
|
-
|
|
298
|
-
|
|
297
|
+
this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
298
|
+
this.debugWarnLog(deviceStatus);
|
|
299
299
|
}
|
|
300
300
|
}
|
|
301
301
|
catch (e) {
|
|
302
302
|
await this.apiError(e);
|
|
303
|
-
|
|
303
|
+
this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
304
304
|
}
|
|
305
305
|
}
|
|
306
306
|
async registerWebhook() {
|
|
307
307
|
if (this.device.webhook) {
|
|
308
|
-
|
|
308
|
+
this.debugLog('is listening webhook.');
|
|
309
309
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
310
310
|
try {
|
|
311
|
-
|
|
311
|
+
this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
312
312
|
this.webhookContext = context;
|
|
313
313
|
await this.parseStatusWebhook();
|
|
314
314
|
await this.updateHomeKitCharacteristics();
|
|
315
315
|
}
|
|
316
316
|
catch (e) {
|
|
317
|
-
|
|
317
|
+
this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`);
|
|
318
318
|
}
|
|
319
319
|
};
|
|
320
320
|
}
|
|
321
321
|
else {
|
|
322
|
-
|
|
322
|
+
this.debugLog('is not listening webhook.');
|
|
323
323
|
}
|
|
324
324
|
}
|
|
325
325
|
/**
|
|
@@ -335,7 +335,7 @@ export class CeilingLight extends deviceBase {
|
|
|
335
335
|
*/
|
|
336
336
|
async pushChanges() {
|
|
337
337
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
338
|
-
|
|
338
|
+
this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
339
339
|
}
|
|
340
340
|
else if (this.BLE) {
|
|
341
341
|
await this.BLEpushChanges();
|
|
@@ -343,24 +343,24 @@ export class CeilingLight extends deviceBase {
|
|
|
343
343
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
344
344
|
await this.openAPIpushChanges();
|
|
345
345
|
if (this.LightBulb.On) {
|
|
346
|
-
|
|
346
|
+
this.debugLog(`On: ${this.LightBulb.On}`);
|
|
347
347
|
// Push Brightness Update
|
|
348
|
-
|
|
348
|
+
this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
349
349
|
await this.pushBrightnessChanges();
|
|
350
350
|
// Push ColorTemperature Update
|
|
351
|
-
|
|
351
|
+
this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
352
352
|
await this.pushColorTemperatureChanges();
|
|
353
353
|
// Push Hue & Saturation Update
|
|
354
|
-
|
|
354
|
+
this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
355
355
|
await this.pushHueSaturationChanges();
|
|
356
356
|
}
|
|
357
357
|
else {
|
|
358
|
-
|
|
358
|
+
this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
361
|
else {
|
|
362
362
|
await this.offlineOff();
|
|
363
|
-
|
|
363
|
+
this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
364
364
|
}
|
|
365
365
|
// Refresh the status from the API
|
|
366
366
|
interval(15000)
|
|
@@ -371,14 +371,14 @@ export class CeilingLight extends deviceBase {
|
|
|
371
371
|
});
|
|
372
372
|
}
|
|
373
373
|
async BLEpushChanges() {
|
|
374
|
-
|
|
374
|
+
this.debugLog('BLEpushChanges');
|
|
375
375
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
376
|
-
|
|
376
|
+
this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
377
377
|
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device);
|
|
378
378
|
try {
|
|
379
379
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId);
|
|
380
380
|
this.device.bleMac = formattedDeviceId;
|
|
381
|
-
|
|
381
|
+
this.debugLog(`bleMac: ${this.device.bleMac}`);
|
|
382
382
|
if (switchBotBLE !== false) {
|
|
383
383
|
switchBotBLE
|
|
384
384
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
@@ -386,7 +386,7 @@ export class CeilingLight extends deviceBase {
|
|
|
386
386
|
const deviceList = device_list[0];
|
|
387
387
|
this.infoLog(`On: ${this.LightBulb.On}`);
|
|
388
388
|
return await this.retryBLE({
|
|
389
|
-
max:
|
|
389
|
+
max: this.maxRetryBLE(),
|
|
390
390
|
fn: async () => {
|
|
391
391
|
if (this.LightBulb.On) {
|
|
392
392
|
return await deviceList[0].turnOn();
|
|
@@ -398,30 +398,30 @@ export class CeilingLight extends deviceBase {
|
|
|
398
398
|
});
|
|
399
399
|
})
|
|
400
400
|
.then(async () => {
|
|
401
|
-
|
|
401
|
+
this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
402
402
|
this.LightBulb.On = false;
|
|
403
403
|
})
|
|
404
404
|
.catch(async (e) => {
|
|
405
405
|
await this.apiError(e);
|
|
406
|
-
|
|
406
|
+
this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
407
407
|
await this.BLEPushConnection();
|
|
408
408
|
});
|
|
409
409
|
}
|
|
410
410
|
else {
|
|
411
|
-
|
|
411
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`);
|
|
412
412
|
await this.BLEPushConnection();
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
catch (error) {
|
|
416
|
-
|
|
416
|
+
this.errorLog(`failed to format device ID as MAC, Error: ${error}`);
|
|
417
417
|
}
|
|
418
418
|
}
|
|
419
419
|
else {
|
|
420
|
-
|
|
420
|
+
this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
async openAPIpushChanges() {
|
|
424
|
-
|
|
424
|
+
this.debugLog('openAPIpushChanges');
|
|
425
425
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
426
426
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
427
427
|
const bodyChange = {
|
|
@@ -429,13 +429,13 @@ export class CeilingLight extends deviceBase {
|
|
|
429
429
|
parameter: 'default',
|
|
430
430
|
commandType: 'command',
|
|
431
431
|
};
|
|
432
|
-
|
|
432
|
+
this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
433
433
|
try {
|
|
434
|
-
const
|
|
435
|
-
const deviceStatus =
|
|
436
|
-
|
|
434
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
435
|
+
const deviceStatus = response.body;
|
|
436
|
+
this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
437
437
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
438
|
-
|
|
438
|
+
this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
439
439
|
await this.updateHomeKitCharacteristics();
|
|
440
440
|
}
|
|
441
441
|
else {
|
|
@@ -444,32 +444,32 @@ export class CeilingLight extends deviceBase {
|
|
|
444
444
|
}
|
|
445
445
|
catch (e) {
|
|
446
446
|
await this.apiError(e);
|
|
447
|
-
|
|
447
|
+
this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
448
448
|
}
|
|
449
449
|
}
|
|
450
450
|
else {
|
|
451
|
-
|
|
451
|
+
this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
452
452
|
}
|
|
453
453
|
}
|
|
454
454
|
async pushHueSaturationChanges() {
|
|
455
|
-
|
|
455
|
+
this.debugLog('pushHueSaturationChanges');
|
|
456
456
|
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
457
|
-
|
|
458
|
-
|
|
457
|
+
this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
|
|
458
|
+
this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
459
459
|
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
|
|
460
|
-
|
|
460
|
+
this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
461
461
|
const bodyChange = {
|
|
462
462
|
command: 'setColor',
|
|
463
463
|
parameter: `${red}:${green}:${blue}`,
|
|
464
464
|
commandType: 'command',
|
|
465
465
|
};
|
|
466
|
-
|
|
466
|
+
this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
467
467
|
try {
|
|
468
|
-
const
|
|
469
|
-
const deviceStatus =
|
|
470
|
-
|
|
468
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
469
|
+
const deviceStatus = response.body;
|
|
470
|
+
this.debugLog(`(pushHueSaturationChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
471
471
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
472
|
-
|
|
472
|
+
this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
473
473
|
await this.updateHomeKitCharacteristics();
|
|
474
474
|
}
|
|
475
475
|
else {
|
|
@@ -478,15 +478,15 @@ export class CeilingLight extends deviceBase {
|
|
|
478
478
|
}
|
|
479
479
|
catch (e) {
|
|
480
480
|
await this.apiError(e);
|
|
481
|
-
|
|
481
|
+
this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
482
482
|
}
|
|
483
483
|
}
|
|
484
484
|
else {
|
|
485
|
-
|
|
485
|
+
this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
486
486
|
}
|
|
487
487
|
}
|
|
488
488
|
async pushColorTemperatureChanges() {
|
|
489
|
-
|
|
489
|
+
this.debugLog('pushColorTemperatureChanges');
|
|
490
490
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
491
491
|
const kelvin = Math.round(1000000 * Number(this.LightBulb.ColorTemperature));
|
|
492
492
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -495,13 +495,13 @@ export class CeilingLight extends deviceBase {
|
|
|
495
495
|
parameter: `${kelvin}`,
|
|
496
496
|
commandType: 'command',
|
|
497
497
|
};
|
|
498
|
-
|
|
498
|
+
this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
499
499
|
try {
|
|
500
|
-
const
|
|
501
|
-
const deviceStatus =
|
|
502
|
-
|
|
500
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
501
|
+
const deviceStatus = response.body;
|
|
502
|
+
this.debugLog(`(pushColorTemperatureChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
503
503
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
504
|
-
|
|
504
|
+
this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
505
505
|
await this.updateHomeKitCharacteristics();
|
|
506
506
|
}
|
|
507
507
|
else {
|
|
@@ -510,28 +510,28 @@ export class CeilingLight extends deviceBase {
|
|
|
510
510
|
}
|
|
511
511
|
catch (e) {
|
|
512
512
|
await this.apiError(e);
|
|
513
|
-
|
|
513
|
+
this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
514
514
|
}
|
|
515
515
|
}
|
|
516
516
|
else {
|
|
517
|
-
|
|
517
|
+
this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
async pushBrightnessChanges() {
|
|
521
|
-
|
|
521
|
+
this.debugLog('pushBrightnessChanges');
|
|
522
522
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
523
523
|
const bodyChange = {
|
|
524
524
|
command: 'setBrightness',
|
|
525
525
|
parameter: `${this.LightBulb.Brightness}`,
|
|
526
526
|
commandType: 'command',
|
|
527
527
|
};
|
|
528
|
-
|
|
528
|
+
this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
529
529
|
try {
|
|
530
|
-
const
|
|
531
|
-
const deviceStatus =
|
|
532
|
-
|
|
530
|
+
const response = await this.pushChangeRequest(bodyChange);
|
|
531
|
+
const deviceStatus = response.body;
|
|
532
|
+
this.debugLog(`(pushBrightnessChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
533
533
|
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
534
|
-
|
|
534
|
+
this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
535
535
|
await this.updateHomeKitCharacteristics();
|
|
536
536
|
}
|
|
537
537
|
else {
|
|
@@ -540,11 +540,11 @@ export class CeilingLight extends deviceBase {
|
|
|
540
540
|
}
|
|
541
541
|
catch (e) {
|
|
542
542
|
await this.apiError(e);
|
|
543
|
-
|
|
543
|
+
this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
544
544
|
}
|
|
545
545
|
}
|
|
546
546
|
else {
|
|
547
|
-
|
|
547
|
+
this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness}, BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
548
548
|
}
|
|
549
549
|
}
|
|
550
550
|
/**
|
|
@@ -552,10 +552,10 @@ export class CeilingLight extends deviceBase {
|
|
|
552
552
|
*/
|
|
553
553
|
async OnSet(value) {
|
|
554
554
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
555
|
-
|
|
555
|
+
this.infoLog(`Set On: ${value}`);
|
|
556
556
|
}
|
|
557
557
|
else {
|
|
558
|
-
|
|
558
|
+
this.debugLog(`No Changes, Set On: ${value}`);
|
|
559
559
|
}
|
|
560
560
|
this.LightBulb.On = value;
|
|
561
561
|
this.doCeilingLightUpdate.next();
|
|
@@ -565,7 +565,7 @@ export class CeilingLight extends deviceBase {
|
|
|
565
565
|
*/
|
|
566
566
|
async BrightnessSet(value) {
|
|
567
567
|
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
568
|
-
|
|
568
|
+
this.infoLog(`Set Brightness: ${value}`);
|
|
569
569
|
}
|
|
570
570
|
else {
|
|
571
571
|
if (this.LightBulb.On) {
|
|
@@ -662,21 +662,21 @@ export class CeilingLight extends deviceBase {
|
|
|
662
662
|
async getAdaptiveLightingSettings(accessory, device) {
|
|
663
663
|
// Adaptive Lighting
|
|
664
664
|
this.adaptiveLighting = accessory.context.adaptiveLighting ?? true;
|
|
665
|
-
|
|
665
|
+
this.debugLog(`adaptiveLighting: ${this.adaptiveLighting}`);
|
|
666
666
|
// Adaptive Lighting Shift
|
|
667
667
|
this.adaptiveLightingShift = device.adaptiveLightingShift ?? 0;
|
|
668
668
|
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
669
669
|
}
|
|
670
670
|
async BLEPushConnection() {
|
|
671
671
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
672
|
-
|
|
672
|
+
this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
673
673
|
await this.openAPIpushChanges();
|
|
674
674
|
}
|
|
675
675
|
}
|
|
676
676
|
async BLERefreshConnection(switchbot) {
|
|
677
|
-
|
|
677
|
+
this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
678
678
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
679
|
-
|
|
679
|
+
this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
680
680
|
await this.openAPIRefreshStatus();
|
|
681
681
|
}
|
|
682
682
|
}
|