@switchbot/homebridge-switchbot 3.5.1-beta.1 → 3.5.1-beta.11
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 +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 +203 -249
- 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 +105 -129
- 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 +45 -51
- 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 +17 -17
- 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 +9 -9
- 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 +19 -19
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +24 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +90 -68
- 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 +15 -17
- 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 +76 -76
- 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 +35 -35
- 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 +9 -9
- 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 +9 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +15 -15
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +288 -271
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +211 -261
- 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 +123 -139
- package/src/irdevice/airconditioner.ts +47 -52
- package/src/irdevice/airpurifier.ts +19 -18
- package/src/irdevice/camera.ts +11 -10
- package/src/irdevice/fan.ts +21 -20
- package/src/irdevice/irdevice.ts +95 -70
- package/src/irdevice/light.ts +17 -18
- package/src/irdevice/other.ts +78 -77
- package/src/irdevice/tv.ts +37 -36
- package/src/irdevice/vacuumcleaner.ts +11 -10
- package/src/irdevice/waterheater.ts +11 -10
- package/src/platform.ts +290 -272
- 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
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
* ceilinglight.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { debounceTime, skipWhile, take, tap } from 'rxjs
|
|
6
|
+
import { hs2rgb, m2hs } from '../utils.js';
|
|
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
|
|
@@ -32,7 +32,7 @@ export class CeilingLight extends deviceBase {
|
|
|
32
32
|
// Initialize LightBulb Service
|
|
33
33
|
accessory.context.LightBulb = accessory.context.LightBulb ?? {};
|
|
34
34
|
this.LightBulb = {
|
|
35
|
-
Name: accessory.context.
|
|
35
|
+
Name: accessory.context.LightBulb.Name ?? accessory.displayName,
|
|
36
36
|
Service: accessory.getService(this.hap.Service.Lightbulb) ?? accessory.addService(this.hap.Service.Lightbulb),
|
|
37
37
|
On: accessory.context.On ?? false,
|
|
38
38
|
Hue: accessory.context.Hue ?? 0,
|
|
@@ -46,7 +46,7 @@ export class CeilingLight 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, {
|
|
@@ -54,10 +54,10 @@ export class CeilingLight extends deviceBase {
|
|
|
54
54
|
});
|
|
55
55
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
56
56
|
this.accessory.context.adaptiveLighting = true;
|
|
57
|
-
this.debugLog(
|
|
57
|
+
this.debugLog(`adaptiveLighting: ${this.accessory.context.adaptiveLighting},`
|
|
58
58
|
+ ` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
59
59
|
}
|
|
60
|
-
this.debugLog(
|
|
60
|
+
this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
61
61
|
// Initialize LightBulb Characteristics
|
|
62
62
|
this.LightBulb.Service
|
|
63
63
|
.setCharacteristic(this.hap.Characteristic.Name, this.LightBulb.Name)
|
|
@@ -119,14 +119,14 @@ export class CeilingLight extends deviceBase {
|
|
|
119
119
|
this.refreshStatus();
|
|
120
120
|
// Update Homekit
|
|
121
121
|
this.updateHomeKitCharacteristics();
|
|
122
|
+
//regisiter webhook event handler
|
|
123
|
+
this.registerWebhook();
|
|
122
124
|
// Start an update interval
|
|
123
125
|
interval(this.deviceRefreshRate * 1000)
|
|
124
126
|
.pipe(skipWhile(() => this.ceilingLightUpdateInProgress))
|
|
125
127
|
.subscribe(async () => {
|
|
126
128
|
await this.refreshStatus();
|
|
127
129
|
});
|
|
128
|
-
//regisiter webhook event handler
|
|
129
|
-
this.registerWebhook(accessory, device);
|
|
130
130
|
// Watch for Bulb change events
|
|
131
131
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
132
132
|
this.doCeilingLightUpdate
|
|
@@ -138,9 +138,8 @@ export class CeilingLight extends deviceBase {
|
|
|
138
138
|
await this.pushChanges();
|
|
139
139
|
}
|
|
140
140
|
catch (e) {
|
|
141
|
-
this.apiError(e);
|
|
142
|
-
this.errorLog(
|
|
143
|
-
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
141
|
+
await this.apiError(e);
|
|
142
|
+
await this.errorLog(`failed pushChanges with ${device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
144
143
|
}
|
|
145
144
|
this.ceilingLightUpdateInProgress = false;
|
|
146
145
|
});
|
|
@@ -149,63 +148,34 @@ export class CeilingLight extends deviceBase {
|
|
|
149
148
|
* Parse the device status from the SwitchBotBLE API
|
|
150
149
|
*/
|
|
151
150
|
async BLEparseStatus(serviceData) {
|
|
152
|
-
this.debugLog(
|
|
153
|
-
//
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.LightBulb.On = true;
|
|
157
|
-
break;
|
|
158
|
-
default:
|
|
159
|
-
this.LightBulb.On = false;
|
|
160
|
-
}
|
|
161
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
151
|
+
await this.debugLog('BLEparseStatus');
|
|
152
|
+
// On
|
|
153
|
+
this.LightBulb.On = serviceData.state;
|
|
154
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
162
155
|
}
|
|
163
156
|
/**
|
|
164
157
|
* Parse the device status from the SwitchBot OpenAPI
|
|
165
158
|
*/
|
|
166
159
|
async openAPIparseStatus(deviceStatus) {
|
|
167
|
-
this.debugLog(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
break;
|
|
172
|
-
default:
|
|
173
|
-
this.LightBulb.On = false;
|
|
174
|
-
}
|
|
175
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
160
|
+
await this.debugLog('openAPIparseStatus');
|
|
161
|
+
// On
|
|
162
|
+
this.LightBulb.On = deviceStatus.power;
|
|
163
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
176
164
|
// Brightness
|
|
177
|
-
this.LightBulb.Brightness =
|
|
178
|
-
this.debugLog(
|
|
179
|
-
// Color, Hue & Brightness
|
|
180
|
-
if (deviceStatus.body.color) {
|
|
181
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(deviceStatus.body.color)}`);
|
|
182
|
-
const [red, green, blue] = deviceStatus.body.color.split(':');
|
|
183
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
184
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
185
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
186
|
-
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
187
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
188
|
-
+ ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
189
|
-
// Hue
|
|
190
|
-
this.LightBulb.Hue = hue;
|
|
191
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
192
|
-
// Saturation
|
|
193
|
-
this.LightBulb.Saturation = saturation;
|
|
194
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
195
|
-
}
|
|
165
|
+
this.LightBulb.Brightness = deviceStatus.brightness;
|
|
166
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
196
167
|
// ColorTemperature
|
|
197
|
-
if (!Number.isNaN(deviceStatus.
|
|
198
|
-
this.debugLog(
|
|
199
|
-
const
|
|
200
|
-
this.LightBulb.ColorTemperature =
|
|
201
|
-
this.
|
|
202
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
168
|
+
if (!Number.isNaN(deviceStatus.colorTemperature)) {
|
|
169
|
+
await this.debugLog(`OpenAPI ColorTemperature: ${deviceStatus.colorTemperature}`);
|
|
170
|
+
const miredColorTemperature = Math.round(1000000 / deviceStatus.colorTemperature);
|
|
171
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(miredColorTemperature, 500), 140);
|
|
172
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
203
173
|
}
|
|
204
174
|
// Firmware Version
|
|
205
|
-
const version = deviceStatus.
|
|
206
|
-
this.debugLog(
|
|
207
|
-
if (deviceStatus.
|
|
208
|
-
const deviceVersion = version
|
|
175
|
+
const version = deviceStatus.version.toString();
|
|
176
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
177
|
+
if (deviceStatus.version) {
|
|
178
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
209
179
|
this.accessory
|
|
210
180
|
.getService(this.hap.Service.AccessoryInformation)
|
|
211
181
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -213,29 +183,43 @@ export class CeilingLight extends deviceBase {
|
|
|
213
183
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
214
184
|
.updateValue(deviceVersion);
|
|
215
185
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
216
|
-
this.debugSuccessLog(
|
|
186
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
217
187
|
}
|
|
218
188
|
}
|
|
189
|
+
async parseStatusWebhook(context) {
|
|
190
|
+
await this.debugLog('parseStatusWebhook');
|
|
191
|
+
await this.debugLog(`(powerState, brightness, colorTemperature) = Webhook:(${context.powerState}, ${context.brightness},`
|
|
192
|
+
+ ` ${context.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
193
|
+
// On
|
|
194
|
+
this.LightBulb.On = context.powerState === 'ON' ? true : false;
|
|
195
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
196
|
+
// Brightness
|
|
197
|
+
this.LightBulb.Brightness = context.brightness;
|
|
198
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
199
|
+
// ColorTemperature
|
|
200
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(context.colorTemperature, 500), 140);
|
|
201
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
202
|
+
}
|
|
219
203
|
/**
|
|
220
204
|
* Asks the SwitchBot API for the latest device information
|
|
221
205
|
*/
|
|
222
206
|
async refreshStatus() {
|
|
223
207
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
224
|
-
this.errorLog(
|
|
225
|
-
|
|
226
|
-
|
|
208
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
209
|
+
}
|
|
210
|
+
else if (this.BLE) {
|
|
211
|
+
await this.BLERefreshStatus();
|
|
227
212
|
}
|
|
228
213
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
229
214
|
await this.openAPIRefreshStatus();
|
|
230
215
|
}
|
|
231
216
|
else {
|
|
232
217
|
await this.offlineOff();
|
|
233
|
-
this.debugWarnLog(
|
|
234
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
218
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
235
219
|
}
|
|
236
220
|
}
|
|
237
221
|
async BLERefreshStatus() {
|
|
238
|
-
this.debugLog(
|
|
222
|
+
await this.debugLog('BLERefreshStatus');
|
|
239
223
|
const switchbot = await this.switchbotBLE();
|
|
240
224
|
if (switchbot === undefined) {
|
|
241
225
|
await this.BLERefreshConnection(switchbot);
|
|
@@ -245,84 +229,56 @@ export class CeilingLight extends deviceBase {
|
|
|
245
229
|
// Start to monitor advertisement packets
|
|
246
230
|
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
247
231
|
// Update HomeKit
|
|
248
|
-
if (serviceData.model
|
|
232
|
+
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
|
|
233
|
+
&& serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
|
|
249
234
|
await this.BLEparseStatus(serviceData);
|
|
250
235
|
await this.updateHomeKitCharacteristics();
|
|
251
236
|
}
|
|
252
237
|
else {
|
|
253
|
-
this.errorLog(
|
|
238
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
254
239
|
await this.BLERefreshConnection(switchbot);
|
|
255
240
|
}
|
|
256
241
|
})();
|
|
257
242
|
}
|
|
258
243
|
}
|
|
259
244
|
async openAPIRefreshStatus() {
|
|
260
|
-
this.debugLog(
|
|
245
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
261
246
|
try {
|
|
262
247
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
263
248
|
const deviceStatus = await body.json();
|
|
264
|
-
await this.
|
|
249
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
265
250
|
;
|
|
266
|
-
if (
|
|
267
|
-
await this.
|
|
268
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
251
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
252
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
253
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
269
254
|
await this.updateHomeKitCharacteristics();
|
|
270
255
|
}
|
|
271
256
|
else {
|
|
272
|
-
await this.
|
|
257
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
258
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
273
259
|
}
|
|
274
260
|
}
|
|
275
261
|
catch (e) {
|
|
276
262
|
await this.apiError(e);
|
|
277
|
-
await this.
|
|
263
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
278
264
|
}
|
|
279
265
|
}
|
|
280
|
-
async registerWebhook(
|
|
281
|
-
if (device.webhook) {
|
|
282
|
-
this.debugLog(
|
|
283
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
266
|
+
async registerWebhook() {
|
|
267
|
+
if (this.device.webhook) {
|
|
268
|
+
await this.debugLog('is listening webhook.');
|
|
269
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
284
270
|
try {
|
|
285
|
-
this.debugLog(
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
|
|
289
|
-
'(powerState, brightness, colorTemperature) = ' +
|
|
290
|
-
`Webhook:(${powerState}, ${brightness}, ${colorTemperature}), `
|
|
291
|
-
+ `current:(${On}, ${Brightness}, ${ColorTemperature})`);
|
|
292
|
-
// On
|
|
293
|
-
this.LightBulb.On = powerState === 'ON' ? true : false;
|
|
294
|
-
if (accessory.context.Brightness !== this.LightBulb.On) {
|
|
295
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
296
|
-
}
|
|
297
|
-
else {
|
|
298
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
299
|
-
}
|
|
300
|
-
// Brightness
|
|
301
|
-
this.LightBulb.Brightness = brightness;
|
|
302
|
-
if (accessory.context.Brightness !== this.LightBulb.Brightness) {
|
|
303
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
304
|
-
}
|
|
305
|
-
else {
|
|
306
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
307
|
-
}
|
|
308
|
-
// ColorTemperature
|
|
309
|
-
this.LightBulb.ColorTemperature = colorTemperature;
|
|
310
|
-
if (accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
|
|
311
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
312
|
-
}
|
|
313
|
-
else {
|
|
314
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
315
|
-
}
|
|
316
|
-
this.updateHomeKitCharacteristics();
|
|
271
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
272
|
+
await this.parseStatusWebhook(context);
|
|
273
|
+
await this.updateHomeKitCharacteristics();
|
|
317
274
|
}
|
|
318
275
|
catch (e) {
|
|
319
|
-
this.errorLog(
|
|
320
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
276
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
321
277
|
}
|
|
322
278
|
};
|
|
323
279
|
}
|
|
324
280
|
else {
|
|
325
|
-
this.debugLog(
|
|
281
|
+
await this.debugLog('is not listening webhook.');
|
|
326
282
|
}
|
|
327
283
|
}
|
|
328
284
|
/**
|
|
@@ -338,17 +294,32 @@ export class CeilingLight extends deviceBase {
|
|
|
338
294
|
*/
|
|
339
295
|
async pushChanges() {
|
|
340
296
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
341
|
-
this.errorLog(
|
|
297
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
342
298
|
}
|
|
343
299
|
else if (this.BLE) {
|
|
344
300
|
await this.BLEpushChanges();
|
|
345
301
|
}
|
|
346
302
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
347
303
|
await this.openAPIpushChanges();
|
|
304
|
+
if (this.LightBulb.On) {
|
|
305
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
306
|
+
// Push Brightness Update
|
|
307
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
308
|
+
await this.pushBrightnessChanges();
|
|
309
|
+
// Push ColorTemperature Update
|
|
310
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
311
|
+
await this.pushColorTemperatureChanges();
|
|
312
|
+
// Push Hue & Saturation Update
|
|
313
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
314
|
+
await this.pushHueSaturationChanges();
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
318
|
+
}
|
|
348
319
|
}
|
|
349
320
|
else {
|
|
350
321
|
await this.offlineOff();
|
|
351
|
-
await this.
|
|
322
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
352
323
|
}
|
|
353
324
|
// Refresh the status from the API
|
|
354
325
|
interval(15000)
|
|
@@ -359,70 +330,63 @@ export class CeilingLight extends deviceBase {
|
|
|
359
330
|
});
|
|
360
331
|
}
|
|
361
332
|
async BLEpushChanges() {
|
|
362
|
-
this.debugLog(
|
|
333
|
+
await this.debugLog('BLEpushChanges');
|
|
363
334
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
364
|
-
this.debugLog(
|
|
365
|
-
|
|
366
|
-
const switchbot = await this.platform.connectBLE();
|
|
367
|
-
// Convert to BLE Address
|
|
335
|
+
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
336
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
368
337
|
await this.convertBLEAddress();
|
|
369
|
-
switchbot
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
338
|
+
if (switchbot !== false) {
|
|
339
|
+
switchbot
|
|
340
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
341
|
+
.then(async (device_list) => {
|
|
342
|
+
this.infoLog(`On: ${this.LightBulb.On}`);
|
|
343
|
+
return await this.retryBLE({
|
|
344
|
+
max: await this.maxRetryBLE(),
|
|
345
|
+
fn: async () => {
|
|
346
|
+
if (this.LightBulb.On) {
|
|
347
|
+
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
return await device_list[0].turnOff({ id: this.device.bleMac });
|
|
351
|
+
}
|
|
352
|
+
},
|
|
353
|
+
});
|
|
354
|
+
})
|
|
355
|
+
.then(async () => {
|
|
356
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
357
|
+
this.LightBulb.On = false;
|
|
358
|
+
})
|
|
359
|
+
.catch(async (e) => {
|
|
360
|
+
await this.apiError(e);
|
|
361
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
362
|
+
await this.BLEPushConnection();
|
|
383
363
|
});
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
this.
|
|
387
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
388
|
-
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
389
|
-
this.LightBulb.On = false;
|
|
390
|
-
})
|
|
391
|
-
.catch(async (e) => {
|
|
392
|
-
this.apiError(e);
|
|
393
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
394
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
395
367
|
await this.BLEPushConnection();
|
|
396
|
-
}
|
|
368
|
+
}
|
|
397
369
|
}
|
|
398
370
|
else {
|
|
399
|
-
this.debugLog(
|
|
400
|
-
+ ` No BLEpushChanges: On: ${this.LightBulb.On}, `
|
|
401
|
-
+ `OnCached: ${this.accessory.context.On}`);
|
|
371
|
+
await this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
402
372
|
}
|
|
403
373
|
}
|
|
404
374
|
async openAPIpushChanges() {
|
|
405
|
-
this.debugLog(
|
|
375
|
+
await this.debugLog('openAPIpushChanges');
|
|
406
376
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
407
|
-
|
|
408
|
-
if (this.LightBulb.On) {
|
|
409
|
-
command = 'turnOn';
|
|
410
|
-
}
|
|
411
|
-
else {
|
|
412
|
-
command = 'turnOff';
|
|
413
|
-
}
|
|
377
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
414
378
|
const bodyChange = JSON.stringify({
|
|
415
379
|
command: `${command}`,
|
|
416
380
|
parameter: 'default',
|
|
417
381
|
commandType: 'command',
|
|
418
382
|
});
|
|
419
|
-
this.debugLog(
|
|
383
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
420
384
|
try {
|
|
421
385
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
422
386
|
const deviceStatus = await body.json();
|
|
423
|
-
await this.
|
|
424
|
-
if (
|
|
425
|
-
await this.
|
|
387
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
388
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
389
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
426
390
|
await this.updateHomeKitCharacteristics();
|
|
427
391
|
}
|
|
428
392
|
else {
|
|
@@ -431,48 +395,33 @@ export class CeilingLight extends deviceBase {
|
|
|
431
395
|
}
|
|
432
396
|
}
|
|
433
397
|
catch (e) {
|
|
434
|
-
this.apiError(e);
|
|
435
|
-
this.errorLog(
|
|
436
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
398
|
+
await this.apiError(e);
|
|
399
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
437
400
|
}
|
|
438
401
|
}
|
|
439
402
|
else {
|
|
440
|
-
this.debugLog(
|
|
441
|
-
+ `On: ${this.LightBulb.On}, `
|
|
442
|
-
+ `OnCached: ${this.accessory.context.On}`);
|
|
443
|
-
}
|
|
444
|
-
// Push Hue & Saturation Update
|
|
445
|
-
if (this.LightBulb.On) {
|
|
446
|
-
await this.pushHueSaturationChanges();
|
|
447
|
-
}
|
|
448
|
-
// Push ColorTemperature Update
|
|
449
|
-
if (this.LightBulb.On) {
|
|
450
|
-
await this.pushColorTemperatureChanges();
|
|
451
|
-
}
|
|
452
|
-
// Push Brightness Update
|
|
453
|
-
if (this.LightBulb.On) {
|
|
454
|
-
await this.pushBrightnessChanges();
|
|
403
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
455
404
|
}
|
|
456
405
|
}
|
|
457
406
|
async pushHueSaturationChanges() {
|
|
458
|
-
this.debugLog(
|
|
459
|
-
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
460
|
-
this.debugLog(
|
|
461
|
-
this.debugLog(
|
|
407
|
+
await this.debugLog('pushHueSaturationChanges');
|
|
408
|
+
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
409
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
|
|
410
|
+
await this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
462
411
|
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
|
|
463
|
-
this.debugLog(
|
|
412
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
464
413
|
const bodyChange = JSON.stringify({
|
|
465
414
|
command: 'setColor',
|
|
466
415
|
parameter: `${red}:${green}:${blue}`,
|
|
467
416
|
commandType: 'command',
|
|
468
417
|
});
|
|
469
|
-
this.debugLog(
|
|
418
|
+
await this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
470
419
|
try {
|
|
471
420
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
472
421
|
const deviceStatus = await body.json();
|
|
473
|
-
await this.
|
|
474
|
-
if (
|
|
475
|
-
await this.
|
|
422
|
+
await this.debugLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
423
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
424
|
+
await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
476
425
|
await this.updateHomeKitCharacteristics();
|
|
477
426
|
}
|
|
478
427
|
else {
|
|
@@ -481,18 +430,18 @@ export class CeilingLight extends deviceBase {
|
|
|
481
430
|
}
|
|
482
431
|
}
|
|
483
432
|
catch (e) {
|
|
484
|
-
this.apiError(e);
|
|
485
|
-
this.errorLog(
|
|
486
|
-
+ `
|
|
433
|
+
await this.apiError(e);
|
|
434
|
+
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
|
|
435
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
487
436
|
}
|
|
488
437
|
}
|
|
489
438
|
else {
|
|
490
|
-
this.debugLog(
|
|
491
|
-
+
|
|
439
|
+
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
|
|
440
|
+
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
492
441
|
}
|
|
493
442
|
}
|
|
494
443
|
async pushColorTemperatureChanges() {
|
|
495
|
-
this.debugLog(
|
|
444
|
+
await this.debugLog('pushColorTemperatureChanges');
|
|
496
445
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
497
446
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
498
447
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -501,13 +450,13 @@ export class CeilingLight extends deviceBase {
|
|
|
501
450
|
parameter: `${kelvin}`,
|
|
502
451
|
commandType: 'command',
|
|
503
452
|
});
|
|
504
|
-
this.debugLog(
|
|
453
|
+
await this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
505
454
|
try {
|
|
506
455
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
507
456
|
const deviceStatus = await body.json();
|
|
508
|
-
await this.
|
|
509
|
-
if (
|
|
510
|
-
await this.
|
|
457
|
+
await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
458
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
459
|
+
await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
511
460
|
await this.updateHomeKitCharacteristics();
|
|
512
461
|
}
|
|
513
462
|
else {
|
|
@@ -516,31 +465,31 @@ export class CeilingLight extends deviceBase {
|
|
|
516
465
|
}
|
|
517
466
|
}
|
|
518
467
|
catch (e) {
|
|
519
|
-
this.apiError(e);
|
|
520
|
-
this.errorLog(
|
|
521
|
-
+ `
|
|
468
|
+
await this.apiError(e);
|
|
469
|
+
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection,`
|
|
470
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
522
471
|
}
|
|
523
472
|
}
|
|
524
473
|
else {
|
|
525
|
-
this.debugLog(
|
|
526
|
-
+ `
|
|
474
|
+
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
|
|
475
|
+
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
527
476
|
}
|
|
528
477
|
}
|
|
529
478
|
async pushBrightnessChanges() {
|
|
530
|
-
this.debugLog(
|
|
479
|
+
await this.debugLog('pushBrightnessChanges');
|
|
531
480
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
532
481
|
const bodyChange = JSON.stringify({
|
|
533
482
|
command: 'setBrightness',
|
|
534
483
|
parameter: `${this.LightBulb.Brightness}`,
|
|
535
484
|
commandType: 'command',
|
|
536
485
|
});
|
|
537
|
-
this.debugLog(
|
|
486
|
+
await this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
538
487
|
try {
|
|
539
488
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
540
489
|
const deviceStatus = await body.json();
|
|
541
|
-
await this.
|
|
542
|
-
if (
|
|
543
|
-
await this.
|
|
490
|
+
await this.debugLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
491
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
492
|
+
await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
544
493
|
await this.updateHomeKitCharacteristics();
|
|
545
494
|
}
|
|
546
495
|
else {
|
|
@@ -549,26 +498,25 @@ export class CeilingLight extends deviceBase {
|
|
|
549
498
|
}
|
|
550
499
|
}
|
|
551
500
|
catch (e) {
|
|
552
|
-
this.apiError(e);
|
|
553
|
-
this.errorLog(
|
|
554
|
-
+ `
|
|
501
|
+
await this.apiError(e);
|
|
502
|
+
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
|
|
503
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
555
504
|
}
|
|
556
505
|
}
|
|
557
506
|
else {
|
|
558
|
-
this.debugLog(
|
|
559
|
-
+ `
|
|
560
|
-
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
507
|
+
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
508
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
561
509
|
}
|
|
562
510
|
}
|
|
563
511
|
/**
|
|
564
512
|
* Handle requests to set the value of the "On" characteristic
|
|
565
513
|
*/
|
|
566
514
|
async OnSet(value) {
|
|
567
|
-
if (this.LightBulb.On
|
|
568
|
-
this.
|
|
515
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
516
|
+
await this.infoLog(`Set On: ${value}`);
|
|
569
517
|
}
|
|
570
518
|
else {
|
|
571
|
-
this.
|
|
519
|
+
await this.debugLog(`No Changes, Set On: ${value}`);
|
|
572
520
|
}
|
|
573
521
|
this.LightBulb.On = value;
|
|
574
522
|
this.doCeilingLightUpdate.next();
|
|
@@ -577,14 +525,16 @@ export class CeilingLight extends deviceBase {
|
|
|
577
525
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
578
526
|
*/
|
|
579
527
|
async BrightnessSet(value) {
|
|
580
|
-
if (this.LightBulb.Brightness
|
|
581
|
-
this.
|
|
582
|
-
}
|
|
583
|
-
else if (this.LightBulb.On) {
|
|
584
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
528
|
+
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
529
|
+
await this.infoLog(`Set Brightness: ${value}`);
|
|
585
530
|
}
|
|
586
531
|
else {
|
|
587
|
-
|
|
532
|
+
if (this.LightBulb.On) {
|
|
533
|
+
this.debugLog(`No Changes, Brightness: ${value}`);
|
|
534
|
+
}
|
|
535
|
+
else {
|
|
536
|
+
this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`);
|
|
537
|
+
}
|
|
588
538
|
}
|
|
589
539
|
this.LightBulb.Brightness = value;
|
|
590
540
|
this.doCeilingLightUpdate.next();
|
|
@@ -593,14 +543,16 @@ export class CeilingLight extends deviceBase {
|
|
|
593
543
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
594
544
|
*/
|
|
595
545
|
async ColorTemperatureSet(value) {
|
|
596
|
-
if (this.LightBulb.ColorTemperature
|
|
597
|
-
this.
|
|
598
|
-
}
|
|
599
|
-
else if (this.LightBulb.On) {
|
|
600
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
546
|
+
if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
|
|
547
|
+
this.infoLog(`Set ColorTemperature: ${value}`);
|
|
601
548
|
}
|
|
602
549
|
else {
|
|
603
|
-
|
|
550
|
+
if (this.LightBulb.On) {
|
|
551
|
+
this.debugLog(`No Changes, ColorTemperature: ${value}`);
|
|
552
|
+
}
|
|
553
|
+
else {
|
|
554
|
+
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`);
|
|
555
|
+
}
|
|
604
556
|
}
|
|
605
557
|
const minKelvin = 2000;
|
|
606
558
|
const maxKelvin = 9000;
|
|
@@ -622,14 +574,16 @@ export class CeilingLight extends deviceBase {
|
|
|
622
574
|
* Handle requests to set the value of the "Hue" characteristic
|
|
623
575
|
*/
|
|
624
576
|
async HueSet(value) {
|
|
625
|
-
if (this.LightBulb.Hue
|
|
626
|
-
this.
|
|
627
|
-
}
|
|
628
|
-
else if (this.LightBulb.On) {
|
|
629
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
577
|
+
if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
|
|
578
|
+
this.infoLog(`Set Hue: ${value}`);
|
|
630
579
|
}
|
|
631
580
|
else {
|
|
632
|
-
|
|
581
|
+
if (this.LightBulb.On) {
|
|
582
|
+
this.debugLog(`No Changes, Hue: ${value}`);
|
|
583
|
+
}
|
|
584
|
+
else {
|
|
585
|
+
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`);
|
|
586
|
+
}
|
|
633
587
|
}
|
|
634
588
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
635
589
|
this.LightBulb.Hue = value;
|
|
@@ -639,14 +593,16 @@ export class CeilingLight extends deviceBase {
|
|
|
639
593
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
640
594
|
*/
|
|
641
595
|
async SaturationSet(value) {
|
|
642
|
-
if (this.LightBulb.Saturation
|
|
643
|
-
this.
|
|
644
|
-
}
|
|
645
|
-
else if (this.LightBulb.On) {
|
|
646
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
596
|
+
if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
597
|
+
this.infoLog(`Set Saturation: ${value}`);
|
|
647
598
|
}
|
|
648
599
|
else {
|
|
649
|
-
|
|
600
|
+
if (this.LightBulb.On) {
|
|
601
|
+
this.debugLog(`No Changes, Saturation: ${value}`);
|
|
602
|
+
}
|
|
603
|
+
else {
|
|
604
|
+
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`);
|
|
605
|
+
}
|
|
650
606
|
}
|
|
651
607
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
652
608
|
this.LightBulb.Saturation = value;
|
|
@@ -667,24 +623,22 @@ export class CeilingLight extends deviceBase {
|
|
|
667
623
|
async adaptiveLighting(device) {
|
|
668
624
|
if (device.ceilinglight?.adaptiveLightingShift) {
|
|
669
625
|
this.adaptiveLightingShift = device.ceilinglight.adaptiveLightingShift;
|
|
670
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
671
626
|
}
|
|
672
627
|
else {
|
|
673
628
|
this.adaptiveLightingShift = 0;
|
|
674
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
675
629
|
}
|
|
630
|
+
await this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
676
631
|
}
|
|
677
632
|
async BLEPushConnection() {
|
|
678
633
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
679
|
-
this.warnLog(
|
|
634
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
680
635
|
await this.openAPIpushChanges();
|
|
681
636
|
}
|
|
682
637
|
}
|
|
683
638
|
async BLERefreshConnection(switchbot) {
|
|
684
|
-
this.errorLog(
|
|
685
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
639
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
686
640
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
687
|
-
this.warnLog(
|
|
641
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
688
642
|
await this.openAPIRefreshStatus();
|
|
689
643
|
}
|
|
690
644
|
}
|