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