@switchbot/homebridge-switchbot 3.5.0-beta.22 → 3.5.0-beta.24
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/config.schema.json +23 -2
- package/dist/device/blindtilt.d.ts +21 -98
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +332 -785
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +25 -75
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +566 -778
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -71
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +168 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +13 -78
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +218 -655
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +14 -69
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +196 -553
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +17 -90
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +324 -810
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +58 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +629 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/hub.d.ts +15 -63
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +223 -610
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +10 -69
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -595
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -68
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +156 -599
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -72
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +204 -591
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +15 -66
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +199 -566
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +13 -67
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +152 -592
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +13 -68
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +151 -599
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -73
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +129 -540
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -61
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +71 -476
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -66
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +122 -471
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +9 -66
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +105 -478
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +5 -36
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +228 -337
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -34
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +19 -267
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +5 -34
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +13 -261
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +5 -34
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +13 -260
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +39 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +502 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +5 -34
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -267
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +18 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +349 -551
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +7 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +79 -325
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +6 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +38 -288
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +6 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +39 -291
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +15 -2
- package/dist/settings.d.ts.map +1 -1
- package/dist/utils.d.ts +68 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +71 -0
- package/dist/utils.js.map +1 -1
- package/package.json +8 -8
- package/src/device/blindtilt.ts +356 -809
- package/src/device/bot.ts +601 -865
- package/src/device/ceilinglight.ts +182 -628
- package/src/device/colorbulb.ts +235 -683
- package/src/device/contact.ts +220 -575
- package/src/device/curtain.ts +344 -836
- package/src/device/device.ts +655 -0
- package/src/device/hub.ts +246 -636
- package/src/device/humidifier.ts +224 -645
- package/src/device/iosensor.ts +181 -625
- package/src/device/lightstrip.ts +230 -622
- package/src/device/lock.ts +236 -607
- package/src/device/meter.ts +177 -616
- package/src/device/meterplus.ts +175 -624
- package/src/device/motion.ts +147 -563
- package/src/device/plug.ts +81 -505
- package/src/device/robotvacuumcleaner.ts +139 -494
- package/src/device/waterdetector.ts +126 -506
- package/src/irdevice/airconditioner.ts +228 -353
- package/src/irdevice/airpurifier.ts +23 -282
- package/src/irdevice/camera.ts +18 -277
- package/src/irdevice/fan.ts +18 -275
- package/src/irdevice/irdevice.ts +518 -0
- package/src/irdevice/light.ts +18 -283
- package/src/irdevice/other.ts +394 -621
- package/src/irdevice/tv.ts +97 -344
- package/src/irdevice/vacuumcleaner.ts +46 -310
- package/src/irdevice/waterheater.ts +47 -315
- package/src/settings.ts +20 -3
- package/src/utils.ts +71 -0
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* ceilinglight.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
1
5
|
import { request } from 'undici';
|
|
2
|
-
import {
|
|
6
|
+
import { deviceBase } from './device.js';
|
|
7
|
+
import { hs2rgb, rgb2hs, m2hs } from '../utils.js';
|
|
3
8
|
import { interval, Subject } from 'rxjs';
|
|
4
9
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
10
|
import { Devices } from '../settings.js';
|
|
@@ -8,105 +13,49 @@ import { Devices } from '../settings.js';
|
|
|
8
13
|
* An instance of this class is created for each accessory your platform registers
|
|
9
14
|
* Each accessory may expose multiple services of different service types.
|
|
10
15
|
*/
|
|
11
|
-
export class CeilingLight {
|
|
16
|
+
export class CeilingLight extends deviceBase {
|
|
12
17
|
platform;
|
|
13
|
-
accessory;
|
|
14
|
-
device;
|
|
15
|
-
api;
|
|
16
|
-
log;
|
|
17
|
-
config;
|
|
18
|
-
hap;
|
|
19
18
|
// Services
|
|
20
|
-
|
|
21
|
-
// Characteristic Values
|
|
22
|
-
On;
|
|
23
|
-
Hue;
|
|
24
|
-
Saturation;
|
|
25
|
-
Brightness;
|
|
26
|
-
ColorTemperature;
|
|
27
|
-
FirmwareRevision;
|
|
28
|
-
// OpenAPI Status
|
|
29
|
-
OpenAPI_On;
|
|
30
|
-
OpenAPI_RGB;
|
|
31
|
-
OpenAPI_Brightness;
|
|
32
|
-
OpenAPI_FirmwareRevision;
|
|
33
|
-
OpenAPI_ColorTemperature;
|
|
34
|
-
// BLE Status
|
|
35
|
-
BLE_Delay;
|
|
36
|
-
BLE_On;
|
|
37
|
-
BLE_WifiRssi;
|
|
38
|
-
// BLE Others
|
|
39
|
-
BLE_IsConnected;
|
|
40
|
-
// Config
|
|
41
|
-
set_minStep;
|
|
42
|
-
scanDuration;
|
|
43
|
-
deviceLogging;
|
|
44
|
-
deviceRefreshRate;
|
|
45
|
-
adaptiveLightingShift;
|
|
46
|
-
maxRetries;
|
|
47
|
-
delayBetweenRetries;
|
|
19
|
+
LightBulb;
|
|
48
20
|
// Adaptive Lighting
|
|
49
21
|
AdaptiveLightingController;
|
|
50
|
-
|
|
51
|
-
maxKelvin;
|
|
52
|
-
// Others
|
|
53
|
-
cacheKelvin;
|
|
22
|
+
adaptiveLightingShift;
|
|
54
23
|
// Updates
|
|
55
24
|
ceilingLightUpdateInProgress;
|
|
56
25
|
doCeilingLightUpdate;
|
|
57
|
-
// Connection
|
|
58
|
-
OpenAPI;
|
|
59
|
-
BLE;
|
|
60
26
|
constructor(platform, accessory, device) {
|
|
27
|
+
super(platform, accessory, device);
|
|
61
28
|
this.platform = platform;
|
|
62
|
-
this.accessory = accessory;
|
|
63
|
-
this.device = device;
|
|
64
|
-
this.api = this.platform.api;
|
|
65
|
-
this.log = this.platform.log;
|
|
66
|
-
this.config = this.platform.config;
|
|
67
|
-
this.hap = this.api.hap;
|
|
68
|
-
// Connection
|
|
69
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
70
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
71
29
|
// default placeholders
|
|
72
|
-
this.deviceLogs(device);
|
|
73
|
-
this.scan(device);
|
|
74
|
-
this.refreshRate(device);
|
|
75
30
|
this.adaptiveLighting(device);
|
|
76
|
-
this.deviceContext();
|
|
77
|
-
this.deviceRetry(device);
|
|
78
|
-
this.deviceConfig(device);
|
|
79
31
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
80
32
|
this.doCeilingLightUpdate = new Subject();
|
|
81
33
|
this.ceilingLightUpdateInProgress = false;
|
|
82
34
|
// Retrieve initial values and updateHomekit
|
|
83
35
|
this.refreshStatus();
|
|
84
|
-
//
|
|
85
|
-
|
|
86
|
-
.
|
|
87
|
-
.
|
|
88
|
-
.
|
|
89
|
-
.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
(this.
|
|
95
|
-
|| accessory.addService(this.hap.Service.Lightbulb)),
|
|
36
|
+
// Initialize LightBulb property
|
|
37
|
+
this.LightBulb = {
|
|
38
|
+
Service: this.accessory.addService(this.hap.Service.Lightbulb),
|
|
39
|
+
On: accessory.context.On || false,
|
|
40
|
+
Hue: accessory.context.Hue || 0,
|
|
41
|
+
Saturation: accessory.context.Saturation || 0,
|
|
42
|
+
Brightness: accessory.context.Brightness || 0,
|
|
43
|
+
ColorTemperature: accessory.context.ColorTemperature || 140,
|
|
44
|
+
};
|
|
45
|
+
const LightBulbService = `${accessory.displayName} ${device.deviceType}`;
|
|
46
|
+
(this.LightBulb.Service = accessory.getService(this.hap.Service.Lightbulb)
|
|
47
|
+
|| accessory.addService(this.hap.Service.Lightbulb)), LightBulbService;
|
|
96
48
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
97
|
-
this.accessory.removeService(this.
|
|
98
|
-
this.
|
|
49
|
+
this.accessory.removeService(this.LightBulb.Service);
|
|
50
|
+
this.LightBulb.Service = this.accessory.addService(this.hap.Service.Lightbulb);
|
|
99
51
|
this.accessory.context.adaptiveLighting = false;
|
|
100
52
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
101
53
|
}
|
|
102
|
-
this.
|
|
103
|
-
if (!this.lightBulbService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
104
|
-
this.lightBulbService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
105
|
-
}
|
|
54
|
+
this.LightBulb.Service.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
106
55
|
// handle on / off events using the On characteristic
|
|
107
|
-
this.
|
|
56
|
+
this.LightBulb.Service.getCharacteristic(this.hap.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
108
57
|
// handle Brightness events using the Brightness characteristic
|
|
109
|
-
this.
|
|
58
|
+
this.LightBulb.Service
|
|
110
59
|
.getCharacteristic(this.hap.Characteristic.Brightness)
|
|
111
60
|
.setProps({
|
|
112
61
|
minStep: this.minStep(device),
|
|
@@ -115,11 +64,11 @@ export class CeilingLight {
|
|
|
115
64
|
validValueRanges: [0, 100],
|
|
116
65
|
})
|
|
117
66
|
.onGet(() => {
|
|
118
|
-
return this.Brightness;
|
|
67
|
+
return this.LightBulb.Brightness;
|
|
119
68
|
})
|
|
120
69
|
.onSet(this.BrightnessSet.bind(this));
|
|
121
70
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
122
|
-
this.
|
|
71
|
+
this.LightBulb.Service
|
|
123
72
|
.getCharacteristic(this.hap.Characteristic.ColorTemperature)
|
|
124
73
|
.setProps({
|
|
125
74
|
minValue: 140,
|
|
@@ -127,11 +76,11 @@ export class CeilingLight {
|
|
|
127
76
|
validValueRanges: [140, 500],
|
|
128
77
|
})
|
|
129
78
|
.onGet(() => {
|
|
130
|
-
return this.ColorTemperature;
|
|
79
|
+
return this.LightBulb.ColorTemperature;
|
|
131
80
|
})
|
|
132
81
|
.onSet(this.ColorTemperatureSet.bind(this));
|
|
133
82
|
// handle Hue events using the Hue characteristic
|
|
134
|
-
this.
|
|
83
|
+
this.LightBulb.Service
|
|
135
84
|
.getCharacteristic(this.hap.Characteristic.Hue)
|
|
136
85
|
.setProps({
|
|
137
86
|
minValue: 0,
|
|
@@ -139,11 +88,11 @@ export class CeilingLight {
|
|
|
139
88
|
validValueRanges: [0, 360],
|
|
140
89
|
})
|
|
141
90
|
.onGet(() => {
|
|
142
|
-
return this.Hue;
|
|
91
|
+
return this.LightBulb.Hue;
|
|
143
92
|
})
|
|
144
93
|
.onSet(this.HueSet.bind(this));
|
|
145
94
|
// handle Hue events using the Hue characteristic
|
|
146
|
-
this.
|
|
95
|
+
this.LightBulb.Service
|
|
147
96
|
.getCharacteristic(this.hap.Characteristic.Saturation)
|
|
148
97
|
.setProps({
|
|
149
98
|
minValue: 0,
|
|
@@ -151,12 +100,12 @@ export class CeilingLight {
|
|
|
151
100
|
validValueRanges: [0, 100],
|
|
152
101
|
})
|
|
153
102
|
.onGet(() => {
|
|
154
|
-
return this.Saturation;
|
|
103
|
+
return this.LightBulb.Saturation;
|
|
155
104
|
})
|
|
156
105
|
.onSet(this.SaturationSet.bind(this));
|
|
157
106
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
158
107
|
if (this.adaptiveLightingShift !== -1) {
|
|
159
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.
|
|
108
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.LightBulb.Service, {
|
|
160
109
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
161
110
|
});
|
|
162
111
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
@@ -179,14 +128,14 @@ export class CeilingLight {
|
|
|
179
128
|
try {
|
|
180
129
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
181
130
|
const { powerState, brightness, colorTemperature } = context;
|
|
182
|
-
const { On, Brightness, ColorTemperature } = this;
|
|
131
|
+
const { On, Brightness, ColorTemperature } = this.LightBulb;
|
|
183
132
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
184
133
|
'(powerState, brightness, colorTemperature) = ' +
|
|
185
134
|
`Webhook:(${powerState}, ${brightness}, ${colorTemperature}), ` +
|
|
186
135
|
`current:(${On}, ${Brightness}, ${ColorTemperature})`);
|
|
187
|
-
this.On = powerState === 'ON' ? true : false;
|
|
188
|
-
this.Brightness = brightness;
|
|
189
|
-
this.ColorTemperature = colorTemperature;
|
|
136
|
+
this.LightBulb.On = powerState === 'ON' ? true : false;
|
|
137
|
+
this.LightBulb.Brightness = brightness;
|
|
138
|
+
this.LightBulb.ColorTemperature = colorTemperature;
|
|
190
139
|
this.updateHomeKitCharacteristics();
|
|
191
140
|
}
|
|
192
141
|
catch (e) {
|
|
@@ -213,88 +162,63 @@ export class CeilingLight {
|
|
|
213
162
|
this.ceilingLightUpdateInProgress = false;
|
|
214
163
|
});
|
|
215
164
|
}
|
|
216
|
-
model(device) {
|
|
217
|
-
let model;
|
|
218
|
-
if (device.deviceType === 'Ceiling Light') {
|
|
219
|
-
model = 'W2612230' || 'W2612240';
|
|
220
|
-
}
|
|
221
|
-
else if (device.deviceType === 'Ceiling Light Pro') {
|
|
222
|
-
model = 'W2612210' || 'W2612220';
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
model = 'unknown';
|
|
226
|
-
}
|
|
227
|
-
return model;
|
|
228
|
-
}
|
|
229
165
|
/**
|
|
230
|
-
* Parse the device status from the
|
|
166
|
+
* Parse the device status from the SwitchBotBLE API
|
|
231
167
|
*/
|
|
232
|
-
async
|
|
233
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
234
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
235
|
-
}
|
|
236
|
-
/*if (this.BLE) {
|
|
237
|
-
await this.BLEparseStatus();
|
|
238
|
-
} else*/ if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
239
|
-
await this.openAPIparseStatus();
|
|
240
|
-
}
|
|
241
|
-
else {
|
|
242
|
-
await this.offlineOff();
|
|
243
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
async BLEparseStatus() {
|
|
168
|
+
async BLEparseStatus(serviceData) {
|
|
247
169
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
248
170
|
// State
|
|
249
|
-
switch (
|
|
171
|
+
switch (serviceData.state) {
|
|
250
172
|
case 'on':
|
|
251
|
-
this.On = true;
|
|
173
|
+
this.LightBulb.On = true;
|
|
252
174
|
break;
|
|
253
175
|
default:
|
|
254
|
-
this.On = false;
|
|
176
|
+
this.LightBulb.On = false;
|
|
255
177
|
}
|
|
256
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
178
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
257
179
|
}
|
|
258
|
-
|
|
180
|
+
/**
|
|
181
|
+
* Parse the device status from the SwitchBot OpenAPI
|
|
182
|
+
*/
|
|
183
|
+
async openAPIparseStatus(deviceStatus) {
|
|
259
184
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
260
|
-
switch (
|
|
185
|
+
switch (deviceStatus.body.power) {
|
|
261
186
|
case 'on':
|
|
262
|
-
this.On = true;
|
|
187
|
+
this.LightBulb.On = true;
|
|
263
188
|
break;
|
|
264
189
|
default:
|
|
265
|
-
this.On = false;
|
|
190
|
+
this.LightBulb.On = false;
|
|
266
191
|
}
|
|
267
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
192
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
268
193
|
// Brightness
|
|
269
|
-
this.Brightness = Number(
|
|
270
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
194
|
+
this.LightBulb.Brightness = Number(deviceStatus.body.brightness);
|
|
195
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
271
196
|
// Color, Hue & Brightness
|
|
272
|
-
if (
|
|
273
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(
|
|
274
|
-
const [red, green, blue] =
|
|
197
|
+
if (deviceStatus.body.color) {
|
|
198
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(deviceStatus.body.color)}`);
|
|
199
|
+
const [red, green, blue] = deviceStatus.body.color.split(':');
|
|
275
200
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
276
201
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
277
202
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
278
203
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
279
204
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}` + ` hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
280
205
|
// Hue
|
|
281
|
-
this.Hue = hue;
|
|
282
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
206
|
+
this.LightBulb.Hue = hue;
|
|
207
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
283
208
|
// Saturation
|
|
284
|
-
this.Saturation = saturation;
|
|
285
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
209
|
+
this.LightBulb.Saturation = saturation;
|
|
210
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
286
211
|
}
|
|
287
212
|
// ColorTemperature
|
|
288
|
-
if (!Number.isNaN(
|
|
289
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${
|
|
290
|
-
const mired = Math.round(1000000 /
|
|
291
|
-
this.ColorTemperature = Number(mired);
|
|
292
|
-
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
293
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
213
|
+
if (!Number.isNaN(deviceStatus.body.colorTemperature)) {
|
|
214
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${deviceStatus.body.colorTemperature}`);
|
|
215
|
+
const mired = Math.round(1000000 / deviceStatus.body.colorTemperature);
|
|
216
|
+
this.LightBulb.ColorTemperature = Number(mired);
|
|
217
|
+
this.LightBulb.ColorTemperature = Math.max(Math.min(this.LightBulb.ColorTemperature, 500), 140);
|
|
218
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
294
219
|
}
|
|
295
220
|
// FirmwareRevision
|
|
296
|
-
this.FirmwareRevision =
|
|
297
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
221
|
+
this.accessory.context.FirmwareRevision = deviceStatus.body.version;
|
|
298
222
|
}
|
|
299
223
|
/**
|
|
300
224
|
* Asks the SwitchBot API for the latest device information
|
|
@@ -327,97 +251,34 @@ export class CeilingLight {
|
|
|
327
251
|
// Start to monitor advertisement packets
|
|
328
252
|
(async () => {
|
|
329
253
|
// Start to monitor advertisement packets
|
|
330
|
-
await switchbot.startScan({
|
|
331
|
-
id: this.device.bleMac,
|
|
332
|
-
});
|
|
254
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
333
255
|
// Set an event handler
|
|
334
256
|
switchbot.onadvertisement = (ad) => {
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
257
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
338
260
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
339
|
-
this.BLE_On = ad.serviceData.state;
|
|
340
|
-
//this.delay = ad.serviceData.delay;
|
|
341
|
-
//this.timer = ad.serviceData.timer;
|
|
342
|
-
//this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
343
|
-
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
344
|
-
//this.overload = ad.serviceData.overload;
|
|
345
|
-
//this.currentPower = ad.serviceData.currentPower;
|
|
346
261
|
}
|
|
347
262
|
else {
|
|
348
263
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
349
264
|
}
|
|
350
265
|
};
|
|
351
|
-
// Wait
|
|
266
|
+
// Wait 10 seconds
|
|
352
267
|
await switchbot.wait(this.scanDuration * 1000);
|
|
353
268
|
// Stop to monitor
|
|
354
269
|
await switchbot.stopScan();
|
|
355
270
|
// Update HomeKit
|
|
356
|
-
await this.BLEparseStatus();
|
|
271
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
357
272
|
await this.updateHomeKitCharacteristics();
|
|
358
273
|
})();
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
model: '',
|
|
363
|
-
id: this.device.bleMac,
|
|
364
|
-
})
|
|
365
|
-
.then(async () => {
|
|
366
|
-
// Set an event handler
|
|
367
|
-
switchbot.onadvertisement = async (ad: ad) => {
|
|
368
|
-
this.debugLog(
|
|
369
|
-
`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},` +
|
|
370
|
-
` BLE Address Found: ${ad.address}`,
|
|
371
|
-
);
|
|
372
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
373
|
-
this.BLE_On = ad.serviceData.state;
|
|
374
|
-
//this.delay = ad.serviceData.delay;
|
|
375
|
-
//this.timer = ad.serviceData.timer;
|
|
376
|
-
//this.syncUtcTime = ad.serviceData.syncUtcTime;
|
|
377
|
-
//this.wifiRssi = ad.serviceData.wifiRssi;
|
|
378
|
-
//this.overload = ad.serviceData.overload;
|
|
379
|
-
//this.currentPower = ad.serviceData.currentPower;
|
|
380
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
381
|
-
this.debugLog(
|
|
382
|
-
`${this.device.deviceType}: ${this.accessory.displayName} state: ${ad.serviceData.state}, ` +
|
|
383
|
-
`delay: ${ad.serviceData.delay}, timer: ${ad.serviceData.timer}, syncUtcTime: ${ad.serviceData.syncUtcTime} ` +
|
|
384
|
-
`wifiRssi: ${ad.serviceData.wifiRssi}, overload: ${ad.serviceData.overload}, currentPower: ${ad.serviceData.currentPower}`,
|
|
385
|
-
);
|
|
386
|
-
|
|
387
|
-
if (ad.serviceData) {
|
|
388
|
-
this.BLE_IsConnected = true;
|
|
389
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
390
|
-
await this.stopScanning(switchbot);
|
|
391
|
-
} else {
|
|
392
|
-
this.BLE_IsConnected = false;
|
|
393
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.BLE_IsConnected}`);
|
|
394
|
-
}
|
|
395
|
-
};
|
|
396
|
-
// Wait
|
|
397
|
-
return await sleep(this.scanDuration * 1000);
|
|
398
|
-
})
|
|
399
|
-
.then(async () => {
|
|
400
|
-
// Stop to monitor
|
|
401
|
-
await this.stopScanning(switchbot);
|
|
402
|
-
})
|
|
403
|
-
.catch(async (e: any) => {
|
|
404
|
-
this.apiError(e);
|
|
405
|
-
this.errorLog(
|
|
406
|
-
`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}` +
|
|
407
|
-
` Connection, Error Message: ${JSON.stringify(e.message)}`,
|
|
408
|
-
);
|
|
409
|
-
await this.BLERefreshConnection(switchbot);
|
|
410
|
-
});
|
|
411
|
-
} else {
|
|
412
|
-
await this.BLERefreshConnection(switchbot);
|
|
413
|
-
}*/
|
|
274
|
+
if (switchbot === undefined) {
|
|
275
|
+
await this.BLERefreshConnection(switchbot);
|
|
276
|
+
}
|
|
414
277
|
}
|
|
415
278
|
async openAPIRefreshStatus() {
|
|
416
279
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
417
280
|
try {
|
|
418
|
-
const { body, statusCode } = await this.platform.retryRequest(this.
|
|
419
|
-
headers: this.platform.generateHeaders(),
|
|
420
|
-
});
|
|
281
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
421
282
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
422
283
|
const deviceStatus = await body.json();
|
|
423
284
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -425,12 +286,7 @@ export class CeilingLight {
|
|
|
425
286
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
426
287
|
this.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
427
288
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
428
|
-
this.
|
|
429
|
-
this.OpenAPI_RGB = deviceStatus.body.color;
|
|
430
|
-
this.OpenAPI_Brightness = deviceStatus.body.brightness;
|
|
431
|
-
this.OpenAPI_ColorTemperature = deviceStatus.body.colorTemperature;
|
|
432
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
433
|
-
this.openAPIparseStatus();
|
|
289
|
+
this.openAPIparseStatus(deviceStatus);
|
|
434
290
|
this.updateHomeKitCharacteristics();
|
|
435
291
|
}
|
|
436
292
|
else {
|
|
@@ -478,8 +334,9 @@ export class CeilingLight {
|
|
|
478
334
|
}
|
|
479
335
|
async BLEpushChanges() {
|
|
480
336
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEpushChanges`);
|
|
481
|
-
if (this.On !== this.accessory.context.On) {
|
|
482
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
337
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
338
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
339
|
+
+ ` BLEpushChanges On: ${this.LightBulb.On} OnCached: ${this.accessory.context.On}`);
|
|
483
340
|
const switchbot = await this.platform.connectBLE();
|
|
484
341
|
// Convert to BLE Address
|
|
485
342
|
this.device.bleMac = this.device
|
|
@@ -493,11 +350,11 @@ export class CeilingLight {
|
|
|
493
350
|
id: this.device.bleMac,
|
|
494
351
|
})
|
|
495
352
|
.then(async (device_list) => {
|
|
496
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
497
|
-
return await this.
|
|
498
|
-
max: this.
|
|
353
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
354
|
+
return await this.retryBLE({
|
|
355
|
+
max: await this.maxRetryBLE(),
|
|
499
356
|
fn: async () => {
|
|
500
|
-
if (this.On) {
|
|
357
|
+
if (this.LightBulb.On) {
|
|
501
358
|
return await device_list[0].turnOn({ id: this.device.bleMac });
|
|
502
359
|
}
|
|
503
360
|
else {
|
|
@@ -509,8 +366,8 @@ export class CeilingLight {
|
|
|
509
366
|
.then(() => {
|
|
510
367
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
511
368
|
this.successLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
512
|
-
+ `On: ${this.On} sent over BLE, sent successfully`);
|
|
513
|
-
this.On = false;
|
|
369
|
+
+ `On: ${this.LightBulb.On} sent over BLE, sent successfully`);
|
|
370
|
+
this.LightBulb.On = false;
|
|
514
371
|
})
|
|
515
372
|
.catch(async (e) => {
|
|
516
373
|
this.apiError(e);
|
|
@@ -520,14 +377,15 @@ export class CeilingLight {
|
|
|
520
377
|
});
|
|
521
378
|
}
|
|
522
379
|
else {
|
|
523
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
380
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
381
|
+
+ ` No BLEpushChanges: On: ${this.LightBulb.On}, ` + `OnCached: ${this.accessory.context.On}`);
|
|
524
382
|
}
|
|
525
383
|
}
|
|
526
384
|
async openAPIpushChanges() {
|
|
527
385
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIpushChanges`);
|
|
528
|
-
if (this.On !== this.accessory.context.On) {
|
|
386
|
+
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
529
387
|
let command = '';
|
|
530
|
-
if (this.On) {
|
|
388
|
+
if (this.LightBulb.On) {
|
|
531
389
|
command = 'turnOn';
|
|
532
390
|
}
|
|
533
391
|
else {
|
|
@@ -569,28 +427,28 @@ export class CeilingLight {
|
|
|
569
427
|
}
|
|
570
428
|
else {
|
|
571
429
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No openAPIpushChanges.` +
|
|
572
|
-
`On: ${this.On}, ` +
|
|
430
|
+
`On: ${this.LightBulb.On}, ` +
|
|
573
431
|
`OnCached: ${this.accessory.context.On}`);
|
|
574
432
|
}
|
|
575
433
|
// Push Hue & Saturation Update
|
|
576
|
-
if (this.On) {
|
|
434
|
+
if (this.LightBulb.On) {
|
|
577
435
|
await this.pushHueSaturationChanges();
|
|
578
436
|
}
|
|
579
437
|
// Push ColorTemperature Update
|
|
580
|
-
if (this.On) {
|
|
438
|
+
if (this.LightBulb.On) {
|
|
581
439
|
await this.pushColorTemperatureChanges();
|
|
582
440
|
}
|
|
583
441
|
// Push Brightness Update
|
|
584
|
-
if (this.On) {
|
|
442
|
+
if (this.LightBulb.On) {
|
|
585
443
|
await this.pushBrightnessChanges();
|
|
586
444
|
}
|
|
587
445
|
}
|
|
588
446
|
async pushHueSaturationChanges() {
|
|
589
447
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushHueSaturationChanges`);
|
|
590
|
-
if (this.Hue !== this.accessory.context.Hue || this.Saturation !== this.accessory.context.Saturation) {
|
|
591
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
592
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
593
|
-
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
448
|
+
if (this.LightBulb.Hue !== this.accessory.context.Hue || this.LightBulb.Saturation !== this.accessory.context.Saturation) {
|
|
449
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.LightBulb.Hue)}`);
|
|
450
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`);
|
|
451
|
+
const [red, green, blue] = hs2rgb(Number(this.LightBulb.Hue), Number(this.LightBulb.Saturation));
|
|
594
452
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
595
453
|
const bodyChange = JSON.stringify({
|
|
596
454
|
command: 'setColor',
|
|
@@ -627,15 +485,15 @@ export class CeilingLight {
|
|
|
627
485
|
}
|
|
628
486
|
}
|
|
629
487
|
else {
|
|
630
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.Hue}, ` +
|
|
631
|
-
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
488
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushHueSaturationChanges. Hue: ${this.LightBulb.Hue}, ` +
|
|
489
|
+
`HueCached: ${this.accessory.context.Hue}, Saturation: ${this.LightBulb.Saturation}, SaturationCached: ${this.accessory.context.Saturation}`);
|
|
632
490
|
}
|
|
633
491
|
}
|
|
634
492
|
async pushColorTemperatureChanges() {
|
|
635
493
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushColorTemperatureChanges`);
|
|
636
|
-
if (this.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
637
|
-
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
638
|
-
this.
|
|
494
|
+
if (this.LightBulb.ColorTemperature !== this.accessory.context.ColorTemperature) {
|
|
495
|
+
const kelvin = Math.round(1000000 / Number(this.LightBulb.ColorTemperature));
|
|
496
|
+
this.accessory.context.kelvin = kelvin;
|
|
639
497
|
const bodyChange = JSON.stringify({
|
|
640
498
|
command: 'setColorTemperature',
|
|
641
499
|
parameter: `${kelvin}`,
|
|
@@ -670,15 +528,15 @@ export class CeilingLight {
|
|
|
670
528
|
}
|
|
671
529
|
else {
|
|
672
530
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushColorTemperatureChanges.` +
|
|
673
|
-
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
531
|
+
`ColorTemperature: ${this.LightBulb.ColorTemperature}, ColorTemperatureCached: ${this.accessory.context.ColorTemperature}`);
|
|
674
532
|
}
|
|
675
533
|
}
|
|
676
534
|
async pushBrightnessChanges() {
|
|
677
535
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushBrightnessChanges`);
|
|
678
|
-
if (this.Brightness !== this.accessory.context.Brightness) {
|
|
536
|
+
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
679
537
|
const bodyChange = JSON.stringify({
|
|
680
538
|
command: 'setBrightness',
|
|
681
|
-
parameter: `${this.Brightness}`,
|
|
539
|
+
parameter: `${this.LightBulb.Brightness}`,
|
|
682
540
|
commandType: 'command',
|
|
683
541
|
});
|
|
684
542
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API, body: ${bodyChange},`);
|
|
@@ -712,7 +570,7 @@ export class CeilingLight {
|
|
|
712
570
|
}
|
|
713
571
|
else {
|
|
714
572
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No pushBrightnessChanges.` +
|
|
715
|
-
`Brightness: ${this.Brightness}, ` +
|
|
573
|
+
`Brightness: ${this.LightBulb.Brightness}, ` +
|
|
716
574
|
`BrightnessCached: ${this.accessory.context.Brightness}`);
|
|
717
575
|
}
|
|
718
576
|
}
|
|
@@ -720,132 +578,135 @@ export class CeilingLight {
|
|
|
720
578
|
* Handle requests to set the value of the "On" characteristic
|
|
721
579
|
*/
|
|
722
580
|
async OnSet(value) {
|
|
723
|
-
if (this.On === this.accessory.context.On) {
|
|
581
|
+
if (this.LightBulb.On === this.accessory.context.On) {
|
|
724
582
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set On: ${value}`);
|
|
725
583
|
}
|
|
726
584
|
else {
|
|
727
585
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set On: ${value}`);
|
|
728
586
|
}
|
|
729
|
-
this.On = value;
|
|
587
|
+
this.LightBulb.On = value;
|
|
730
588
|
this.doCeilingLightUpdate.next();
|
|
731
589
|
}
|
|
732
590
|
/**
|
|
733
591
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
734
592
|
*/
|
|
735
593
|
async BrightnessSet(value) {
|
|
736
|
-
if (this.Brightness === this.accessory.context.Brightness) {
|
|
594
|
+
if (this.LightBulb.Brightness === this.accessory.context.Brightness) {
|
|
737
595
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Brightness: ${value}`);
|
|
738
596
|
}
|
|
739
|
-
else if (this.On) {
|
|
597
|
+
else if (this.LightBulb.On) {
|
|
740
598
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
741
599
|
}
|
|
742
600
|
else {
|
|
743
601
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Brightness: ${value}`);
|
|
744
602
|
}
|
|
745
|
-
this.Brightness = value;
|
|
603
|
+
this.LightBulb.Brightness = value;
|
|
746
604
|
this.doCeilingLightUpdate.next();
|
|
747
605
|
}
|
|
748
606
|
/**
|
|
749
607
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
750
608
|
*/
|
|
751
609
|
async ColorTemperatureSet(value) {
|
|
752
|
-
if (this.ColorTemperature === this.accessory.context.ColorTemperature) {
|
|
610
|
+
if (this.LightBulb.ColorTemperature === this.accessory.context.ColorTemperature) {
|
|
753
611
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set ColorTemperature: ${value}`);
|
|
754
612
|
}
|
|
755
|
-
else if (this.On) {
|
|
613
|
+
else if (this.LightBulb.On) {
|
|
756
614
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
757
615
|
}
|
|
758
616
|
else {
|
|
759
617
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set ColorTemperature: ${value}`);
|
|
760
618
|
}
|
|
619
|
+
const minKelvin = 2000;
|
|
620
|
+
const maxKelvin = 9000;
|
|
761
621
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
762
622
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
763
623
|
// Check and increase/decrease kelvin to range of device
|
|
764
|
-
const k = Math.min(Math.max(kelvin,
|
|
765
|
-
if (!this.accessory.context.On || this.
|
|
624
|
+
const k = Math.min(Math.max(kelvin, minKelvin), maxKelvin);
|
|
625
|
+
if (!this.accessory.context.On || this.accessory.context.kelvin === k) {
|
|
766
626
|
return;
|
|
767
627
|
}
|
|
768
628
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
769
629
|
const hs = m2hs(value);
|
|
770
|
-
this.
|
|
771
|
-
this.
|
|
772
|
-
this.ColorTemperature = value;
|
|
630
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, hs[0]);
|
|
631
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, hs[1]);
|
|
632
|
+
this.LightBulb.ColorTemperature = value;
|
|
773
633
|
this.doCeilingLightUpdate.next();
|
|
774
634
|
}
|
|
775
635
|
/**
|
|
776
636
|
* Handle requests to set the value of the "Hue" characteristic
|
|
777
637
|
*/
|
|
778
638
|
async HueSet(value) {
|
|
779
|
-
if (this.Hue === this.accessory.context.Hue) {
|
|
639
|
+
if (this.LightBulb.Hue === this.accessory.context.Hue) {
|
|
780
640
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Hue: ${value}`);
|
|
781
641
|
}
|
|
782
|
-
else if (this.On) {
|
|
642
|
+
else if (this.LightBulb.On) {
|
|
783
643
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
784
644
|
}
|
|
785
645
|
else {
|
|
786
646
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Hue: ${value}`);
|
|
787
647
|
}
|
|
788
|
-
this.
|
|
789
|
-
this.Hue = value;
|
|
648
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
649
|
+
this.LightBulb.Hue = value;
|
|
790
650
|
this.doCeilingLightUpdate.next();
|
|
791
651
|
}
|
|
792
652
|
/**
|
|
793
653
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
794
654
|
*/
|
|
795
655
|
async SaturationSet(value) {
|
|
796
|
-
if (this.Saturation === this.accessory.context.Saturation) {
|
|
656
|
+
if (this.LightBulb.Saturation === this.accessory.context.Saturation) {
|
|
797
657
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes, Set Saturation: ${value}`);
|
|
798
658
|
}
|
|
799
|
-
else if (this.On) {
|
|
659
|
+
else if (this.LightBulb.On) {
|
|
800
660
|
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
801
661
|
}
|
|
802
662
|
else {
|
|
803
663
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Set Saturation: ${value}`);
|
|
804
664
|
}
|
|
805
|
-
this.
|
|
806
|
-
this.Saturation = value;
|
|
665
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, 140);
|
|
666
|
+
this.LightBulb.Saturation = value;
|
|
807
667
|
this.doCeilingLightUpdate.next();
|
|
808
668
|
}
|
|
809
669
|
async updateHomeKitCharacteristics() {
|
|
810
|
-
if (this.On === undefined) {
|
|
811
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
670
|
+
if (this.LightBulb.On === undefined) {
|
|
671
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LightBulb.On}`);
|
|
812
672
|
}
|
|
813
673
|
else {
|
|
814
|
-
this.accessory.context.On = this.On;
|
|
815
|
-
this.
|
|
816
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
674
|
+
this.accessory.context.On = this.LightBulb.On;
|
|
675
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, this.LightBulb.On);
|
|
676
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.LightBulb.On}`);
|
|
817
677
|
}
|
|
818
|
-
if (this.Brightness === undefined) {
|
|
819
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
678
|
+
if (this.LightBulb.Brightness === undefined) {
|
|
679
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.LightBulb.Brightness}`);
|
|
820
680
|
}
|
|
821
681
|
else {
|
|
822
|
-
this.accessory.context.Brightness = this.Brightness;
|
|
823
|
-
this.
|
|
824
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
682
|
+
this.accessory.context.Brightness = this.LightBulb.Brightness;
|
|
683
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, this.LightBulb.Brightness);
|
|
684
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.LightBulb.Brightness}`);
|
|
825
685
|
}
|
|
826
|
-
if (this.ColorTemperature === undefined) {
|
|
827
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
686
|
+
if (this.LightBulb.ColorTemperature === undefined) {
|
|
687
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
828
688
|
}
|
|
829
689
|
else {
|
|
830
|
-
this.accessory.context.ColorTemperature = this.ColorTemperature;
|
|
831
|
-
this.
|
|
832
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}
|
|
690
|
+
this.accessory.context.ColorTemperature = this.LightBulb.ColorTemperature;
|
|
691
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, this.LightBulb.ColorTemperature);
|
|
692
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
693
|
+
+ ` updateCharacteristic ColorTemperature: ${this.LightBulb.ColorTemperature}`);
|
|
833
694
|
}
|
|
834
|
-
if (this.Hue === undefined) {
|
|
835
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
695
|
+
if (this.LightBulb.Hue === undefined) {
|
|
696
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.LightBulb.Hue}`);
|
|
836
697
|
}
|
|
837
698
|
else {
|
|
838
|
-
this.accessory.context.Hue = this.Hue;
|
|
839
|
-
this.
|
|
840
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
699
|
+
this.accessory.context.Hue = this.LightBulb.Hue;
|
|
700
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, this.LightBulb.Hue);
|
|
701
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.LightBulb.Hue}`);
|
|
841
702
|
}
|
|
842
|
-
if (this.Saturation === undefined) {
|
|
843
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
703
|
+
if (this.LightBulb.Saturation === undefined) {
|
|
704
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.LightBulb.Saturation}`);
|
|
844
705
|
}
|
|
845
706
|
else {
|
|
846
|
-
this.accessory.context.Saturation = this.Saturation;
|
|
847
|
-
this.
|
|
848
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
707
|
+
this.accessory.context.Saturation = this.LightBulb.Saturation;
|
|
708
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, this.LightBulb.Saturation);
|
|
709
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.LightBulb.Saturation}`);
|
|
849
710
|
}
|
|
850
711
|
}
|
|
851
712
|
async adaptiveLighting(device) {
|
|
@@ -858,34 +719,6 @@ export class CeilingLight {
|
|
|
858
719
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
859
720
|
}
|
|
860
721
|
}
|
|
861
|
-
async stopScanning(switchbot) {
|
|
862
|
-
switchbot.stopScan();
|
|
863
|
-
if (this.BLE_IsConnected) {
|
|
864
|
-
await this.BLEparseStatus();
|
|
865
|
-
await this.updateHomeKitCharacteristics();
|
|
866
|
-
}
|
|
867
|
-
else {
|
|
868
|
-
await this.BLERefreshConnection(switchbot);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
async getCustomBLEAddress(switchbot) {
|
|
872
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
873
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} customBLEaddress: ${this.device.customBLEaddress}`);
|
|
874
|
-
(async () => {
|
|
875
|
-
// Start to monitor advertisement packets
|
|
876
|
-
await switchbot.startScan({
|
|
877
|
-
model: 'u',
|
|
878
|
-
});
|
|
879
|
-
// Set an event handler
|
|
880
|
-
switchbot.onadvertisement = (ad) => {
|
|
881
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
882
|
-
};
|
|
883
|
-
await sleep(10000);
|
|
884
|
-
// Stop to monitor
|
|
885
|
-
switchbot.stopScan();
|
|
886
|
-
})();
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
722
|
async BLEPushConnection() {
|
|
890
723
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
891
724
|
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Push Changes`);
|
|
@@ -900,298 +733,27 @@ export class CeilingLight {
|
|
|
900
733
|
await this.openAPIRefreshStatus();
|
|
901
734
|
}
|
|
902
735
|
}
|
|
903
|
-
async retry({ max, fn }) {
|
|
904
|
-
return fn().catch(async (e) => {
|
|
905
|
-
if (max === 0) {
|
|
906
|
-
throw e;
|
|
907
|
-
}
|
|
908
|
-
this.infoLog(e);
|
|
909
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Retrying`);
|
|
910
|
-
await sleep(1000);
|
|
911
|
-
return this.retry({ max: max - 1, fn });
|
|
912
|
-
});
|
|
913
|
-
}
|
|
914
|
-
maxRetry() {
|
|
915
|
-
if (this.device.maxRetry) {
|
|
916
|
-
return this.device.maxRetry;
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
919
|
-
return 5;
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
736
|
minStep(device) {
|
|
737
|
+
let set_minStep;
|
|
923
738
|
if (device.ceilinglight?.set_minStep) {
|
|
924
|
-
|
|
739
|
+
set_minStep = device.ceilinglight?.set_minStep;
|
|
925
740
|
}
|
|
926
741
|
else {
|
|
927
|
-
|
|
928
|
-
}
|
|
929
|
-
return this.set_minStep;
|
|
930
|
-
}
|
|
931
|
-
async scan(device) {
|
|
932
|
-
if (device.scanDuration) {
|
|
933
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
934
|
-
if (this.BLE) {
|
|
935
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
else {
|
|
939
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
940
|
-
if (this.BLE) {
|
|
941
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
942
|
-
}
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
async statusCode(statusCode) {
|
|
946
|
-
switch (statusCode) {
|
|
947
|
-
case 151:
|
|
948
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
949
|
-
break;
|
|
950
|
-
case 152:
|
|
951
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
952
|
-
break;
|
|
953
|
-
case 160:
|
|
954
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
955
|
-
break;
|
|
956
|
-
case 161:
|
|
957
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
958
|
-
this.offlineOff();
|
|
959
|
-
break;
|
|
960
|
-
case 171:
|
|
961
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
962
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
963
|
-
this.offlineOff();
|
|
964
|
-
break;
|
|
965
|
-
case 190:
|
|
966
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
967
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
968
|
-
break;
|
|
969
|
-
case 100:
|
|
970
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
971
|
-
break;
|
|
972
|
-
case 200:
|
|
973
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
974
|
-
break;
|
|
975
|
-
case 400:
|
|
976
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
977
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
978
|
-
break;
|
|
979
|
-
case 401:
|
|
980
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
981
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
982
|
-
break;
|
|
983
|
-
case 403:
|
|
984
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
985
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
986
|
-
break;
|
|
987
|
-
case 404:
|
|
988
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
989
|
-
+ `statusCode: ${statusCode}`);
|
|
990
|
-
break;
|
|
991
|
-
case 406:
|
|
992
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
993
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
994
|
-
break;
|
|
995
|
-
case 415:
|
|
996
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
997
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
998
|
-
break;
|
|
999
|
-
case 422:
|
|
1000
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
1001
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
1002
|
-
break;
|
|
1003
|
-
case 429:
|
|
1004
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
1005
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
1006
|
-
break;
|
|
1007
|
-
case 500:
|
|
1008
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
1009
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
1010
|
-
break;
|
|
1011
|
-
default:
|
|
1012
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
1013
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
742
|
+
set_minStep = 1;
|
|
1014
743
|
}
|
|
744
|
+
return set_minStep;
|
|
1015
745
|
}
|
|
1016
746
|
async offlineOff() {
|
|
1017
747
|
if (this.device.offline) {
|
|
1018
|
-
|
|
1019
|
-
await this.updateHomeKitCharacteristics();
|
|
748
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, false);
|
|
1020
749
|
}
|
|
1021
750
|
}
|
|
1022
751
|
apiError(e) {
|
|
1023
|
-
this.
|
|
1024
|
-
this.
|
|
1025
|
-
this.
|
|
1026
|
-
this.
|
|
1027
|
-
this.
|
|
1028
|
-
}
|
|
1029
|
-
async deviceContext() {
|
|
1030
|
-
if (this.On === undefined) {
|
|
1031
|
-
this.On = false;
|
|
1032
|
-
}
|
|
1033
|
-
else {
|
|
1034
|
-
this.On = this.accessory.context.On;
|
|
1035
|
-
}
|
|
1036
|
-
if (this.Hue === undefined) {
|
|
1037
|
-
this.Hue = 0;
|
|
1038
|
-
}
|
|
1039
|
-
else {
|
|
1040
|
-
this.Hue = this.accessory.context.Hue;
|
|
1041
|
-
}
|
|
1042
|
-
if (this.Brightness === undefined) {
|
|
1043
|
-
this.Brightness = 0;
|
|
1044
|
-
}
|
|
1045
|
-
else {
|
|
1046
|
-
this.Brightness = this.accessory.context.Brightness;
|
|
1047
|
-
}
|
|
1048
|
-
if (this.Brightness === undefined) {
|
|
1049
|
-
this.Saturation = 0;
|
|
1050
|
-
}
|
|
1051
|
-
else {
|
|
1052
|
-
this.Saturation = this.accessory.context.Saturation;
|
|
1053
|
-
}
|
|
1054
|
-
if (this.ColorTemperature === undefined) {
|
|
1055
|
-
this.ColorTemperature = 140;
|
|
1056
|
-
}
|
|
1057
|
-
else {
|
|
1058
|
-
this.ColorTemperature = this.accessory.context.ColorTemperature;
|
|
1059
|
-
}
|
|
1060
|
-
this.minKelvin = 2000;
|
|
1061
|
-
this.maxKelvin = 9000;
|
|
1062
|
-
if (this.FirmwareRevision === undefined) {
|
|
1063
|
-
this.FirmwareRevision = this.platform.version;
|
|
1064
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
async refreshRate(device) {
|
|
1068
|
-
if (device.refreshRate) {
|
|
1069
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
1070
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1071
|
-
}
|
|
1072
|
-
else if (this.platform.config.options.refreshRate) {
|
|
1073
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
1074
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
async deviceRetry(device) {
|
|
1078
|
-
if (!device.maxRetries) {
|
|
1079
|
-
this.maxRetries = 5; // Maximum number of retries
|
|
1080
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Max Retries Not Set, Using: ${this.maxRetries}`);
|
|
1081
|
-
}
|
|
1082
|
-
else {
|
|
1083
|
-
this.maxRetries = device.maxRetries;
|
|
1084
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Max Retries: ${this.maxRetries}`);
|
|
1085
|
-
}
|
|
1086
|
-
if (!device.delayBetweenRetries) {
|
|
1087
|
-
this.delayBetweenRetries = 3000; // Delay between retries in milliseconds
|
|
1088
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Delay Between Retries Not Set, Using: ${this.delayBetweenRetries}`);
|
|
1089
|
-
}
|
|
1090
|
-
else {
|
|
1091
|
-
this.delayBetweenRetries = device.delayBetweenRetries * 1000;
|
|
1092
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Delay Between Retries: ${this.delayBetweenRetries}`);
|
|
1093
|
-
}
|
|
1094
|
-
}
|
|
1095
|
-
async deviceConfig(device) {
|
|
1096
|
-
let config = {};
|
|
1097
|
-
if (device.ceilinglight) {
|
|
1098
|
-
config = device.ceilinglight;
|
|
1099
|
-
}
|
|
1100
|
-
if (device.connectionType !== undefined) {
|
|
1101
|
-
config['connectionType'] = device.connectionType;
|
|
1102
|
-
}
|
|
1103
|
-
if (device.external !== undefined) {
|
|
1104
|
-
config['external'] = device.external;
|
|
1105
|
-
}
|
|
1106
|
-
if (device.logging !== undefined) {
|
|
1107
|
-
config['logging'] = device.logging;
|
|
1108
|
-
}
|
|
1109
|
-
if (device.refreshRate !== undefined) {
|
|
1110
|
-
config['refreshRate'] = device.refreshRate;
|
|
1111
|
-
}
|
|
1112
|
-
if (device.scanDuration !== undefined) {
|
|
1113
|
-
config['scanDuration'] = device.scanDuration;
|
|
1114
|
-
}
|
|
1115
|
-
if (device.offline !== undefined) {
|
|
1116
|
-
config['offline'] = device.offline;
|
|
1117
|
-
}
|
|
1118
|
-
if (device.maxRetry !== undefined) {
|
|
1119
|
-
config['maxRetry'] = device.maxRetry;
|
|
1120
|
-
}
|
|
1121
|
-
if (device.webhook !== undefined) {
|
|
1122
|
-
config['webhook'] = device.webhook;
|
|
1123
|
-
}
|
|
1124
|
-
if (Object.entries(config).length !== 0) {
|
|
1125
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
async deviceLogs(device) {
|
|
1129
|
-
if (this.platform.debugMode) {
|
|
1130
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
1131
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
1132
|
-
}
|
|
1133
|
-
else if (device.logging) {
|
|
1134
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
1135
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
1136
|
-
}
|
|
1137
|
-
else if (this.platform.config.options?.logging) {
|
|
1138
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
1139
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
1140
|
-
}
|
|
1141
|
-
else {
|
|
1142
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
1143
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
/**
|
|
1147
|
-
* Logging for Device
|
|
1148
|
-
*/
|
|
1149
|
-
successLog(...log) {
|
|
1150
|
-
if (this.enablingDeviceLogging()) {
|
|
1151
|
-
this.platform.log.success(String(...log));
|
|
1152
|
-
}
|
|
1153
|
-
}
|
|
1154
|
-
infoLog(...log) {
|
|
1155
|
-
if (this.enablingDeviceLogging()) {
|
|
1156
|
-
this.platform.log.info(String(...log));
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
warnLog(...log) {
|
|
1160
|
-
if (this.enablingDeviceLogging()) {
|
|
1161
|
-
this.platform.log.warn(String(...log));
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
debugWarnLog(...log) {
|
|
1165
|
-
if (this.enablingDeviceLogging()) {
|
|
1166
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1167
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
}
|
|
1171
|
-
errorLog(...log) {
|
|
1172
|
-
if (this.enablingDeviceLogging()) {
|
|
1173
|
-
this.platform.log.error(String(...log));
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
debugErrorLog(...log) {
|
|
1177
|
-
if (this.enablingDeviceLogging()) {
|
|
1178
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
1179
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
}
|
|
1183
|
-
debugLog(...log) {
|
|
1184
|
-
if (this.enablingDeviceLogging()) {
|
|
1185
|
-
if (this.deviceLogging === 'debug') {
|
|
1186
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
1187
|
-
}
|
|
1188
|
-
else {
|
|
1189
|
-
this.platform.log.debug(String(...log));
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
|
-
enablingDeviceLogging() {
|
|
1194
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
752
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.On, e);
|
|
753
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Hue, e);
|
|
754
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Brightness, e);
|
|
755
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.Saturation, e);
|
|
756
|
+
this.LightBulb.Service.updateCharacteristic(this.hap.Characteristic.ColorTemperature, e);
|
|
1195
757
|
}
|
|
1196
758
|
}
|
|
1197
759
|
//# sourceMappingURL=ceilinglight.js.map
|