@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.4
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.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +102 -128
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/src/device/colorbulb.ts
CHANGED
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
* blindtilt.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import { interval, Subject } from 'rxjs';
|
|
7
6
|
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
8
|
-
import {
|
|
7
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
|
+
import { Subject, debounceTime, interval, skipWhile, take, tap } from 'rxjs';
|
|
9
9
|
|
|
10
|
+
import type { devicesConfig } from '../settings.js';
|
|
11
|
+
import type { device } from '../types/devicelist.js';
|
|
10
12
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
11
|
-
import type {
|
|
13
|
+
import type { colorBulbServiceData } from '../types/bledevicestatus.js';
|
|
14
|
+
import type { colorBulbStatus } from '../types/devicestatus.js';
|
|
15
|
+
import type { colorBulbWebhookContext } from '../types/devicewebhookstatus.js';
|
|
12
16
|
import type { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
13
17
|
|
|
14
18
|
/**
|
|
@@ -67,7 +71,7 @@ export class ColorBulb extends deviceBase {
|
|
|
67
71
|
accessory.removeService(this.LightBulb.Service);
|
|
68
72
|
this.LightBulb.Service = accessory.addService(this.hap.Service.Lightbulb);
|
|
69
73
|
accessory.context.adaptiveLighting = false;
|
|
70
|
-
this.debugLog(
|
|
74
|
+
this.debugLog(`adaptiveLighting: ${accessory.context.adaptiveLighting}`);
|
|
71
75
|
}
|
|
72
76
|
if (this.adaptiveLightingShift !== -1) {
|
|
73
77
|
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
@@ -144,6 +148,9 @@ export class ColorBulb extends deviceBase {
|
|
|
144
148
|
// Update Homekit
|
|
145
149
|
this.updateHomeKitCharacteristics();
|
|
146
150
|
|
|
151
|
+
//regisiter webhook event handler
|
|
152
|
+
this.registerWebhook();
|
|
153
|
+
|
|
147
154
|
// Start an update interval
|
|
148
155
|
interval(this.deviceRefreshRate * 1000)
|
|
149
156
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
@@ -151,9 +158,6 @@ export class ColorBulb extends deviceBase {
|
|
|
151
158
|
await this.refreshStatus();
|
|
152
159
|
});
|
|
153
160
|
|
|
154
|
-
//regisiter webhook event handler
|
|
155
|
-
this.registerWebhook(accessory, device);
|
|
156
|
-
|
|
157
161
|
// Watch for Bulb change events
|
|
158
162
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
159
163
|
this.doColorBulbUpdate
|
|
@@ -167,9 +171,8 @@ export class ColorBulb extends deviceBase {
|
|
|
167
171
|
try {
|
|
168
172
|
await this.pushChanges();
|
|
169
173
|
} catch (e: any) {
|
|
170
|
-
this.apiError(e);
|
|
171
|
-
this.errorLog(
|
|
172
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
174
|
+
await this.apiError(e);
|
|
175
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
173
176
|
}
|
|
174
177
|
this.colorBulbUpdateInProgress = false;
|
|
175
178
|
});
|
|
@@ -178,104 +181,68 @@ export class ColorBulb extends deviceBase {
|
|
|
178
181
|
/**
|
|
179
182
|
* Parse the device status from the SwitchBotBLE API
|
|
180
183
|
*/
|
|
181
|
-
async BLEparseStatus(serviceData:
|
|
182
|
-
this.debugLog(
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
this.LightBulb.On = true;
|
|
187
|
-
break;
|
|
188
|
-
default:
|
|
189
|
-
this.LightBulb.On = false;
|
|
190
|
-
}
|
|
191
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
192
|
-
|
|
184
|
+
async BLEparseStatus(serviceData: colorBulbServiceData): Promise<void> {
|
|
185
|
+
await this.debugLog('BLEparseStatus');
|
|
186
|
+
// On
|
|
187
|
+
this.LightBulb.On = serviceData.power;
|
|
188
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
193
189
|
// Brightness
|
|
194
|
-
this.LightBulb.Brightness =
|
|
195
|
-
this.debugLog(
|
|
196
|
-
|
|
190
|
+
this.LightBulb.Brightness = serviceData.brightness;
|
|
191
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
197
192
|
// Color, Hue & Brightness
|
|
198
|
-
this.debugLog(
|
|
199
|
-
|
|
200
|
-
this.debugLog(
|
|
201
|
-
|
|
202
|
-
const [hue, saturation] = rgb2hs(Number(serviceData.red), Number(serviceData.green), Number(serviceData.blue));
|
|
203
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
204
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(serviceData.red), Number(serviceData.green), Number(serviceData.blue)))}`);
|
|
205
|
-
|
|
193
|
+
await this.debugLog(`red: ${serviceData.red}, green: ${serviceData.green}, blue: ${serviceData.blue}`);
|
|
194
|
+
const [hue, saturation] = rgb2hs(serviceData.red, serviceData.green, serviceData.blue);
|
|
195
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(serviceData.red, serviceData.green, serviceData.blue))}`);
|
|
206
196
|
// Hue
|
|
207
197
|
this.LightBulb.Hue = hue;
|
|
208
|
-
this.debugLog(
|
|
209
|
-
|
|
198
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
210
199
|
// Saturation
|
|
211
200
|
this.LightBulb.Saturation = saturation;
|
|
212
|
-
this.debugLog(
|
|
213
|
-
|
|
201
|
+
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
214
202
|
// ColorTemperature
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
this.LightBulb.ColorTemperature = serviceData.color_temperature!;
|
|
218
|
-
|
|
219
|
-
this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
|
|
220
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
221
|
-
}
|
|
203
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(serviceData.color_temperature, 500), 140);
|
|
204
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
222
205
|
}
|
|
223
206
|
|
|
224
207
|
/**
|
|
225
208
|
* Parse the device status from the SwitchBot OpenAPI
|
|
226
209
|
*/
|
|
227
|
-
async openAPIparseStatus(deviceStatus:
|
|
228
|
-
this.debugLog(
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
default:
|
|
234
|
-
this.LightBulb.On = false;
|
|
235
|
-
}
|
|
236
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
210
|
+
async openAPIparseStatus(deviceStatus: colorBulbStatus): Promise<void> {
|
|
211
|
+
await this.debugLog('openAPIparseStatus');
|
|
212
|
+
|
|
213
|
+
// On
|
|
214
|
+
this.LightBulb.On = deviceStatus.power === 'on' ? true : false;
|
|
215
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
237
216
|
|
|
238
217
|
// Brightness
|
|
239
|
-
this.LightBulb.Brightness =
|
|
240
|
-
this.debugLog(
|
|
218
|
+
this.LightBulb.Brightness = deviceStatus.brightness;
|
|
219
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
241
220
|
|
|
242
221
|
// Color, Hue & Brightness
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
249
|
-
|
|
250
|
-
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
251
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
252
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
253
|
-
|
|
254
|
-
// Hue
|
|
255
|
-
this.LightBulb.Hue = hue;
|
|
256
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
257
|
-
|
|
258
|
-
// Saturation
|
|
259
|
-
this.LightBulb.Saturation = saturation;
|
|
260
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
261
|
-
}
|
|
222
|
+
await this.debugLog(`color: ${JSON.stringify(deviceStatus.color)}`);
|
|
223
|
+
const [red, green, blue] = deviceStatus.color.split(':');
|
|
224
|
+
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
225
|
+
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
226
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
262
227
|
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const mired = Math.round(1000000 / deviceStatus.body.colorTemperature!);
|
|
228
|
+
// Hue
|
|
229
|
+
this.LightBulb.Hue = hue;
|
|
230
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
267
231
|
|
|
268
|
-
|
|
232
|
+
// Saturation
|
|
233
|
+
this.LightBulb.Saturation = saturation;
|
|
234
|
+
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
269
235
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
236
|
+
// ColorTemperature
|
|
237
|
+
const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
|
|
238
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
239
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
273
240
|
|
|
274
241
|
// Firmware Version
|
|
275
|
-
const version = deviceStatus.
|
|
276
|
-
this.debugLog(
|
|
277
|
-
if (deviceStatus.
|
|
278
|
-
const deviceVersion = version
|
|
242
|
+
const version = deviceStatus.version.toString();
|
|
243
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
244
|
+
if (deviceStatus.version) {
|
|
245
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
279
246
|
this.accessory
|
|
280
247
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
281
248
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -283,29 +250,56 @@ export class ColorBulb extends deviceBase {
|
|
|
283
250
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
284
251
|
.updateValue(deviceVersion);
|
|
285
252
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
286
|
-
this.debugSuccessLog(
|
|
253
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
287
254
|
}
|
|
288
255
|
}
|
|
289
256
|
|
|
257
|
+
async parseStatusWebhook(context: colorBulbWebhookContext): Promise<void> {
|
|
258
|
+
await this.debugLog('parseStatusWebhook');
|
|
259
|
+
await this.debugLog(`(powerState, brightness, color, colorTemperature) = Webhook:(${context.powerState}, ${context.brightness}, ${context.color},`
|
|
260
|
+
+ ` ${context.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.Hue},`
|
|
261
|
+
+ ` ${this.LightBulb.Saturation}, ${this.LightBulb.ColorTemperature})`);
|
|
262
|
+
// On
|
|
263
|
+
this.LightBulb.On = context.powerState === 'ON' ? true : false;
|
|
264
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
265
|
+
// Brightness
|
|
266
|
+
this.LightBulb.Brightness = context.brightness;
|
|
267
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
268
|
+
// Color, Hue & Brightness
|
|
269
|
+
await this.debugLog(`color: ${JSON.stringify(context.color)}`);
|
|
270
|
+
const [red, green, blue] = context.color.split(':');
|
|
271
|
+
await this.debugLog(`red: ${JSON.stringify(red)}, green: ${JSON.stringify(green)}, blue: ${JSON.stringify(blue)}`);
|
|
272
|
+
const [hue, saturation] = rgb2hs(red, green, blue);
|
|
273
|
+
await this.debugLog(`hs: ${JSON.stringify(rgb2hs(red, green, blue))}`);
|
|
274
|
+
// Hue
|
|
275
|
+
this.LightBulb.Hue = hue;
|
|
276
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}`);
|
|
277
|
+
// Saturation
|
|
278
|
+
this.LightBulb.Saturation = saturation;
|
|
279
|
+
await this.debugLog(`Saturation: ${this.LightBulb.Saturation}`);
|
|
280
|
+
// ColorTemperature
|
|
281
|
+
this.LightBulb.ColorTemperature = context.colorTemperature;
|
|
282
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
283
|
+
}
|
|
284
|
+
|
|
290
285
|
/**
|
|
291
286
|
* Asks the SwitchBot API for the latest device information
|
|
292
287
|
*/
|
|
293
288
|
async refreshStatus(): Promise<void> {
|
|
294
289
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
295
|
-
this.errorLog(
|
|
290
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
296
291
|
} else if (this.BLE) {
|
|
297
292
|
await this.BLERefreshStatus();
|
|
298
293
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
299
294
|
await this.openAPIRefreshStatus();
|
|
300
295
|
} else {
|
|
301
296
|
await this.offlineOff();
|
|
302
|
-
this.debugWarnLog(
|
|
303
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
297
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
304
298
|
}
|
|
305
299
|
}
|
|
306
300
|
|
|
307
301
|
async BLERefreshStatus(): Promise<void> {
|
|
308
|
-
this.debugLog(
|
|
302
|
+
await this.debugLog('BLERefreshStatus');
|
|
309
303
|
const switchbot = await this.switchbotBLE();
|
|
310
304
|
|
|
311
305
|
if (switchbot === undefined) {
|
|
@@ -314,13 +308,13 @@ export class ColorBulb extends deviceBase {
|
|
|
314
308
|
// Start to monitor advertisement packets
|
|
315
309
|
(async () => {
|
|
316
310
|
// Start to monitor advertisement packets
|
|
317
|
-
const serviceData
|
|
311
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as colorBulbServiceData;
|
|
318
312
|
// Update HomeKit
|
|
319
|
-
if (serviceData.model
|
|
313
|
+
if (serviceData.model === SwitchBotBLEModel.ColorBulb && serviceData.modelName === SwitchBotBLEModelName.ColorBulb) {
|
|
320
314
|
await this.BLEparseStatus(serviceData);
|
|
321
315
|
await this.updateHomeKitCharacteristics();
|
|
322
316
|
} else {
|
|
323
|
-
this.errorLog(
|
|
317
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
324
318
|
await this.BLERefreshConnection(switchbot);
|
|
325
319
|
}
|
|
326
320
|
})();
|
|
@@ -328,94 +322,39 @@ export class ColorBulb extends deviceBase {
|
|
|
328
322
|
}
|
|
329
323
|
|
|
330
324
|
async openAPIRefreshStatus(): Promise<void> {
|
|
331
|
-
this.debugLog(
|
|
325
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
332
326
|
try {
|
|
333
327
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
334
328
|
const deviceStatus: any = await body.json();
|
|
335
|
-
await this.
|
|
336
|
-
if (
|
|
337
|
-
await this.
|
|
338
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
329
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
330
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
331
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
332
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
339
333
|
await this.updateHomeKitCharacteristics();
|
|
340
334
|
} else {
|
|
341
|
-
await this.
|
|
335
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
336
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
342
337
|
}
|
|
343
338
|
} catch (e: any) {
|
|
344
339
|
await this.apiError(e);
|
|
345
|
-
await this.
|
|
340
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
346
341
|
}
|
|
347
342
|
}
|
|
348
343
|
|
|
349
|
-
async registerWebhook(
|
|
350
|
-
if (device.webhook) {
|
|
351
|
-
this.debugLog(
|
|
352
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
344
|
+
async registerWebhook() {
|
|
345
|
+
if (this.device.webhook) {
|
|
346
|
+
await this.debugLog('is listening webhook.');
|
|
347
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: colorBulbWebhookContext) => {
|
|
353
348
|
try {
|
|
354
|
-
this.debugLog(
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
|
|
358
|
-
'(powerState, brightness, color, colorTemperature) = ' +
|
|
359
|
-
`Webhook:(${powerState}, ${brightness}, ${color}, ${colorTemperature}), `
|
|
360
|
-
+ `current:(${On}, ${Brightness}, ${Hue}, ${Saturation}, ${ColorTemperature})`);
|
|
361
|
-
|
|
362
|
-
// On
|
|
363
|
-
this.LightBulb.On = powerState === 'ON' ? true : false;
|
|
364
|
-
if (accessory.context.Brightness !== this.LightBulb.On) {
|
|
365
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
366
|
-
} else {
|
|
367
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
// Brightness
|
|
371
|
-
this.LightBulb.Brightness = brightness;
|
|
372
|
-
if (accessory.context.Brightness !== this.LightBulb.Brightness) {
|
|
373
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
374
|
-
} else {
|
|
375
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} color: ${JSON.stringify(color)}`);
|
|
379
|
-
const [red, green, blue] = color!.split(':');
|
|
380
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
381
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
382
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
383
|
-
|
|
384
|
-
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
385
|
-
this.debugLog(
|
|
386
|
-
`${device.deviceType}: ${accessory.displayName}`
|
|
387
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
388
|
-
|
|
389
|
-
// Hue
|
|
390
|
-
this.LightBulb.Hue = hue;
|
|
391
|
-
if (accessory.context.Hue !== this.LightBulb.Hue) {
|
|
392
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
393
|
-
} else {
|
|
394
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// Saturation
|
|
398
|
-
this.LightBulb.Saturation = saturation;
|
|
399
|
-
if (accessory.context.Saturation !== this.LightBulb.Saturation) {
|
|
400
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
401
|
-
} else {
|
|
402
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
this.LightBulb.ColorTemperature = colorTemperature;
|
|
406
|
-
if (accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
|
|
407
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
408
|
-
} else {
|
|
409
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
410
|
-
}
|
|
411
|
-
this.updateHomeKitCharacteristics();
|
|
349
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
350
|
+
await this.parseStatusWebhook(context);
|
|
351
|
+
await this.updateHomeKitCharacteristics();
|
|
412
352
|
} catch (e: any) {
|
|
413
|
-
this.errorLog(
|
|
414
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
353
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
415
354
|
}
|
|
416
355
|
};
|
|
417
356
|
} else {
|
|
418
|
-
this.
|
|
357
|
+
await this.debugLog('is not listening webhook.');
|
|
419
358
|
}
|
|
420
359
|
}
|
|
421
360
|
|
|
@@ -432,14 +371,40 @@ export class ColorBulb extends deviceBase {
|
|
|
432
371
|
*/
|
|
433
372
|
async pushChanges(): Promise<void> {
|
|
434
373
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
435
|
-
this.errorLog(
|
|
374
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
436
375
|
} else if (this.BLE) {
|
|
437
376
|
await this.BLEpushChanges();
|
|
377
|
+
if (this.LightBulb.On) {
|
|
378
|
+
// Push Brightness Update
|
|
379
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
380
|
+
await this.BLEpushBrightnessChanges();
|
|
381
|
+
// Push ColorTemperature Update
|
|
382
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
383
|
+
await this.BLEpushColorTemperatureChanges();
|
|
384
|
+
// Push Hue & Saturation Update
|
|
385
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
386
|
+
await this.BLEpushRGBChanges();
|
|
387
|
+
} else {
|
|
388
|
+
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
389
|
+
}
|
|
438
390
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
439
391
|
await this.openAPIpushChanges();
|
|
392
|
+
if (this.LightBulb.On) {
|
|
393
|
+
// Push Brightness Update
|
|
394
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
395
|
+
await this.pushBrightnessChanges();
|
|
396
|
+
// Push ColorTemperature Update
|
|
397
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
398
|
+
await this.pushColorTemperatureChanges();
|
|
399
|
+
// Push Hue & Saturation Update
|
|
400
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
401
|
+
await this.pushHueSaturationChanges();
|
|
402
|
+
} else {
|
|
403
|
+
await this.debugLog('openAPI (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
404
|
+
}
|
|
440
405
|
} else {
|
|
441
406
|
await this.offlineOff();
|
|
442
|
-
await this.
|
|
407
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
443
408
|
}
|
|
444
409
|
// Refresh the status from the API
|
|
445
410
|
interval(15000)
|
|
@@ -451,239 +416,209 @@ export class ColorBulb extends deviceBase {
|
|
|
451
416
|
}
|
|
452
417
|
|
|
453
418
|
async BLEpushChanges(): Promise<void> {
|
|
454
|
-
this.debugLog(
|
|
419
|
+
await this.debugLog('BLEpushChanges');
|
|
455
420
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
456
|
-
this.debugLog(
|
|
457
|
-
|
|
458
|
-
const switchbot = await this.platform.connectBLE();
|
|
459
|
-
// Convert to BLE Address
|
|
421
|
+
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
422
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
460
423
|
await this.convertBLEAddress();
|
|
461
|
-
switchbot
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
424
|
+
if (switchbot !== false) {
|
|
425
|
+
switchbot
|
|
426
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
427
|
+
.then(async (device_list: any) => {
|
|
428
|
+
await this.infoLog(`On: ${this.LightBulb.On}`);
|
|
429
|
+
return await this.retryBLE({
|
|
430
|
+
max: await this.maxRetryBLE(),
|
|
431
|
+
fn: async () => {
|
|
432
|
+
if (this.LightBulb.On) {
|
|
433
|
+
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
434
|
+
} else {
|
|
435
|
+
return await device_list[0].turnOff({ id: this.device.bleMac });
|
|
436
|
+
}
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
})
|
|
440
|
+
.then(async () => {
|
|
441
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
442
|
+
await this.updateHomeKitCharacteristics();
|
|
443
|
+
})
|
|
444
|
+
.catch(async (e: any) => {
|
|
445
|
+
await this.apiError(e);
|
|
446
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
447
|
+
await this.BLEPushConnection();
|
|
474
448
|
});
|
|
475
|
-
|
|
476
|
-
.
|
|
477
|
-
|
|
478
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
479
|
-
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
480
|
-
this.LightBulb.On = false;
|
|
481
|
-
})
|
|
482
|
-
.catch(async (e: any) => {
|
|
483
|
-
this.apiError(e);
|
|
484
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
485
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
486
|
-
await this.BLEPushConnection();
|
|
487
|
-
});
|
|
488
|
-
// Push Brightness Update
|
|
489
|
-
if (this.LightBulb.On) {
|
|
490
|
-
await this.BLEpushBrightnessChanges();
|
|
491
|
-
}
|
|
492
|
-
// Push ColorTemperature Update
|
|
493
|
-
if (this.LightBulb.On) {
|
|
494
|
-
await this.BLEpushColorTemperatureChanges();
|
|
495
|
-
}
|
|
496
|
-
// Push Hue & Saturation Update
|
|
497
|
-
if (this.LightBulb.On) {
|
|
498
|
-
await this.BLEpushRGBChanges();
|
|
449
|
+
} else {
|
|
450
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
451
|
+
await this.BLEPushConnection();
|
|
499
452
|
}
|
|
500
|
-
await this.updateHomeKitCharacteristics();
|
|
501
453
|
} else {
|
|
502
|
-
this.debugLog(
|
|
503
|
-
+ ` OnCached: ${this.accessory.context.On}`);
|
|
454
|
+
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
504
455
|
}
|
|
505
456
|
}
|
|
506
457
|
|
|
507
458
|
async BLEpushBrightnessChanges(): Promise<void> {
|
|
508
|
-
this.debugLog(
|
|
459
|
+
await this.debugLog('BLEpushBrightnessChanges');
|
|
509
460
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
510
|
-
const switchbot = await this.platform.connectBLE();
|
|
511
|
-
// Convert to BLE Address
|
|
461
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
512
462
|
await this.convertBLEAddress();
|
|
513
|
-
switchbot
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
463
|
+
if (switchbot !== false) {
|
|
464
|
+
switchbot
|
|
465
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
466
|
+
.then(async (device_list: any) => {
|
|
467
|
+
await this.infoLog(`${this.accessory.displayName} Target Brightness: ${this.LightBulb.Brightness}`);
|
|
468
|
+
return await device_list[0].setBrightness(this.LightBulb.Brightness);
|
|
469
|
+
})
|
|
470
|
+
.then(async () => {
|
|
471
|
+
await this.successLog(`Brightness: ${this.LightBulb.Brightness} sent over SwitchBot BLE, sent successfully`);
|
|
472
|
+
await this.updateHomeKitCharacteristics();
|
|
473
|
+
})
|
|
474
|
+
.catch(async (e: any) => {
|
|
475
|
+
await this.apiError(e);
|
|
476
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
477
|
+
await this.BLEPushConnection();
|
|
478
|
+
});
|
|
479
|
+
} else {
|
|
480
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
481
|
+
await this.BLEPushConnection();
|
|
482
|
+
}
|
|
529
483
|
} else {
|
|
530
|
-
this.debugLog(
|
|
531
|
-
+ `
|
|
484
|
+
await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
485
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
532
486
|
}
|
|
533
487
|
}
|
|
534
488
|
|
|
535
489
|
async BLEpushColorTemperatureChanges(): Promise<void> {
|
|
536
|
-
this.debugLog(
|
|
490
|
+
await this.debugLog('BLEpushColorTemperatureChanges');
|
|
537
491
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
538
|
-
const switchbot = await this.platform.connectBLE();
|
|
539
|
-
// Convert to BLE Address
|
|
492
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
540
493
|
await this.convertBLEAddress();
|
|
541
|
-
switchbot
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
494
|
+
if (switchbot !== false) {
|
|
495
|
+
switchbot
|
|
496
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
497
|
+
.then(async (device_list: any) => {
|
|
498
|
+
await this.infoLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
499
|
+
return await device_list[0].setColorTemperature(this.LightBulb.ColorTemperature);
|
|
500
|
+
})
|
|
501
|
+
.then(async () => {
|
|
502
|
+
await this.successLog(`ColorTemperature: ${this.LightBulb.ColorTemperature} sent over SwitchBot BLE, sent successfully`);
|
|
503
|
+
await this.updateHomeKitCharacteristics();
|
|
504
|
+
})
|
|
505
|
+
.catch(async (e: any) => {
|
|
506
|
+
await this.apiError(e);
|
|
507
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection,`
|
|
508
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
509
|
+
await this.BLEPushConnection();
|
|
510
|
+
});
|
|
511
|
+
} else {
|
|
512
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
513
|
+
await this.BLEPushConnection();
|
|
514
|
+
}
|
|
557
515
|
} else {
|
|
558
|
-
this.debugLog(
|
|
559
|
-
+ `
|
|
516
|
+
await this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
|
|
517
|
+
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
560
518
|
}
|
|
561
519
|
}
|
|
562
520
|
|
|
563
521
|
async BLEpushRGBChanges(): Promise<void> {
|
|
564
|
-
this.debugLog(
|
|
565
|
-
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
566
|
-
this.debugLog(
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const
|
|
570
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
571
|
-
|
|
572
|
-
const switchbot = await this.platform.connectBLE();
|
|
573
|
-
// Convert to BLE Address
|
|
522
|
+
await this.debugLog('BLEpushRGBChanges');
|
|
523
|
+
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
524
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
525
|
+
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
|
|
526
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
527
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
574
528
|
await this.convertBLEAddress();
|
|
575
|
-
switchbot
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
529
|
+
if (switchbot !== false) {
|
|
530
|
+
switchbot
|
|
531
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
532
|
+
.then(async (device_list: any) => {
|
|
533
|
+
await this.infoLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)}`);
|
|
534
|
+
return await device_list[0].setRGB(this.LightBulb.Brightness, red, green, blue);
|
|
535
|
+
})
|
|
536
|
+
.then(async () => {
|
|
537
|
+
await this.successLog(`RGB: ${(this.LightBulb.Brightness, red, green, blue)} sent over SwitchBot BLE, sent successfully`);
|
|
538
|
+
await this.updateHomeKitCharacteristics();
|
|
539
|
+
})
|
|
540
|
+
.catch(async (e: any) => {
|
|
541
|
+
await this.apiError(e);
|
|
542
|
+
await this.errorLog(`failed BLEpushRGBChanges with ${this.device.connectionType} Connection,`
|
|
543
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
544
|
+
await this.BLEPushConnection();
|
|
545
|
+
});
|
|
546
|
+
} else {
|
|
547
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
548
|
+
await this.BLEPushConnection();
|
|
549
|
+
}
|
|
591
550
|
} else {
|
|
592
|
-
this.debugLog(
|
|
593
|
-
+
|
|
551
|
+
await this.debugLog(`No changes (BLEpushRGBChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
|
|
552
|
+
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
594
553
|
}
|
|
595
554
|
}
|
|
596
555
|
|
|
597
556
|
async openAPIpushChanges(): Promise<void> {
|
|
598
|
-
this.debugLog(
|
|
557
|
+
await this.debugLog('openAPIpushChanges');
|
|
599
558
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
600
|
-
|
|
601
|
-
if (this.LightBulb.On) {
|
|
602
|
-
command = 'turnOn';
|
|
603
|
-
} else {
|
|
604
|
-
command = 'turnOff';
|
|
605
|
-
}
|
|
559
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
606
560
|
const bodyChange = JSON.stringify({
|
|
607
561
|
command: `${command}`,
|
|
608
562
|
parameter: 'default',
|
|
609
563
|
commandType: 'command',
|
|
610
564
|
});
|
|
611
|
-
this.debugLog(
|
|
565
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
612
566
|
try {
|
|
613
567
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
614
568
|
const deviceStatus: any = await body.json();
|
|
615
|
-
await this.
|
|
616
|
-
if (
|
|
617
|
-
this.
|
|
618
|
-
|
|
619
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
620
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
569
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
570
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
571
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
572
|
+
await this.updateHomeKitCharacteristics();
|
|
621
573
|
} else {
|
|
622
|
-
this.statusCode(statusCode);
|
|
623
|
-
this.statusCode(deviceStatus.statusCode);
|
|
574
|
+
await this.statusCode(statusCode);
|
|
575
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
624
576
|
}
|
|
625
577
|
} catch (e: any) {
|
|
626
|
-
this.apiError(e);
|
|
627
|
-
this.errorLog(
|
|
628
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
578
|
+
await this.apiError(e);
|
|
579
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
629
580
|
}
|
|
630
581
|
} else {
|
|
631
|
-
this.debugLog(
|
|
632
|
-
+ `On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
633
|
-
}
|
|
634
|
-
// Push Hue & Saturation Update
|
|
635
|
-
if (this.LightBulb.On) {
|
|
636
|
-
await this.pushHueSaturationChanges();
|
|
637
|
-
}
|
|
638
|
-
// Push ColorTemperature Update
|
|
639
|
-
if (this.LightBulb.On) {
|
|
640
|
-
await this.pushColorTemperatureChanges();
|
|
641
|
-
}
|
|
642
|
-
// Push Brightness Update
|
|
643
|
-
if (this.LightBulb.On) {
|
|
644
|
-
await this.pushBrightnessChanges();
|
|
582
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
645
583
|
}
|
|
646
584
|
}
|
|
647
585
|
|
|
648
586
|
async pushHueSaturationChanges(): Promise<void> {
|
|
649
|
-
this.debugLog(
|
|
650
|
-
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
651
|
-
this.debugLog(
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
587
|
+
await this.debugLog('pushHueSaturationChanges');
|
|
588
|
+
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
589
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
590
|
+
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation);
|
|
591
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
655
592
|
const bodyChange = JSON.stringify({
|
|
656
593
|
command: 'setColor',
|
|
657
594
|
parameter: `${red}:${green}:${blue}`,
|
|
658
595
|
commandType: 'command',
|
|
659
596
|
});
|
|
660
|
-
this.debugLog(
|
|
597
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
661
598
|
try {
|
|
662
599
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
663
600
|
const deviceStatus: any = await body.json();
|
|
664
|
-
await this.
|
|
665
|
-
if (
|
|
666
|
-
this.
|
|
667
|
-
|
|
668
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
669
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
601
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
602
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
603
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
604
|
+
await this.updateHomeKitCharacteristics();
|
|
670
605
|
} else {
|
|
671
|
-
this.statusCode(statusCode);
|
|
672
|
-
this.statusCode(deviceStatus.statusCode);
|
|
606
|
+
await this.statusCode(statusCode);
|
|
607
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
673
608
|
}
|
|
674
609
|
} catch (e: any) {
|
|
675
|
-
this.apiError(e);
|
|
676
|
-
this.errorLog(
|
|
677
|
-
+ `
|
|
610
|
+
await this.apiError(e);
|
|
611
|
+
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
|
|
612
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
678
613
|
}
|
|
679
614
|
} else {
|
|
680
|
-
this.debugLog(
|
|
681
|
-
+
|
|
615
|
+
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
|
|
616
|
+
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
682
617
|
}
|
|
683
618
|
}
|
|
684
619
|
|
|
685
620
|
async pushColorTemperatureChanges(): Promise<void> {
|
|
686
|
-
this.debugLog(
|
|
621
|
+
await this.debugLog('pushColorTemperatureChanges');
|
|
687
622
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
688
623
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
689
624
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -692,61 +627,57 @@ export class ColorBulb extends deviceBase {
|
|
|
692
627
|
parameter: `${kelvin}`,
|
|
693
628
|
commandType: 'command',
|
|
694
629
|
});
|
|
695
|
-
this.debugLog(
|
|
630
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
696
631
|
try {
|
|
697
632
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
698
633
|
const deviceStatus: any = await body.json();
|
|
699
|
-
await this.
|
|
700
|
-
if (
|
|
701
|
-
this.
|
|
702
|
-
|
|
703
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
704
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
634
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
635
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
636
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
637
|
+
await this.updateHomeKitCharacteristics();
|
|
705
638
|
} else {
|
|
706
|
-
this.statusCode(statusCode);
|
|
707
|
-
this.statusCode(deviceStatus.statusCode);
|
|
639
|
+
await this.statusCode(statusCode);
|
|
640
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
708
641
|
}
|
|
709
642
|
} catch (e: any) {
|
|
710
|
-
this.apiError(e);
|
|
711
|
-
this.errorLog(
|
|
712
|
-
+ `
|
|
643
|
+
await this.apiError(e);
|
|
644
|
+
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection,`
|
|
645
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
713
646
|
}
|
|
714
647
|
} else {
|
|
715
|
-
this.debugLog(
|
|
716
|
-
+ `
|
|
648
|
+
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
|
|
649
|
+
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
717
650
|
}
|
|
718
651
|
}
|
|
719
652
|
|
|
720
653
|
async pushBrightnessChanges(): Promise<void> {
|
|
721
|
-
this.debugLog(
|
|
654
|
+
await this.debugLog('pushBrightnessChanges');
|
|
722
655
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
723
656
|
const bodyChange = JSON.stringify({
|
|
724
657
|
command: 'setBrightness',
|
|
725
658
|
parameter: `${this.LightBulb.Brightness}`,
|
|
726
659
|
commandType: 'command',
|
|
727
660
|
});
|
|
728
|
-
this.debugLog(
|
|
661
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
729
662
|
try {
|
|
730
663
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
731
664
|
const deviceStatus: any = await body.json();
|
|
732
|
-
await this.
|
|
733
|
-
if (
|
|
734
|
-
this.
|
|
735
|
-
|
|
736
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
737
|
-
+ `request to SwitchBot API, body: ${JSON.stringify(JSON.parse(bodyChange))} sent successfully`);
|
|
665
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
666
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
667
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
668
|
+
await this.updateHomeKitCharacteristics();
|
|
738
669
|
} else {
|
|
739
|
-
this.statusCode(statusCode);
|
|
740
|
-
this.statusCode(deviceStatus.statusCode);
|
|
670
|
+
await this.statusCode(statusCode);
|
|
671
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
741
672
|
}
|
|
742
673
|
} catch (e: any) {
|
|
743
|
-
this.apiError(e);
|
|
744
|
-
this.errorLog(
|
|
745
|
-
+ `
|
|
674
|
+
await this.apiError(e);
|
|
675
|
+
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
|
|
676
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
746
677
|
}
|
|
747
678
|
} else {
|
|
748
|
-
this.debugLog(
|
|
749
|
-
+ `
|
|
679
|
+
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
680
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
750
681
|
}
|
|
751
682
|
}
|
|
752
683
|
|
|
@@ -754,10 +685,10 @@ export class ColorBulb extends deviceBase {
|
|
|
754
685
|
* Handle requests to set the value of the "On" characteristic
|
|
755
686
|
*/
|
|
756
687
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
757
|
-
if (this.LightBulb.On
|
|
758
|
-
this.
|
|
688
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
689
|
+
await this.infoLog(`Set On: ${value}`);
|
|
759
690
|
} else {
|
|
760
|
-
this.
|
|
691
|
+
await this.debugLog(`No Changes, On: ${value}`);
|
|
761
692
|
}
|
|
762
693
|
|
|
763
694
|
this.LightBulb.On = value;
|
|
@@ -768,12 +699,14 @@ export class ColorBulb extends deviceBase {
|
|
|
768
699
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
769
700
|
*/
|
|
770
701
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
771
|
-
if (this.LightBulb.Brightness
|
|
772
|
-
this.
|
|
773
|
-
} else if (this.LightBulb.On) {
|
|
774
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
702
|
+
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
703
|
+
await this.infoLog(`Set Brightness: ${value}`);
|
|
775
704
|
} else {
|
|
776
|
-
|
|
705
|
+
if (this.LightBulb.On) {
|
|
706
|
+
this.debugLog(`No Changes, Brightness: ${value}`);
|
|
707
|
+
} else {
|
|
708
|
+
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`);
|
|
709
|
+
}
|
|
777
710
|
}
|
|
778
711
|
|
|
779
712
|
this.LightBulb.Brightness = value;
|
|
@@ -784,12 +717,14 @@ export class ColorBulb extends deviceBase {
|
|
|
784
717
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
785
718
|
*/
|
|
786
719
|
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
787
|
-
if (this.LightBulb.ColorTemperature
|
|
788
|
-
this.
|
|
789
|
-
} else if (this.LightBulb.On) {
|
|
790
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
720
|
+
if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
|
|
721
|
+
this.infoLog(`Set ColorTemperature: ${value}`);
|
|
791
722
|
} else {
|
|
792
|
-
|
|
723
|
+
if (this.LightBulb.On) {
|
|
724
|
+
this.debugLog(`No Changes, ColorTemperature: ${value}`);
|
|
725
|
+
} else {
|
|
726
|
+
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`);
|
|
727
|
+
}
|
|
793
728
|
}
|
|
794
729
|
|
|
795
730
|
const minKelvin = 2000;
|
|
@@ -817,12 +752,14 @@ export class ColorBulb extends deviceBase {
|
|
|
817
752
|
* Handle requests to set the value of the "Hue" characteristic
|
|
818
753
|
*/
|
|
819
754
|
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
820
|
-
if (this.LightBulb.Hue
|
|
821
|
-
this.
|
|
822
|
-
} else if (this.LightBulb.On) {
|
|
823
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
755
|
+
if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
|
|
756
|
+
this.infoLog(`Set Hue: ${value}`);
|
|
824
757
|
} else {
|
|
825
|
-
|
|
758
|
+
if (this.LightBulb.On) {
|
|
759
|
+
this.debugLog(`No Changes, Hue: ${value}`);
|
|
760
|
+
} else {
|
|
761
|
+
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`);
|
|
762
|
+
}
|
|
826
763
|
}
|
|
827
764
|
|
|
828
765
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
@@ -835,12 +772,14 @@ export class ColorBulb extends deviceBase {
|
|
|
835
772
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
836
773
|
*/
|
|
837
774
|
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
838
|
-
if (this.LightBulb.Saturation
|
|
839
|
-
this.
|
|
840
|
-
} else if (this.LightBulb.On) {
|
|
841
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
775
|
+
if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
776
|
+
this.infoLog(`Set Saturation: ${value}`);
|
|
842
777
|
} else {
|
|
843
|
-
|
|
778
|
+
if (this.LightBulb.On) {
|
|
779
|
+
this.debugLog(`No Changes, Saturation: ${value}`);
|
|
780
|
+
} else {
|
|
781
|
+
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`);
|
|
782
|
+
}
|
|
844
783
|
}
|
|
845
784
|
|
|
846
785
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
@@ -870,25 +809,23 @@ export class ColorBulb extends deviceBase {
|
|
|
870
809
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
871
810
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
872
811
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
873
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
874
812
|
} else {
|
|
875
813
|
this.adaptiveLightingShift = 0;
|
|
876
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
877
814
|
}
|
|
815
|
+
await this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
878
816
|
}
|
|
879
817
|
|
|
880
818
|
async BLEPushConnection() {
|
|
881
819
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
882
|
-
this.warnLog(
|
|
820
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
883
821
|
await this.openAPIpushChanges();
|
|
884
822
|
}
|
|
885
823
|
}
|
|
886
824
|
|
|
887
825
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
888
|
-
this.errorLog(
|
|
889
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
826
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
890
827
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
891
|
-
this.warnLog(
|
|
828
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
892
829
|
await this.openAPIRefreshStatus();
|
|
893
830
|
}
|
|
894
831
|
}
|
|
@@ -899,7 +836,7 @@ export class ColorBulb extends deviceBase {
|
|
|
899
836
|
}
|
|
900
837
|
}
|
|
901
838
|
|
|
902
|
-
apiError(e: any): void {
|
|
839
|
+
async apiError(e: any): Promise<void> {
|
|
903
840
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
904
841
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
905
842
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|