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