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