@switchbot/homebridge-switchbot 3.5.1-beta.0 → 3.5.1-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +224 -370
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +197 -221
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +10 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +214 -292
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +335 -421
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +121 -200
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +20 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +229 -403
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +41 -22
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +212 -181
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +204 -249
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +107 -233
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +193 -235
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +92 -159
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +288 -370
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +172 -219
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +94 -160
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +95 -157
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +85 -144
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +100 -127
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +172 -259
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +106 -131
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +2 -3
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +2 -3
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +2 -3
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +2 -3
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +3 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +5 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +2 -3
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +2 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +2 -3
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -3
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -3
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +102 -86
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -190
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +11 -11
- package/src/device/blindtilt.ts +254 -376
- package/src/device/bot.ts +209 -224
- package/src/device/ceilinglight.ts +227 -297
- package/src/device/colorbulb.ts +345 -435
- package/src/device/contact.ts +139 -200
- package/src/device/curtain.ts +254 -414
- package/src/device/device.ts +221 -190
- package/src/device/fan.ts +222 -253
- package/src/device/hub.ts +127 -248
- package/src/device/humidifier.ts +217 -246
- package/src/device/iosensor.ts +115 -168
- package/src/device/lightstrip.ts +303 -380
- package/src/device/lock.ts +188 -224
- package/src/device/meter.ts +117 -179
- package/src/device/meterplus.ts +118 -176
- package/src/device/motion.ts +100 -146
- package/src/device/plug.ts +111 -131
- package/src/device/robotvacuumcleaner.ts +191 -258
- package/src/device/waterdetector.ts +124 -141
- package/src/irdevice/airconditioner.ts +4 -4
- package/src/irdevice/airpurifier.ts +4 -4
- package/src/irdevice/camera.ts +4 -4
- package/src/irdevice/fan.ts +4 -4
- package/src/irdevice/irdevice.ts +8 -2
- package/src/irdevice/light.ts +4 -4
- package/src/irdevice/other.ts +4 -4
- package/src/irdevice/tv.ts +4 -4
- package/src/irdevice/vacuumcleaner.ts +4 -4
- package/src/irdevice/waterheater.ts +4 -4
- package/src/platform.ts +104 -87
- package/src/settings.ts +30 -238
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
|
@@ -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,35 @@ 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 mired = Math.round(1000000 / deviceStatus.
|
|
168
|
+
if (!Number.isNaN(deviceStatus.colorTemperature)) {
|
|
169
|
+
await this.debugLog(`OpenAPI ColorTemperature: ${deviceStatus.colorTemperature}`);
|
|
170
|
+
const mired = Math.round(1000000 / deviceStatus.colorTemperature);
|
|
200
171
|
this.LightBulb.ColorTemperature = Number(mired);
|
|
201
172
|
this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
|
|
202
|
-
this.debugLog(
|
|
173
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
203
174
|
}
|
|
204
175
|
// Firmware Version
|
|
205
|
-
const version = deviceStatus.
|
|
206
|
-
this.debugLog(
|
|
207
|
-
if (deviceStatus.
|
|
208
|
-
const deviceVersion = version
|
|
176
|
+
const version = deviceStatus.version.toString();
|
|
177
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
178
|
+
if (deviceStatus.version) {
|
|
179
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
209
180
|
this.accessory
|
|
210
181
|
.getService(this.hap.Service.AccessoryInformation)
|
|
211
182
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -213,29 +184,43 @@ export class CeilingLight extends deviceBase {
|
|
|
213
184
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
214
185
|
.updateValue(deviceVersion);
|
|
215
186
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
216
|
-
this.debugSuccessLog(
|
|
187
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
217
188
|
}
|
|
218
189
|
}
|
|
190
|
+
async parseStatusWebhook(context) {
|
|
191
|
+
await this.debugLog('parseStatusWebhook');
|
|
192
|
+
await this.debugLog(`(powerState, brightness, colorTemperature) = Webhook:(${context.powerState}, ${context.brightness},`
|
|
193
|
+
+ ` ${context.colorTemperature}), current:(${this.LightBulb.On}, ${this.LightBulb.Brightness}, ${this.LightBulb.ColorTemperature})`);
|
|
194
|
+
// On
|
|
195
|
+
this.LightBulb.On = context.powerState === 'ON' ? true : false;
|
|
196
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
197
|
+
// Brightness
|
|
198
|
+
this.LightBulb.Brightness = context.brightness;
|
|
199
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
200
|
+
// ColorTemperature
|
|
201
|
+
this.LightBulb.ColorTemperature = context.colorTemperature;
|
|
202
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
203
|
+
}
|
|
219
204
|
/**
|
|
220
205
|
* Asks the SwitchBot API for the latest device information
|
|
221
206
|
*/
|
|
222
207
|
async refreshStatus() {
|
|
223
208
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
224
|
-
this.errorLog(
|
|
225
|
-
|
|
226
|
-
|
|
209
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
210
|
+
}
|
|
211
|
+
else if (this.BLE) {
|
|
212
|
+
await this.BLERefreshStatus();
|
|
227
213
|
}
|
|
228
214
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
229
215
|
await this.openAPIRefreshStatus();
|
|
230
216
|
}
|
|
231
217
|
else {
|
|
232
218
|
await this.offlineOff();
|
|
233
|
-
this.debugWarnLog(
|
|
234
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
219
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
235
220
|
}
|
|
236
221
|
}
|
|
237
222
|
async BLERefreshStatus() {
|
|
238
|
-
this.debugLog(
|
|
223
|
+
await this.debugLog('BLERefreshStatus');
|
|
239
224
|
const switchbot = await this.switchbotBLE();
|
|
240
225
|
if (switchbot === undefined) {
|
|
241
226
|
await this.BLERefreshConnection(switchbot);
|
|
@@ -245,85 +230,56 @@ export class CeilingLight extends deviceBase {
|
|
|
245
230
|
// Start to monitor advertisement packets
|
|
246
231
|
const serviceData = await this.monitorAdvertisementPackets(switchbot);
|
|
247
232
|
// Update HomeKit
|
|
248
|
-
if (serviceData.model
|
|
233
|
+
if ((serviceData.model === SwitchBotBLEModel.CeilingLight || SwitchBotBLEModel.CeilingLightPro)
|
|
234
|
+
&& serviceData.modelName === SwitchBotBLEModelName.CeilingLight || SwitchBotBLEModelName.CeilingLightPro) {
|
|
249
235
|
await this.BLEparseStatus(serviceData);
|
|
250
236
|
await this.updateHomeKitCharacteristics();
|
|
251
237
|
}
|
|
252
238
|
else {
|
|
253
|
-
this.errorLog(
|
|
239
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
254
240
|
await this.BLERefreshConnection(switchbot);
|
|
255
241
|
}
|
|
256
242
|
})();
|
|
257
243
|
}
|
|
258
244
|
}
|
|
259
245
|
async openAPIRefreshStatus() {
|
|
260
|
-
this.debugLog(
|
|
246
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
261
247
|
try {
|
|
262
248
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
263
249
|
const deviceStatus = await body.json();
|
|
264
|
-
await this.
|
|
250
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
265
251
|
;
|
|
266
|
-
if (
|
|
267
|
-
await this.
|
|
268
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
252
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
253
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
254
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
269
255
|
await this.updateHomeKitCharacteristics();
|
|
270
256
|
}
|
|
271
257
|
else {
|
|
272
|
-
await this.
|
|
258
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
259
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
273
260
|
}
|
|
274
261
|
}
|
|
275
262
|
catch (e) {
|
|
276
|
-
this.apiError(e);
|
|
277
|
-
this.errorLog(
|
|
278
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
263
|
+
await this.apiError(e);
|
|
264
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
279
265
|
}
|
|
280
266
|
}
|
|
281
|
-
async registerWebhook(
|
|
282
|
-
if (device.webhook) {
|
|
283
|
-
this.debugLog(
|
|
284
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
267
|
+
async registerWebhook() {
|
|
268
|
+
if (this.device.webhook) {
|
|
269
|
+
await this.debugLog('is listening webhook.');
|
|
270
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
285
271
|
try {
|
|
286
|
-
this.debugLog(
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
|
|
290
|
-
'(powerState, brightness, colorTemperature) = ' +
|
|
291
|
-
`Webhook:(${powerState}, ${brightness}, ${colorTemperature}), `
|
|
292
|
-
+ `current:(${On}, ${Brightness}, ${ColorTemperature})`);
|
|
293
|
-
// On
|
|
294
|
-
this.LightBulb.On = powerState === 'ON' ? true : false;
|
|
295
|
-
if (accessory.context.Brightness !== this.LightBulb.On) {
|
|
296
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} On: ${this.LightBulb.On}`);
|
|
300
|
-
}
|
|
301
|
-
// Brightness
|
|
302
|
-
this.LightBulb.Brightness = brightness;
|
|
303
|
-
if (accessory.context.Brightness !== this.LightBulb.Brightness) {
|
|
304
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
305
|
-
}
|
|
306
|
-
else {
|
|
307
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
308
|
-
}
|
|
309
|
-
// ColorTemperature
|
|
310
|
-
this.LightBulb.ColorTemperature = colorTemperature;
|
|
311
|
-
if (accessory.context.ColorTemperature !== this.LightBulb.ColorTemperature) {
|
|
312
|
-
this.infoLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
313
|
-
}
|
|
314
|
-
else {
|
|
315
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
316
|
-
}
|
|
317
|
-
this.updateHomeKitCharacteristics();
|
|
272
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
273
|
+
await this.parseStatusWebhook(context);
|
|
274
|
+
await this.updateHomeKitCharacteristics();
|
|
318
275
|
}
|
|
319
276
|
catch (e) {
|
|
320
|
-
this.errorLog(
|
|
321
|
-
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
277
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
322
278
|
}
|
|
323
279
|
};
|
|
324
280
|
}
|
|
325
281
|
else {
|
|
326
|
-
this.debugLog(
|
|
282
|
+
await this.debugLog('is not listening webhook.');
|
|
327
283
|
}
|
|
328
284
|
}
|
|
329
285
|
/**
|
|
@@ -339,18 +295,32 @@ export class CeilingLight extends deviceBase {
|
|
|
339
295
|
*/
|
|
340
296
|
async pushChanges() {
|
|
341
297
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
342
|
-
this.errorLog(
|
|
298
|
+
await this.errorLog(`pushChanges enableCloudService: ${this.device.enableCloudService}`);
|
|
343
299
|
}
|
|
344
300
|
else if (this.BLE) {
|
|
345
301
|
await this.BLEpushChanges();
|
|
346
302
|
}
|
|
347
303
|
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
348
304
|
await this.openAPIpushChanges();
|
|
305
|
+
if (this.LightBulb.On) {
|
|
306
|
+
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
307
|
+
// Push Brightness Update
|
|
308
|
+
await this.debugLog(`Brightness: ${this.LightBulb.Brightness}`);
|
|
309
|
+
await this.pushBrightnessChanges();
|
|
310
|
+
// Push ColorTemperature Update
|
|
311
|
+
await this.debugLog(`ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
312
|
+
await this.pushColorTemperatureChanges();
|
|
313
|
+
// Push Hue & Saturation Update
|
|
314
|
+
await this.debugLog(`Hue: ${this.LightBulb.Hue}, Saturation: ${this.LightBulb.Saturation}`);
|
|
315
|
+
await this.pushHueSaturationChanges();
|
|
316
|
+
}
|
|
317
|
+
else {
|
|
318
|
+
await this.debugLog('BLE (Brightness), (ColorTemperature), (Hue), & (Saturation) changes will not happen, as the device is OFF.');
|
|
319
|
+
}
|
|
349
320
|
}
|
|
350
321
|
else {
|
|
351
322
|
await this.offlineOff();
|
|
352
|
-
this.debugWarnLog(
|
|
353
|
-
+ ` ${this.device.connectionType}, pushChanges will not happen.`);
|
|
323
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, pushChanges will not happen.`);
|
|
354
324
|
}
|
|
355
325
|
// Refresh the status from the API
|
|
356
326
|
interval(15000)
|
|
@@ -361,70 +331,63 @@ export class CeilingLight extends deviceBase {
|
|
|
361
331
|
});
|
|
362
332
|
}
|
|
363
333
|
async BLEpushChanges() {
|
|
364
|
-
this.debugLog(
|
|
334
|
+
await this.debugLog('BLEpushChanges');
|
|
365
335
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
366
|
-
this.debugLog(
|
|
367
|
-
|
|
368
|
-
const switchbot = await this.platform.connectBLE();
|
|
369
|
-
// Convert to BLE Address
|
|
336
|
+
await this.debugLog(`BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
337
|
+
const switchbot = await this.platform.connectBLE(this.accessory, this.device);
|
|
370
338
|
await this.convertBLEAddress();
|
|
371
|
-
switchbot
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
339
|
+
if (switchbot !== false) {
|
|
340
|
+
switchbot
|
|
341
|
+
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
342
|
+
.then(async (device_list) => {
|
|
343
|
+
this.infoLog(`On: ${this.LightBulb.On}`);
|
|
344
|
+
return await this.retryBLE({
|
|
345
|
+
max: await this.maxRetryBLE(),
|
|
346
|
+
fn: async () => {
|
|
347
|
+
if (this.LightBulb.On) {
|
|
348
|
+
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
return await device_list[0].turnOff({ id: this.device.bleMac });
|
|
352
|
+
}
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
})
|
|
356
|
+
.then(async () => {
|
|
357
|
+
await this.successLog(`On: ${this.LightBulb.On} sent over SwitchBot BLE, sent successfully`);
|
|
358
|
+
this.LightBulb.On = false;
|
|
359
|
+
})
|
|
360
|
+
.catch(async (e) => {
|
|
361
|
+
await this.apiError(e);
|
|
362
|
+
await this.errorLog(`failed BLEpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
363
|
+
await this.BLEPushConnection();
|
|
385
364
|
});
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
this.
|
|
389
|
-
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
390
|
-
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
391
|
-
this.LightBulb.On = false;
|
|
392
|
-
})
|
|
393
|
-
.catch(async (e) => {
|
|
394
|
-
this.apiError(e);
|
|
395
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLEpushChanges with ${this.device.connectionType}`
|
|
396
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
365
|
+
}
|
|
366
|
+
else {
|
|
367
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
397
368
|
await this.BLEPushConnection();
|
|
398
|
-
}
|
|
369
|
+
}
|
|
399
370
|
}
|
|
400
371
|
else {
|
|
401
|
-
this.debugLog(
|
|
402
|
-
+ ` No BLEpushChanges: On: ${this.LightBulb.On}, `
|
|
403
|
-
+ `OnCached: ${this.accessory.context.On}`);
|
|
372
|
+
await this.debugLog(`No changes (BLEpushChanges): On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
404
373
|
}
|
|
405
374
|
}
|
|
406
375
|
async openAPIpushChanges() {
|
|
407
|
-
this.debugLog(
|
|
376
|
+
await this.debugLog('openAPIpushChanges');
|
|
408
377
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
409
|
-
|
|
410
|
-
if (this.LightBulb.On) {
|
|
411
|
-
command = 'turnOn';
|
|
412
|
-
}
|
|
413
|
-
else {
|
|
414
|
-
command = 'turnOff';
|
|
415
|
-
}
|
|
378
|
+
const command = this.LightBulb.On ? 'turnOn' : 'turnOff';
|
|
416
379
|
const bodyChange = JSON.stringify({
|
|
417
380
|
command: `${command}`,
|
|
418
381
|
parameter: 'default',
|
|
419
382
|
commandType: 'command',
|
|
420
383
|
});
|
|
421
|
-
this.debugLog(
|
|
384
|
+
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
422
385
|
try {
|
|
423
386
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
424
387
|
const deviceStatus = await body.json();
|
|
425
|
-
await this.
|
|
426
|
-
if (
|
|
427
|
-
await this.
|
|
388
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
389
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
390
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
428
391
|
await this.updateHomeKitCharacteristics();
|
|
429
392
|
}
|
|
430
393
|
else {
|
|
@@ -433,48 +396,33 @@ export class CeilingLight extends deviceBase {
|
|
|
433
396
|
}
|
|
434
397
|
}
|
|
435
398
|
catch (e) {
|
|
436
|
-
this.apiError(e);
|
|
437
|
-
this.errorLog(
|
|
438
|
-
+ ` Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
399
|
+
await this.apiError(e);
|
|
400
|
+
await this.errorLog(`failed openAPIpushChanges with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
439
401
|
}
|
|
440
402
|
}
|
|
441
403
|
else {
|
|
442
|
-
this.debugLog(
|
|
443
|
-
+ `On: ${this.LightBulb.On}, `
|
|
444
|
-
+ `OnCached: ${this.accessory.context.On}`);
|
|
445
|
-
}
|
|
446
|
-
// Push Hue & Saturation Update
|
|
447
|
-
if (this.LightBulb.On) {
|
|
448
|
-
await this.pushHueSaturationChanges();
|
|
449
|
-
}
|
|
450
|
-
// Push ColorTemperature Update
|
|
451
|
-
if (this.LightBulb.On) {
|
|
452
|
-
await this.pushColorTemperatureChanges();
|
|
453
|
-
}
|
|
454
|
-
// Push Brightness Update
|
|
455
|
-
if (this.LightBulb.On) {
|
|
456
|
-
await this.pushBrightnessChanges();
|
|
404
|
+
await this.debugLog(`No changes (openAPIpushChanges), On: ${this.LightBulb.On}, OnCached: ${this.accessory.context.On}`);
|
|
457
405
|
}
|
|
458
406
|
}
|
|
459
407
|
async pushHueSaturationChanges() {
|
|
460
|
-
this.debugLog(
|
|
461
|
-
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
462
|
-
this.debugLog(
|
|
463
|
-
this.debugLog(
|
|
408
|
+
await this.debugLog('pushHueSaturationChanges');
|
|
409
|
+
if ((this.LightBulb.Hue !== this.accessory.context.Hue) || (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
410
|
+
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
|
|
411
|
+
await this.debugLog(`Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
464
412
|
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
|
|
465
|
-
this.debugLog(
|
|
413
|
+
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`);
|
|
466
414
|
const bodyChange = JSON.stringify({
|
|
467
415
|
command: 'setColor',
|
|
468
416
|
parameter: `${red}:${green}:${blue}`,
|
|
469
417
|
commandType: 'command',
|
|
470
418
|
});
|
|
471
|
-
this.debugLog(
|
|
419
|
+
await this.debugLog(`(pushHueSaturationChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
472
420
|
try {
|
|
473
421
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
474
422
|
const deviceStatus = await body.json();
|
|
475
|
-
await this.
|
|
476
|
-
if (
|
|
477
|
-
await this.
|
|
423
|
+
await this.debugLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
424
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
425
|
+
await this.debugSuccessLog(`(pushHueSaturationChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
478
426
|
await this.updateHomeKitCharacteristics();
|
|
479
427
|
}
|
|
480
428
|
else {
|
|
@@ -483,18 +431,18 @@ export class CeilingLight extends deviceBase {
|
|
|
483
431
|
}
|
|
484
432
|
}
|
|
485
433
|
catch (e) {
|
|
486
|
-
this.apiError(e);
|
|
487
|
-
this.errorLog(
|
|
488
|
-
+ `
|
|
434
|
+
await this.apiError(e);
|
|
435
|
+
await this.errorLog(`failed pushHueSaturationChanges with ${this.device.connectionType} Connection,`
|
|
436
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
489
437
|
}
|
|
490
438
|
}
|
|
491
439
|
else {
|
|
492
|
-
this.debugLog(
|
|
493
|
-
+
|
|
440
|
+
await this.debugLog(`No changes (pushHueSaturationChanges), Hue: ${this.LightBulb.Hue}, HueCached: ${this.accessory.context.Hue},`
|
|
441
|
+
+ ` Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
494
442
|
}
|
|
495
443
|
}
|
|
496
444
|
async pushColorTemperatureChanges() {
|
|
497
|
-
this.debugLog(
|
|
445
|
+
await this.debugLog('pushColorTemperatureChanges');
|
|
498
446
|
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
499
447
|
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
500
448
|
this.accessory.context.kelvin = kelvin;
|
|
@@ -503,13 +451,13 @@ export class CeilingLight extends deviceBase {
|
|
|
503
451
|
parameter: `${kelvin}`,
|
|
504
452
|
commandType: 'command',
|
|
505
453
|
});
|
|
506
|
-
this.debugLog(
|
|
454
|
+
await this.debugLog(`(pushColorTemperatureChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
507
455
|
try {
|
|
508
456
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
509
457
|
const deviceStatus = await body.json();
|
|
510
|
-
await this.
|
|
511
|
-
if (
|
|
512
|
-
await this.
|
|
458
|
+
await this.debugLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
459
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
460
|
+
await this.debugSuccessLog(`(pushColorTemperatureChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
513
461
|
await this.updateHomeKitCharacteristics();
|
|
514
462
|
}
|
|
515
463
|
else {
|
|
@@ -518,31 +466,31 @@ export class CeilingLight extends deviceBase {
|
|
|
518
466
|
}
|
|
519
467
|
}
|
|
520
468
|
catch (e) {
|
|
521
|
-
this.apiError(e);
|
|
522
|
-
this.errorLog(
|
|
523
|
-
+ `
|
|
469
|
+
await this.apiError(e);
|
|
470
|
+
await this.errorLog(`failed pushColorTemperatureChanges with ${this.device.connectionType} Connection,`
|
|
471
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
524
472
|
}
|
|
525
473
|
}
|
|
526
474
|
else {
|
|
527
|
-
this.debugLog(
|
|
528
|
-
+ `
|
|
475
|
+
await this.debugLog(`No changes (pushColorTemperatureChanges), ColorTemperature: ${this.LightBulb.ColorTemperature},`
|
|
476
|
+
+ ` ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
529
477
|
}
|
|
530
478
|
}
|
|
531
479
|
async pushBrightnessChanges() {
|
|
532
|
-
this.debugLog(
|
|
480
|
+
await this.debugLog('pushBrightnessChanges');
|
|
533
481
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
534
482
|
const bodyChange = JSON.stringify({
|
|
535
483
|
command: 'setBrightness',
|
|
536
484
|
parameter: `${this.LightBulb.Brightness}`,
|
|
537
485
|
commandType: 'command',
|
|
538
486
|
});
|
|
539
|
-
this.debugLog(
|
|
487
|
+
await this.debugLog(`(pushBrightnessChanges) SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`);
|
|
540
488
|
try {
|
|
541
489
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
542
490
|
const deviceStatus = await body.json();
|
|
543
|
-
await this.
|
|
544
|
-
if (
|
|
545
|
-
await this.
|
|
491
|
+
await this.debugLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
492
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
493
|
+
await this.debugSuccessLog(`(pushBrightnessChanges) statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
546
494
|
await this.updateHomeKitCharacteristics();
|
|
547
495
|
}
|
|
548
496
|
else {
|
|
@@ -551,26 +499,25 @@ export class CeilingLight extends deviceBase {
|
|
|
551
499
|
}
|
|
552
500
|
}
|
|
553
501
|
catch (e) {
|
|
554
|
-
this.apiError(e);
|
|
555
|
-
this.errorLog(
|
|
556
|
-
+ `
|
|
502
|
+
await this.apiError(e);
|
|
503
|
+
await this.errorLog(`failed pushBrightnessChanges with ${this.device.connectionType} Connection,`
|
|
504
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
557
505
|
}
|
|
558
506
|
}
|
|
559
507
|
else {
|
|
560
|
-
this.debugLog(
|
|
561
|
-
+ `
|
|
562
|
-
+ `BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
508
|
+
await this.debugLog(`No changes (pushBrightnessChanges), Brightness: ${this.LightBulb.Brightness},`
|
|
509
|
+
+ ` BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
563
510
|
}
|
|
564
511
|
}
|
|
565
512
|
/**
|
|
566
513
|
* Handle requests to set the value of the "On" characteristic
|
|
567
514
|
*/
|
|
568
515
|
async OnSet(value) {
|
|
569
|
-
if (this.LightBulb.On
|
|
570
|
-
this.
|
|
516
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
517
|
+
await this.infoLog(`Set On: ${value}`);
|
|
571
518
|
}
|
|
572
519
|
else {
|
|
573
|
-
this.
|
|
520
|
+
await this.debugLog(`No Changes, Set On: ${value}`);
|
|
574
521
|
}
|
|
575
522
|
this.LightBulb.On = value;
|
|
576
523
|
this.doCeilingLightUpdate.next();
|
|
@@ -579,14 +526,16 @@ export class CeilingLight extends deviceBase {
|
|
|
579
526
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
580
527
|
*/
|
|
581
528
|
async BrightnessSet(value) {
|
|
582
|
-
if (this.LightBulb.Brightness
|
|
583
|
-
this.
|
|
584
|
-
}
|
|
585
|
-
else if (this.LightBulb.On) {
|
|
586
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
529
|
+
if (this.LightBulb.On && (this.LightBulb.Brightness !== this.accessory.context.Brightness)) {
|
|
530
|
+
await this.infoLog(`Set Brightness: ${value}`);
|
|
587
531
|
}
|
|
588
532
|
else {
|
|
589
|
-
|
|
533
|
+
if (this.LightBulb.On) {
|
|
534
|
+
this.debugLog(`No Changes, Brightness: ${value}`);
|
|
535
|
+
}
|
|
536
|
+
else {
|
|
537
|
+
this.debugLog(`Set Brightness: ${value}, On: ${this.LightBulb.On}`);
|
|
538
|
+
}
|
|
590
539
|
}
|
|
591
540
|
this.LightBulb.Brightness = value;
|
|
592
541
|
this.doCeilingLightUpdate.next();
|
|
@@ -595,14 +544,16 @@ export class CeilingLight extends deviceBase {
|
|
|
595
544
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
596
545
|
*/
|
|
597
546
|
async ColorTemperatureSet(value) {
|
|
598
|
-
if (this.LightBulb.ColorTemperature
|
|
599
|
-
this.
|
|
600
|
-
}
|
|
601
|
-
else if (this.LightBulb.On) {
|
|
602
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
547
|
+
if (this.LightBulb.On && (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature)) {
|
|
548
|
+
this.infoLog(`Set ColorTemperature: ${value}`);
|
|
603
549
|
}
|
|
604
550
|
else {
|
|
605
|
-
|
|
551
|
+
if (this.LightBulb.On) {
|
|
552
|
+
this.debugLog(`No Changes, ColorTemperature: ${value}`);
|
|
553
|
+
}
|
|
554
|
+
else {
|
|
555
|
+
this.debugLog(`Set ColorTemperature: ${value}, On: ${this.LightBulb.On}`);
|
|
556
|
+
}
|
|
606
557
|
}
|
|
607
558
|
const minKelvin = 2000;
|
|
608
559
|
const maxKelvin = 9000;
|
|
@@ -624,14 +575,16 @@ export class CeilingLight extends deviceBase {
|
|
|
624
575
|
* Handle requests to set the value of the "Hue" characteristic
|
|
625
576
|
*/
|
|
626
577
|
async HueSet(value) {
|
|
627
|
-
if (this.LightBulb.Hue
|
|
628
|
-
this.
|
|
629
|
-
}
|
|
630
|
-
else if (this.LightBulb.On) {
|
|
631
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
578
|
+
if (this.LightBulb.On && (this.LightBulb.Hue !== this.accessory.context.Hue)) {
|
|
579
|
+
this.infoLog(`Set Hue: ${value}`);
|
|
632
580
|
}
|
|
633
581
|
else {
|
|
634
|
-
|
|
582
|
+
if (this.LightBulb.On) {
|
|
583
|
+
this.debugLog(`No Changes, Hue: ${value}`);
|
|
584
|
+
}
|
|
585
|
+
else {
|
|
586
|
+
this.debugLog(`Set Hue: ${value}, On: ${this.LightBulb.On}`);
|
|
587
|
+
}
|
|
635
588
|
}
|
|
636
589
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
637
590
|
this.LightBulb.Hue = value;
|
|
@@ -641,83 +594,52 @@ export class CeilingLight extends deviceBase {
|
|
|
641
594
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
642
595
|
*/
|
|
643
596
|
async SaturationSet(value) {
|
|
644
|
-
if (this.LightBulb.Saturation
|
|
645
|
-
this.
|
|
646
|
-
}
|
|
647
|
-
else if (this.LightBulb.On) {
|
|
648
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
597
|
+
if (this.LightBulb.On && (this.LightBulb.Saturation !== this.accessory.context.Saturation)) {
|
|
598
|
+
this.infoLog(`Set Saturation: ${value}`);
|
|
649
599
|
}
|
|
650
600
|
else {
|
|
651
|
-
|
|
601
|
+
if (this.LightBulb.On) {
|
|
602
|
+
this.debugLog(`No Changes, Saturation: ${value}`);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
this.debugLog(`Set Saturation: ${value}, On: ${this.LightBulb.On}`);
|
|
606
|
+
}
|
|
652
607
|
}
|
|
653
608
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
654
609
|
this.LightBulb.Saturation = value;
|
|
655
610
|
this.doCeilingLightUpdate.next();
|
|
656
611
|
}
|
|
657
612
|
async updateHomeKitCharacteristics() {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
}
|
|
669
|
-
else {
|
|
670
|
-
this.accessory.context.Brightness = this.LightBulb.Brightness;
|
|
671
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
|
|
672
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
|
|
673
|
-
}
|
|
674
|
-
if (this.LightBulb.ColorTemperature === undefined) {
|
|
675
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
676
|
-
}
|
|
677
|
-
else {
|
|
678
|
-
this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
|
|
679
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
|
|
680
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
681
|
-
+ ` updateCharacteristic ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
682
|
-
}
|
|
683
|
-
if (this.LightBulb.Hue === undefined) {
|
|
684
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
685
|
-
}
|
|
686
|
-
else {
|
|
687
|
-
this.accessory.context.Hue = this.LightBulb.Hue;
|
|
688
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
|
|
689
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
|
|
690
|
-
}
|
|
691
|
-
if (this.LightBulb.Saturation === undefined) {
|
|
692
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
693
|
-
}
|
|
694
|
-
else {
|
|
695
|
-
this.accessory.context.Saturation = this.LightBulb.Saturation;
|
|
696
|
-
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
|
|
697
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
|
|
698
|
-
}
|
|
613
|
+
// On
|
|
614
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.On, this.LightBulb.On, 'On');
|
|
615
|
+
// Brightness
|
|
616
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Brightness, this.LightBulb.Brightness, 'Brightness');
|
|
617
|
+
// ColorTemperature
|
|
618
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature, 'ColorTemperature');
|
|
619
|
+
// Hue
|
|
620
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Hue, this.LightBulb.Hue, 'Hue');
|
|
621
|
+
// Saturation
|
|
622
|
+
await this.updateCharacteristic(this.LightBulb.Service, this.hap.Characteristic.Saturation, this.LightBulb.Saturation, 'Saturation');
|
|
699
623
|
}
|
|
700
624
|
async adaptiveLighting(device) {
|
|
701
625
|
if (device.ceilinglight?.adaptiveLightingShift) {
|
|
702
626
|
this.adaptiveLightingShift = device.ceilinglight.adaptiveLightingShift;
|
|
703
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
704
627
|
}
|
|
705
628
|
else {
|
|
706
629
|
this.adaptiveLightingShift = 0;
|
|
707
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
708
630
|
}
|
|
631
|
+
await this.debugLog(`adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
709
632
|
}
|
|
710
633
|
async BLEPushConnection() {
|
|
711
634
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
712
|
-
this.warnLog(
|
|
635
|
+
await this.warnLog('Using OpenAPI Connection to Push Changes');
|
|
713
636
|
await this.openAPIpushChanges();
|
|
714
637
|
}
|
|
715
638
|
}
|
|
716
639
|
async BLERefreshConnection(switchbot) {
|
|
717
|
-
this.errorLog(
|
|
718
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
640
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
719
641
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
720
|
-
this.warnLog(
|
|
642
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
721
643
|
await this.openAPIRefreshStatus();
|
|
722
644
|
}
|
|
723
645
|
}
|
|
@@ -726,7 +648,7 @@ export class CeilingLight extends deviceBase {
|
|
|
726
648
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
727
649
|
}
|
|
728
650
|
}
|
|
729
|
-
apiError(e) {
|
|
651
|
+
async apiError(e) {
|
|
730
652
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
731
653
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
732
654
|
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|