@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10
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/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +224 -370
- 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 +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- 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 +335 -421
- 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 +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- 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 +204 -249
- 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 +107 -233
- 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 +193 -235
- 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 +92 -159
- 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 +288 -370
- 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 +172 -219
- 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 +94 -160
- 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 +95 -157
- 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 +85 -144
- 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 +100 -127
- 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 +172 -259
- 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 +106 -131
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- 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 +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -190
- 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 +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- 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,95 +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
|
-
this.apiError(e);
|
|
345
|
-
this.errorLog(
|
|
346
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
339
|
+
await this.apiError(e);
|
|
340
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
347
341
|
}
|
|
348
342
|
}
|
|
349
343
|
|
|
350
|
-
async registerWebhook(
|
|
351
|
-
if (device.webhook) {
|
|
352
|
-
this.debugLog(
|
|
353
|
-
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) => {
|
|
354
348
|
try {
|
|
355
|
-
this.debugLog(
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
|
|
359
|
-
'(powerState, brightness, color, colorTemperature) = ' +
|
|
360
|
-
`Webhook:(${powerState}, ${brightness}, ${color}, ${colorTemperature}), `
|
|
361
|
-
+ `current:(${On}, ${Brightness}, ${Hue}, ${Saturation}, ${ColorTemperature})`);
|
|
362
|
-
|
|
363
|
-
// On
|
|
364
|
-
this.LightBulb.On = powerState === 'ON' ? true : false;
|
|
365
|
-
if (accessory.context.Brightness !== this.LightBulb.On) {
|
|
366
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
367
|
-
} else {
|
|
368
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// Brightness
|
|
372
|
-
this.LightBulb.Brightness = brightness;
|
|
373
|
-
if (accessory.context.Brightness !== this.LightBulb.Brightness) {
|
|
374
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
375
|
-
} else {
|
|
376
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} color: ${JSON.stringify(color)}`);
|
|
380
|
-
const [red, green, blue] = color!.split(':');
|
|
381
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
382
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
383
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
384
|
-
|
|
385
|
-
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
386
|
-
this.debugLog(
|
|
387
|
-
`${device.deviceType}: ${accessory.displayName}`
|
|
388
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
389
|
-
|
|
390
|
-
// Hue
|
|
391
|
-
this.LightBulb.Hue = hue;
|
|
392
|
-
if (accessory.context.Hue !== this.LightBulb.Hue) {
|
|
393
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
394
|
-
} else {
|
|
395
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
// Saturation
|
|
399
|
-
this.LightBulb.Saturation = saturation;
|
|
400
|
-
if (accessory.context.Saturation !== this.LightBulb.Saturation) {
|
|
401
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
402
|
-
} else {
|
|
403
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
this.LightBulb.ColorTemperature = colorTemperature;
|
|
407
|
-
if (accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
|
|
408
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
409
|
-
} else {
|
|
410
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
411
|
-
}
|
|
412
|
-
this.updateHomeKitCharacteristics();
|
|
349
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
350
|
+
await this.parseStatusWebhook(context);
|
|
351
|
+
await this.updateHomeKitCharacteristics();
|
|
413
352
|
} catch (e: any) {
|
|
414
|
-
this.errorLog(
|
|
415
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
353
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
416
354
|
}
|
|
417
355
|
};
|
|
418
356
|
} else {
|
|
419
|
-
this.
|
|
357
|
+
await this.debugLog('is not listening webhook.');
|
|
420
358
|
}
|
|
421
359
|
}
|
|
422
360
|
|
|
@@ -433,15 +371,40 @@ export class ColorBulb extends deviceBase {
|
|
|
433
371
|
*/
|
|
434
372
|
async pushChanges(): Promise<void> {
|
|
435
373
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
436
|
-
this.errorLog(
|
|
374
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
437
375
|
} else if (this.BLE) {
|
|
438
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
|
+
}
|
|
439
390
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
440
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
|
+
}
|
|
441
405
|
} else {
|
|
442
406
|
await this.offlineOff();
|
|
443
|
-
this.debugWarnLog(
|
|
444
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
407
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
445
408
|
}
|
|
446
409
|
// Refresh the status from the API
|
|
447
410
|
interval(15000)
|
|
@@ -453,238 +416,209 @@ export class ColorBulb extends deviceBase {
|
|
|
453
416
|
}
|
|
454
417
|
|
|
455
418
|
async BLEpushChanges(): Promise<void> {
|
|
456
|
-
this.debugLog(
|
|
419
|
+
await this.debugLog('BLEpushChanges');
|
|
457
420
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
458
|
-
this.debugLog(
|
|
459
|
-
|
|
460
|
-
const switchbot = await this.platform.connectBLE();
|
|
461
|
-
// 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);
|
|
462
423
|
await this.convertBLEAddress();
|
|
463
|
-
switchbot
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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();
|
|
476
448
|
});
|
|
477
|
-
|
|
478
|
-
.
|
|
479
|
-
|
|
480
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
481
|
-
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
482
|
-
this.LightBulb.On = false;
|
|
483
|
-
})
|
|
484
|
-
.catch(async (e: any) => {
|
|
485
|
-
this.apiError(e);
|
|
486
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
487
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
488
|
-
await this.BLEPushConnection();
|
|
489
|
-
});
|
|
490
|
-
// Push Brightness Update
|
|
491
|
-
if (this.LightBulb.On) {
|
|
492
|
-
await this.BLEpushBrightnessChanges();
|
|
493
|
-
}
|
|
494
|
-
// Push ColorTemperature Update
|
|
495
|
-
if (this.LightBulb.On) {
|
|
496
|
-
await this.BLEpushColorTemperatureChanges();
|
|
497
|
-
}
|
|
498
|
-
// Push Hue & Saturation Update
|
|
499
|
-
if (this.LightBulb.On) {
|
|
500
|
-
await this.BLEpushRGBChanges();
|
|
449
|
+
} else {
|
|
450
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
451
|
+
await this.BLEPushConnection();
|
|
501
452
|
}
|
|
502
453
|
} else {
|
|
503
|
-
this.debugLog(
|
|
504
|
-
+ ` OnCached: ${this.accessory.context.On}`);
|
|
454
|
+
await this.debugLog(`No changes (BLEpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
505
455
|
}
|
|
506
456
|
}
|
|
507
457
|
|
|
508
458
|
async BLEpushBrightnessChanges(): Promise<void> {
|
|
509
|
-
this.debugLog(
|
|
459
|
+
await this.debugLog('BLEpushBrightnessChanges');
|
|
510
460
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
511
|
-
const switchbot = await this.platform.connectBLE();
|
|
512
|
-
// Convert to BLE Address
|
|
461
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
513
462
|
await this.convertBLEAddress();
|
|
514
|
-
switchbot
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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
|
+
}
|
|
530
483
|
} else {
|
|
531
|
-
this.debugLog(
|
|
532
|
-
+ `
|
|
484
|
+
await this.debugLog(`No changes (BLEpushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
485
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
533
486
|
}
|
|
534
487
|
}
|
|
535
488
|
|
|
536
489
|
async BLEpushColorTemperatureChanges(): Promise<void> {
|
|
537
|
-
this.debugLog(
|
|
490
|
+
await this.debugLog('BLEpushColorTemperatureChanges');
|
|
538
491
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
539
|
-
const switchbot = await this.platform.connectBLE();
|
|
540
|
-
// Convert to BLE Address
|
|
492
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
541
493
|
await this.convertBLEAddress();
|
|
542
|
-
switchbot
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
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
|
+
}
|
|
558
515
|
} else {
|
|
559
|
-
this.debugLog(
|
|
560
|
-
+ `
|
|
516
|
+
await this.debugLog(`No changes (BLEpushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
|
|
517
|
+
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
561
518
|
}
|
|
562
519
|
}
|
|
563
520
|
|
|
564
521
|
async BLEpushRGBChanges(): Promise<void> {
|
|
565
|
-
this.debugLog(
|
|
566
|
-
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
567
|
-
this.debugLog(
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const
|
|
571
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
572
|
-
|
|
573
|
-
const switchbot = await this.platform.connectBLE();
|
|
574
|
-
// 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);
|
|
575
528
|
await this.convertBLEAddress();
|
|
576
|
-
switchbot
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
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
|
+
}
|
|
592
550
|
} else {
|
|
593
|
-
this.debugLog(
|
|
594
|
-
+
|
|
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}`);
|
|
595
553
|
}
|
|
596
554
|
}
|
|
597
555
|
|
|
598
556
|
async openAPIpushChanges(): Promise<void> {
|
|
599
|
-
this.debugLog(
|
|
557
|
+
await this.debugLog('openAPIpushChanges');
|
|
600
558
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
601
|
-
|
|
602
|
-
if (this.LightBulb.On) {
|
|
603
|
-
command = 'turnOn';
|
|
604
|
-
} else {
|
|
605
|
-
command = 'turnOff';
|
|
606
|
-
}
|
|
559
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
607
560
|
const bodyChange = JSON.stringify({
|
|
608
561
|
command: `${command}`,
|
|
609
562
|
parameter: 'default',
|
|
610
563
|
commandType: 'command',
|
|
611
564
|
});
|
|
612
|
-
this.debugLog(
|
|
565
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
613
566
|
try {
|
|
614
567
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
615
568
|
const deviceStatus: any = await body.json();
|
|
616
|
-
await this.
|
|
617
|
-
if (
|
|
618
|
-
this.
|
|
619
|
-
|
|
620
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
621
|
-
+ `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();
|
|
622
573
|
} else {
|
|
623
|
-
this.statusCode(statusCode);
|
|
624
|
-
this.statusCode(deviceStatus.statusCode);
|
|
574
|
+
await this.statusCode(statusCode);
|
|
575
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
625
576
|
}
|
|
626
577
|
} catch (e: any) {
|
|
627
|
-
this.apiError(e);
|
|
628
|
-
this.errorLog(
|
|
629
|
-
+ ` 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)}`);
|
|
630
580
|
}
|
|
631
581
|
} else {
|
|
632
|
-
this.debugLog(
|
|
633
|
-
+ `On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
634
|
-
}
|
|
635
|
-
// Push Hue & Saturation Update
|
|
636
|
-
if (this.LightBulb.On) {
|
|
637
|
-
await this.pushHueSaturationChanges();
|
|
638
|
-
}
|
|
639
|
-
// Push ColorTemperature Update
|
|
640
|
-
if (this.LightBulb.On) {
|
|
641
|
-
await this.pushColorTemperatureChanges();
|
|
642
|
-
}
|
|
643
|
-
// Push Brightness Update
|
|
644
|
-
if (this.LightBulb.On) {
|
|
645
|
-
await this.pushBrightnessChanges();
|
|
582
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
646
583
|
}
|
|
647
584
|
}
|
|
648
585
|
|
|
649
586
|
async pushHueSaturationChanges(): Promise<void> {
|
|
650
|
-
this.debugLog(
|
|
651
|
-
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
652
|
-
this.debugLog(
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
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])}`);
|
|
656
592
|
const bodyChange = JSON.stringify({
|
|
657
593
|
command: 'setColor',
|
|
658
594
|
parameter: `${red}:${green}:${blue}`,
|
|
659
595
|
commandType: 'command',
|
|
660
596
|
});
|
|
661
|
-
this.debugLog(
|
|
597
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
662
598
|
try {
|
|
663
599
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
664
600
|
const deviceStatus: any = await body.json();
|
|
665
|
-
await this.
|
|
666
|
-
if (
|
|
667
|
-
this.
|
|
668
|
-
|
|
669
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
670
|
-
+ `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();
|
|
671
605
|
} else {
|
|
672
|
-
this.statusCode(statusCode);
|
|
673
|
-
this.statusCode(deviceStatus.statusCode);
|
|
606
|
+
await this.statusCode(statusCode);
|
|
607
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
674
608
|
}
|
|
675
609
|
} catch (e: any) {
|
|
676
|
-
this.apiError(e);
|
|
677
|
-
this.errorLog(
|
|
678
|
-
+ `
|
|
610
|
+
await this.apiError(e);
|
|
611
|
+
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
|
|
612
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
679
613
|
}
|
|
680
614
|
} else {
|
|
681
|
-
this.debugLog(
|
|
682
|
-
+
|
|
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}`);
|
|
683
617
|
}
|
|
684
618
|
}
|
|
685
619
|
|
|
686
620
|
async pushColorTemperatureChanges(): Promise<void> {
|
|
687
|
-
this.debugLog(
|
|
621
|
+
await this.debugLog('pushColorTemperatureChanges');
|
|
688
622
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
689
623
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
690
624
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -693,61 +627,57 @@ export class ColorBulb extends deviceBase {
|
|
|
693
627
|
parameter: `${kelvin}`,
|
|
694
628
|
commandType: 'command',
|
|
695
629
|
});
|
|
696
|
-
this.debugLog(
|
|
630
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
697
631
|
try {
|
|
698
632
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
699
633
|
const deviceStatus: any = await body.json();
|
|
700
|
-
await this.
|
|
701
|
-
if (
|
|
702
|
-
this.
|
|
703
|
-
|
|
704
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
705
|
-
+ `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();
|
|
706
638
|
} else {
|
|
707
|
-
this.statusCode(statusCode);
|
|
708
|
-
this.statusCode(deviceStatus.statusCode);
|
|
639
|
+
await this.statusCode(statusCode);
|
|
640
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
709
641
|
}
|
|
710
642
|
} catch (e: any) {
|
|
711
|
-
this.apiError(e);
|
|
712
|
-
this.errorLog(
|
|
713
|
-
+ `
|
|
643
|
+
await this.apiError(e);
|
|
644
|
+
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection,`
|
|
645
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
714
646
|
}
|
|
715
647
|
} else {
|
|
716
|
-
this.debugLog(
|
|
717
|
-
+ `
|
|
648
|
+
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
|
|
649
|
+
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
718
650
|
}
|
|
719
651
|
}
|
|
720
652
|
|
|
721
653
|
async pushBrightnessChanges(): Promise<void> {
|
|
722
|
-
this.debugLog(
|
|
654
|
+
await this.debugLog('pushBrightnessChanges');
|
|
723
655
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
724
656
|
const bodyChange = JSON.stringify({
|
|
725
657
|
command: 'setBrightness',
|
|
726
658
|
parameter: `${this.LightBulb.Brightness}`,
|
|
727
659
|
commandType: 'command',
|
|
728
660
|
});
|
|
729
|
-
this.debugLog(
|
|
661
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
730
662
|
try {
|
|
731
663
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
732
664
|
const deviceStatus: any = await body.json();
|
|
733
|
-
await this.
|
|
734
|
-
if (
|
|
735
|
-
this.
|
|
736
|
-
|
|
737
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
738
|
-
+ `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();
|
|
739
669
|
} else {
|
|
740
|
-
this.statusCode(statusCode);
|
|
741
|
-
this.statusCode(deviceStatus.statusCode);
|
|
670
|
+
await this.statusCode(statusCode);
|
|
671
|
+
await this.statusCode(deviceStatus.statusCode);
|
|
742
672
|
}
|
|
743
673
|
} catch (e: any) {
|
|
744
|
-
this.apiError(e);
|
|
745
|
-
this.errorLog(
|
|
746
|
-
+ `
|
|
674
|
+
await this.apiError(e);
|
|
675
|
+
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
|
|
676
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
747
677
|
}
|
|
748
678
|
} else {
|
|
749
|
-
this.debugLog(
|
|
750
|
-
+ `
|
|
679
|
+
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
680
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
751
681
|
}
|
|
752
682
|
}
|
|
753
683
|
|
|
@@ -755,10 +685,10 @@ export class ColorBulb extends deviceBase {
|
|
|
755
685
|
* Handle requests to set the value of the "On" characteristic
|
|
756
686
|
*/
|
|
757
687
|
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
758
|
-
if (this.LightBulb.On
|
|
759
|
-
this.
|
|
688
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
689
|
+
await this.infoLog(`Set On: ${value}`);
|
|
760
690
|
} else {
|
|
761
|
-
this.
|
|
691
|
+
await this.debugLog(`No Changes, On: ${value}`);
|
|
762
692
|
}
|
|
763
693
|
|
|
764
694
|
this.LightBulb.On = value;
|
|
@@ -769,12 +699,14 @@ export class ColorBulb extends deviceBase {
|
|
|
769
699
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
770
700
|
*/
|
|
771
701
|
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
772
|
-
if (this.LightBulb.Brightness
|
|
773
|
-
this.
|
|
774
|
-
} else if (this.LightBulb.On) {
|
|
775
|
-
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}`);
|
|
776
704
|
} else {
|
|
777
|
-
|
|
705
|
+
if (this.LightBulb.On) {
|
|
706
|
+
this.debugLog(`No Changes, Brightness: ${value}`);
|
|
707
|
+
} else {
|
|
708
|
+
this.debugLog(`Brightness: ${value}, On: ${this.LightBulb.On}`);
|
|
709
|
+
}
|
|
778
710
|
}
|
|
779
711
|
|
|
780
712
|
this.LightBulb.Brightness = value;
|
|
@@ -785,12 +717,14 @@ export class ColorBulb extends deviceBase {
|
|
|
785
717
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
786
718
|
*/
|
|
787
719
|
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
788
|
-
if (this.LightBulb.ColorTemperature
|
|
789
|
-
this.
|
|
790
|
-
} else if (this.LightBulb.On) {
|
|
791
|
-
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}`);
|
|
792
722
|
} else {
|
|
793
|
-
|
|
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
|
+
}
|
|
794
728
|
}
|
|
795
729
|
|
|
796
730
|
const minKelvin = 2000;
|
|
@@ -818,12 +752,14 @@ export class ColorBulb extends deviceBase {
|
|
|
818
752
|
* Handle requests to set the value of the "Hue" characteristic
|
|
819
753
|
*/
|
|
820
754
|
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
821
|
-
if (this.LightBulb.Hue
|
|
822
|
-
this.
|
|
823
|
-
} else if (this.LightBulb.On) {
|
|
824
|
-
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}`);
|
|
825
757
|
} else {
|
|
826
|
-
|
|
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
|
+
}
|
|
827
763
|
}
|
|
828
764
|
|
|
829
765
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
@@ -836,12 +772,14 @@ export class ColorBulb extends deviceBase {
|
|
|
836
772
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
837
773
|
*/
|
|
838
774
|
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
839
|
-
if (this.LightBulb.Saturation
|
|
840
|
-
this.
|
|
841
|
-
} else if (this.LightBulb.On) {
|
|
842
|
-
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}`);
|
|
843
777
|
} else {
|
|
844
|
-
|
|
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
|
+
}
|
|
845
783
|
}
|
|
846
784
|
|
|
847
785
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
@@ -852,70 +790,42 @@ export class ColorBulb extends deviceBase {
|
|
|
852
790
|
|
|
853
791
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
854
792
|
// On
|
|
855
|
-
|
|
856
|
-
this.
|
|
857
|
-
} else {
|
|
858
|
-
this.accessory.context.On = this.LightBulb.On;
|
|
859
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
860
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
861
|
-
}
|
|
793
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On,
|
|
794
|
+
this.LightBulb.On, 'On');
|
|
862
795
|
// Brightness
|
|
863
|
-
|
|
864
|
-
this.
|
|
865
|
-
} else {
|
|
866
|
-
this.accessory.context.Brightness = this.LightBulb.Brightness;
|
|
867
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
|
|
868
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
|
|
869
|
-
}
|
|
796
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness,
|
|
797
|
+
this.LightBulb.Brightness, 'Brightness');
|
|
870
798
|
// ColorTemperature
|
|
871
|
-
|
|
872
|
-
this.
|
|
873
|
-
} else {
|
|
874
|
-
this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
|
|
875
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
|
|
876
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
877
|
-
+ ` ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
878
|
-
}
|
|
799
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature,
|
|
800
|
+
this.LightBulb.ColorTemperature, 'ColorTemperature');
|
|
879
801
|
// Hue
|
|
880
|
-
|
|
881
|
-
this.
|
|
882
|
-
} else {
|
|
883
|
-
this.accessory.context.Hue = this.LightBulb.Hue;
|
|
884
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
|
|
885
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
|
|
886
|
-
}
|
|
802
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue,
|
|
803
|
+
this.LightBulb.Hue, 'Hue');
|
|
887
804
|
// Saturation
|
|
888
|
-
|
|
889
|
-
this.
|
|
890
|
-
} else {
|
|
891
|
-
this.accessory.context.Saturation = this.LightBulb.Saturation;
|
|
892
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
|
|
893
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
|
|
894
|
-
}
|
|
805
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation,
|
|
806
|
+
this.LightBulb.Saturation, 'Saturation');
|
|
895
807
|
}
|
|
896
808
|
|
|
897
809
|
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
898
810
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
899
811
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
900
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
901
812
|
} else {
|
|
902
813
|
this.adaptiveLightingShift = 0;
|
|
903
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
904
814
|
}
|
|
815
|
+
await this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
905
816
|
}
|
|
906
817
|
|
|
907
818
|
async BLEPushConnection() {
|
|
908
819
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
909
|
-
this.warnLog(
|
|
820
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
910
821
|
await this.openAPIpushChanges();
|
|
911
822
|
}
|
|
912
823
|
}
|
|
913
824
|
|
|
914
825
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
915
|
-
this.errorLog(
|
|
916
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
826
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
917
827
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
918
|
-
this.warnLog(
|
|
828
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
919
829
|
await this.openAPIRefreshStatus();
|
|
920
830
|
}
|
|
921
831
|
}
|
|
@@ -926,7 +836,7 @@ export class ColorBulb extends deviceBase {
|
|
|
926
836
|
}
|
|
927
837
|
}
|
|
928
838
|
|
|
929
|
-
apiError(e: any): void {
|
|
839
|
+
async apiError(e: any): Promise<void> {
|
|
930
840
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
931
841
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
932
842
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|