@switchbot/homebridge-switchbot 1.8.3-beta.0 → 1.10.1-beta.0
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/.eslintrc +14 -45
- package/.github/ISSUE_TEMPLATE/bug-report.yml +3 -3
- package/.github/ISSUE_TEMPLATE/feature-request.yml +2 -2
- package/.github/ISSUE_TEMPLATE/support-request.yml +3 -3
- package/.github/labeler.yml +1 -1
- package/.github/workflows/codeql-analysis.yml +29 -29
- package/.github/workflows/nodejs-beta.yml +1 -1
- package/.github/workflows/prerelease-beta.js +1 -1
- package/.github/workflows/stale.yml +1 -1
- package/.prettierrc +9 -0
- package/.vscode/extensions.json +2 -4
- package/.vscode/settings.json +14 -2
- package/CHANGELOG.md +16 -0
- package/README.md +100 -99
- package/SECURITY.md +2 -2
- package/config.schema.json +17 -0
- package/dist/devices/bots.d.ts +35 -32
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +168 -210
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +35 -35
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +83 -108
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +27 -25
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +110 -131
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +29 -27
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +147 -182
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +31 -31
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +154 -181
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +29 -28
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +98 -120
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +24 -23
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +97 -113
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +16 -16
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +48 -71
- package/dist/devices/plugs.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -22
- package/dist/index.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +7 -4
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +72 -93
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +3 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +32 -51
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +3 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +19 -26
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +3 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +35 -44
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +3 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +25 -32
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +3 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +21 -29
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +3 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +66 -89
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +3 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +18 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +3 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +19 -26
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +163 -233
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +3 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +4 -4
- package/dist/settings.js.map +1 -1
- package/homebridge-ui/public/index.html +231 -245
- package/homebridge-ui/server.js +2 -4
- package/nodemon.json +2 -4
- package/package.json +17 -12
- package/src/devices/bots.ts +411 -854
- package/src/devices/colorbulb.ts +187 -408
- package/src/devices/contact.ts +210 -376
- package/src/devices/curtains.ts +288 -563
- package/src/devices/humidifiers.ts +291 -537
- package/src/devices/meters.ts +189 -331
- package/src/devices/motion.ts +188 -322
- package/src/devices/plugs.ts +88 -160
- package/src/index.ts +5 -5
- package/src/irdevices/airconditioners.ts +139 -318
- package/src/irdevices/airpurifiers.ts +71 -170
- package/src/irdevices/cameras.ts +44 -103
- package/src/irdevices/fans.ts +70 -165
- package/src/irdevices/lights.ts +49 -104
- package/src/irdevices/others.ts +55 -131
- package/src/irdevices/tvs.ts +114 -247
- package/src/irdevices/vacuumcleaners.ts +44 -104
- package/src/irdevices/waterheaters.ts +49 -121
- package/src/platform.ts +341 -753
- package/src/settings.ts +8 -11
- package/tsconfig.json +5 -14
- package/.github/PULL_REQUEST_TEMPLATE/pull_requests.md +0 -27
package/src/devices/colorbulb.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { interval, Subject } from 'rxjs';
|
|
3
|
+
import { SwitchBotPlatform } from '../platform';
|
|
4
|
+
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
5
|
+
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
6
|
+
import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, m2hs, deviceStatus } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Platform Accessory
|
|
@@ -12,29 +12,29 @@ import * as settings from "../settings";
|
|
|
12
12
|
*/
|
|
13
13
|
export class ColorBulb {
|
|
14
14
|
// Services
|
|
15
|
-
service!:
|
|
15
|
+
service!: Service;
|
|
16
16
|
|
|
17
17
|
// Characteristic Values
|
|
18
|
-
On!:
|
|
19
|
-
OnCached!:
|
|
20
|
-
Hue!:
|
|
21
|
-
HueCached!:
|
|
22
|
-
Saturation!:
|
|
23
|
-
SaturationCached!:
|
|
24
|
-
Brightness!:
|
|
25
|
-
BrightnessCached!:
|
|
26
|
-
ColorTemperature!:
|
|
27
|
-
ColorTemperatureCached!:
|
|
18
|
+
On!: CharacteristicValue;
|
|
19
|
+
OnCached!: CharacteristicValue;
|
|
20
|
+
Hue!: CharacteristicValue;
|
|
21
|
+
HueCached!: CharacteristicValue;
|
|
22
|
+
Saturation!: CharacteristicValue;
|
|
23
|
+
SaturationCached!: CharacteristicValue;
|
|
24
|
+
Brightness!: CharacteristicValue;
|
|
25
|
+
BrightnessCached!: CharacteristicValue;
|
|
26
|
+
ColorTemperature!: CharacteristicValue;
|
|
27
|
+
ColorTemperatureCached!: CharacteristicValue;
|
|
28
28
|
|
|
29
29
|
// OpenAPI Others
|
|
30
|
-
power:
|
|
31
|
-
color:
|
|
32
|
-
brightness:
|
|
33
|
-
colorTemperature:
|
|
34
|
-
deviceStatus!:
|
|
30
|
+
power: deviceStatus['power'];
|
|
31
|
+
color: deviceStatus['color'];
|
|
32
|
+
brightness: deviceStatus['brightness'];
|
|
33
|
+
colorTemperature: deviceStatus['colorTemperature'];
|
|
34
|
+
deviceStatus!: deviceStatusResponse;
|
|
35
35
|
|
|
36
36
|
// BLE Others
|
|
37
|
-
switchbot!:
|
|
37
|
+
switchbot!: switchbot;
|
|
38
38
|
|
|
39
39
|
// Config
|
|
40
40
|
set_minStep?: number;
|
|
@@ -43,23 +43,16 @@ export class ColorBulb {
|
|
|
43
43
|
adaptiveLightingShift?: number;
|
|
44
44
|
|
|
45
45
|
// Adaptive Lighting
|
|
46
|
-
AdaptiveLightingController?:
|
|
47
|
-
| homebridge.ControllerConstructor
|
|
48
|
-
| homebridge.Controller<homebridge.ControllerServiceMap>;
|
|
49
|
-
|
|
46
|
+
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
50
47
|
minKelvin: number;
|
|
51
48
|
maxKelvin: number;
|
|
52
49
|
|
|
53
50
|
// Updates
|
|
54
51
|
colorBulbUpdateInProgress!: boolean;
|
|
55
|
-
doColorBulbUpdate!:
|
|
52
|
+
doColorBulbUpdate!: Subject<void>;
|
|
56
53
|
cacheKelvin!: number;
|
|
57
54
|
|
|
58
|
-
constructor(
|
|
59
|
-
private readonly platform: platform.SwitchBotPlatform,
|
|
60
|
-
private accessory: homebridge.PlatformAccessory,
|
|
61
|
-
public device: settings.device & settings.devicesConfig,
|
|
62
|
-
) {
|
|
55
|
+
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
63
56
|
// default placeholders
|
|
64
57
|
this.logs(device);
|
|
65
58
|
this.refreshRate(device);
|
|
@@ -77,7 +70,7 @@ export class ColorBulb {
|
|
|
77
70
|
this.minKelvin = 2000;
|
|
78
71
|
this.maxKelvin = 9000;
|
|
79
72
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
80
|
-
this.doColorBulbUpdate = new
|
|
73
|
+
this.doColorBulbUpdate = new Subject();
|
|
81
74
|
this.colorBulbUpdateInProgress = false;
|
|
82
75
|
|
|
83
76
|
// Retrieve initial values and updateHomekit
|
|
@@ -86,33 +79,20 @@ export class ColorBulb {
|
|
|
86
79
|
// set accessory information
|
|
87
80
|
accessory
|
|
88
81
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
89
|
-
.setCharacteristic(this.platform.Characteristic.Manufacturer,
|
|
90
|
-
.setCharacteristic(
|
|
91
|
-
|
|
92
|
-
"SWITCHBOT-COLORBULB-W1401400",
|
|
93
|
-
)
|
|
94
|
-
.setCharacteristic(
|
|
95
|
-
this.platform.Characteristic.SerialNumber,
|
|
96
|
-
device.deviceId!,
|
|
97
|
-
);
|
|
82
|
+
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
83
|
+
.setCharacteristic(this.platform.Characteristic.Model, 'SWITCHBOT-COLORBULB-W1401400')
|
|
84
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
98
85
|
|
|
99
86
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
100
87
|
// you can create multiple services for each accessory
|
|
101
|
-
(this.service =
|
|
102
|
-
accessory.getService(this.platform.Service.Lightbulb) ||
|
|
103
|
-
accessory.addService(this.platform.Service.Lightbulb)),
|
|
88
|
+
(this.service = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
104
89
|
`${accessory.displayName} Light Bulb`;
|
|
105
90
|
|
|
106
|
-
if (
|
|
107
|
-
this.adaptiveLightingShift === -1 &&
|
|
108
|
-
this.accessory.context.adaptiveLighting
|
|
109
|
-
) {
|
|
91
|
+
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
110
92
|
this.accessory.removeService(this.service);
|
|
111
93
|
this.service = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
112
94
|
this.accessory.context.adaptiveLighting = false;
|
|
113
|
-
this.debugLog(
|
|
114
|
-
`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`,
|
|
115
|
-
);
|
|
95
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
116
96
|
}
|
|
117
97
|
|
|
118
98
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -121,15 +101,10 @@ export class ColorBulb {
|
|
|
121
101
|
|
|
122
102
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
123
103
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
124
|
-
this.service.setCharacteristic(
|
|
125
|
-
this.platform.Characteristic.Name,
|
|
126
|
-
accessory.displayName,
|
|
127
|
-
);
|
|
104
|
+
this.service.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
128
105
|
|
|
129
106
|
// handle on / off events using the On characteristic
|
|
130
|
-
this.service
|
|
131
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
132
|
-
.onSet(this.OnSet.bind(this));
|
|
107
|
+
this.service.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
133
108
|
|
|
134
109
|
// handle Brightness events using the Brightness characteristic
|
|
135
110
|
this.service
|
|
@@ -184,14 +159,11 @@ export class ColorBulb {
|
|
|
184
159
|
})
|
|
185
160
|
.onSet(this.SaturationSet.bind(this));
|
|
186
161
|
|
|
187
|
-
this.debugLog(
|
|
188
|
-
`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
189
|
-
);
|
|
162
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
190
163
|
if (this.adaptiveLightingShift !== -1) {
|
|
191
|
-
this.AdaptiveLightingController =
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
164
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.service, {
|
|
165
|
+
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
166
|
+
});
|
|
195
167
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
196
168
|
this.accessory.context.adaptiveLighting = true;
|
|
197
169
|
this.debugLog(
|
|
@@ -204,9 +176,8 @@ export class ColorBulb {
|
|
|
204
176
|
this.updateHomeKitCharacteristics();
|
|
205
177
|
|
|
206
178
|
// Start an update interval
|
|
207
|
-
|
|
208
|
-
.
|
|
209
|
-
.pipe(operators.skipWhile(() => this.colorBulbUpdateInProgress))
|
|
179
|
+
interval(this.deviceRefreshRate * 1000)
|
|
180
|
+
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
210
181
|
.subscribe(() => {
|
|
211
182
|
this.refreshStatus();
|
|
212
183
|
});
|
|
@@ -215,23 +186,21 @@ export class ColorBulb {
|
|
|
215
186
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
216
187
|
this.doColorBulbUpdate
|
|
217
188
|
.pipe(
|
|
218
|
-
|
|
189
|
+
tap(() => {
|
|
219
190
|
this.colorBulbUpdateInProgress = true;
|
|
220
191
|
}),
|
|
221
|
-
|
|
192
|
+
debounceTime(this.platform.config.options!.pushRate! * 1000),
|
|
222
193
|
)
|
|
223
194
|
.subscribe(async () => {
|
|
224
195
|
try {
|
|
225
196
|
await this.pushChanges();
|
|
226
197
|
} catch (e: any) {
|
|
227
|
-
this.errorLog(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
234
|
-
);
|
|
198
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges`);
|
|
199
|
+
if (this.deviceLogging === 'debug') {
|
|
200
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
201
|
+
}
|
|
202
|
+
if (this.platform.debugMode) {
|
|
203
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
235
204
|
}
|
|
236
205
|
this.apiError(e);
|
|
237
206
|
}
|
|
@@ -241,7 +210,7 @@ export class ColorBulb {
|
|
|
241
210
|
|
|
242
211
|
parseStatus() {
|
|
243
212
|
switch (this.power) {
|
|
244
|
-
case
|
|
213
|
+
case 'on':
|
|
245
214
|
this.On = true;
|
|
246
215
|
break;
|
|
247
216
|
default:
|
|
@@ -251,87 +220,44 @@ export class ColorBulb {
|
|
|
251
220
|
|
|
252
221
|
// Brightness
|
|
253
222
|
this.Brightness = Number(this.brightness);
|
|
254
|
-
this.debugLog(
|
|
255
|
-
`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`,
|
|
256
|
-
);
|
|
223
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
257
224
|
|
|
258
225
|
// Color, Hue & Brightness
|
|
259
226
|
if (this.color) {
|
|
260
|
-
this.debugLog(
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
);
|
|
265
|
-
const [red, green, blue] = this.color!.split(":");
|
|
266
|
-
this.debugLog(
|
|
267
|
-
`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`,
|
|
268
|
-
);
|
|
269
|
-
this.debugLog(
|
|
270
|
-
`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(
|
|
271
|
-
green,
|
|
272
|
-
)}`,
|
|
273
|
-
);
|
|
274
|
-
this.debugLog(
|
|
275
|
-
`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(
|
|
276
|
-
blue,
|
|
277
|
-
)}`,
|
|
278
|
-
);
|
|
227
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
228
|
+
const [red, green, blue] = this.color!.split(':');
|
|
229
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
230
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
231
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
279
232
|
|
|
280
|
-
const [hue, saturation] =
|
|
281
|
-
|
|
282
|
-
Number(green),
|
|
283
|
-
Number(blue),
|
|
284
|
-
);
|
|
285
|
-
this.debugLog(
|
|
286
|
-
`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(
|
|
287
|
-
settings.rgb2hs(Number(red), Number(green), Number(blue)),
|
|
288
|
-
)}`,
|
|
289
|
-
);
|
|
233
|
+
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
234
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
290
235
|
|
|
291
236
|
// Hue
|
|
292
237
|
this.Hue = hue;
|
|
293
|
-
this.debugLog(
|
|
294
|
-
`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`,
|
|
295
|
-
);
|
|
238
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
296
239
|
|
|
297
240
|
// Saturation
|
|
298
241
|
this.Saturation = saturation;
|
|
299
|
-
this.debugLog(
|
|
300
|
-
`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`,
|
|
301
|
-
);
|
|
242
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
302
243
|
}
|
|
303
244
|
|
|
304
245
|
// ColorTemperature
|
|
305
246
|
if (!Number.isNaN(this.colorTemperature)) {
|
|
306
|
-
this.debugLog(
|
|
307
|
-
`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`,
|
|
308
|
-
);
|
|
247
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
309
248
|
const mired = Math.round(1000000 / this.colorTemperature!);
|
|
310
249
|
|
|
311
250
|
this.ColorTemperature = Number(mired);
|
|
312
251
|
|
|
313
|
-
this.ColorTemperature = Math.max(
|
|
314
|
-
|
|
315
|
-
140,
|
|
316
|
-
);
|
|
317
|
-
this.debugLog(
|
|
318
|
-
`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`,
|
|
319
|
-
);
|
|
252
|
+
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
253
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
320
254
|
}
|
|
321
255
|
}
|
|
322
256
|
|
|
323
257
|
async refreshStatus() {
|
|
324
258
|
try {
|
|
325
|
-
this.deviceStatus = (
|
|
326
|
-
|
|
327
|
-
`${settings.DeviceURL}/${this.device.deviceId}/status`,
|
|
328
|
-
)
|
|
329
|
-
).data;
|
|
330
|
-
this.debugLog(
|
|
331
|
-
`Color Bulb: ${
|
|
332
|
-
this.accessory.displayName
|
|
333
|
-
} refreshStatus: ${JSON.stringify(this.deviceStatus)}`,
|
|
334
|
-
);
|
|
259
|
+
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
260
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
335
261
|
this.power = this.deviceStatus.body.power;
|
|
336
262
|
this.color = this.deviceStatus.body.color;
|
|
337
263
|
this.brightness = this.deviceStatus.body.brightness;
|
|
@@ -339,15 +265,15 @@ export class ColorBulb {
|
|
|
339
265
|
this.parseStatus();
|
|
340
266
|
this.updateHomeKitCharacteristics();
|
|
341
267
|
} catch (e: any) {
|
|
342
|
-
this.errorLog(
|
|
343
|
-
|
|
344
|
-
);
|
|
345
|
-
if (this.deviceLogging.includes("debug")) {
|
|
268
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
269
|
+
if (this.deviceLogging === 'debug') {
|
|
346
270
|
this.errorLog(
|
|
347
|
-
`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
348
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
271
|
+
`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
349
272
|
);
|
|
350
273
|
}
|
|
274
|
+
if (this.platform.debugMode) {
|
|
275
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
276
|
+
}
|
|
351
277
|
this.apiError(e);
|
|
352
278
|
}
|
|
353
279
|
}
|
|
@@ -367,14 +293,14 @@ export class ColorBulb {
|
|
|
367
293
|
if (this.On !== this.OnCached) {
|
|
368
294
|
// Push On Update
|
|
369
295
|
const payload = {
|
|
370
|
-
commandType:
|
|
371
|
-
parameter:
|
|
372
|
-
} as
|
|
296
|
+
commandType: 'command',
|
|
297
|
+
parameter: 'default',
|
|
298
|
+
} as payload;
|
|
373
299
|
|
|
374
300
|
if (this.On) {
|
|
375
|
-
payload.command =
|
|
301
|
+
payload.command = 'turnOn';
|
|
376
302
|
} else {
|
|
377
|
-
payload.command =
|
|
303
|
+
payload.command = 'turnOff';
|
|
378
304
|
}
|
|
379
305
|
|
|
380
306
|
this.infoLog(
|
|
@@ -383,15 +309,8 @@ export class ColorBulb {
|
|
|
383
309
|
);
|
|
384
310
|
|
|
385
311
|
// Make the API request
|
|
386
|
-
const push: any = await this.platform.axios.post(
|
|
387
|
-
|
|
388
|
-
payload,
|
|
389
|
-
);
|
|
390
|
-
this.debugLog(
|
|
391
|
-
`Color Bulb: ${
|
|
392
|
-
this.accessory.displayName
|
|
393
|
-
} pushChanges: ${JSON.stringify(push.data)}`,
|
|
394
|
-
);
|
|
312
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
313
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
395
314
|
this.statusCode(push);
|
|
396
315
|
this.OnCached = this.On;
|
|
397
316
|
this.accessory.context.On = this.OnCached;
|
|
@@ -411,53 +330,33 @@ export class ColorBulb {
|
|
|
411
330
|
await this.pushHueSaturationChanges();
|
|
412
331
|
}
|
|
413
332
|
} catch (e: any) {
|
|
414
|
-
this.errorLog(
|
|
415
|
-
|
|
416
|
-
);
|
|
417
|
-
if (this.deviceLogging.includes("debug")) {
|
|
333
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
334
|
+
if (this.deviceLogging === 'debug') {
|
|
418
335
|
this.errorLog(
|
|
419
|
-
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
420
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
336
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
421
337
|
);
|
|
422
338
|
}
|
|
339
|
+
if (this.platform.debugMode) {
|
|
340
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
341
|
+
}
|
|
423
342
|
this.apiError(e);
|
|
424
343
|
}
|
|
425
344
|
}
|
|
426
345
|
|
|
427
346
|
private async pushHueSaturationChanges() {
|
|
428
347
|
try {
|
|
429
|
-
if (
|
|
430
|
-
this.
|
|
431
|
-
this.
|
|
432
|
-
) {
|
|
433
|
-
this.debugLog(
|
|
434
|
-
`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(
|
|
435
|
-
this.Hue,
|
|
436
|
-
)}`,
|
|
437
|
-
);
|
|
438
|
-
this.debugLog(
|
|
439
|
-
`Color Bulb: ${
|
|
440
|
-
this.accessory.displayName
|
|
441
|
-
} Saturation: ${JSON.stringify(this.Saturation)}`,
|
|
442
|
-
);
|
|
348
|
+
if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
|
|
349
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
350
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
443
351
|
|
|
444
|
-
const [red, green, blue] =
|
|
445
|
-
|
|
446
|
-
Number(this.Saturation),
|
|
447
|
-
);
|
|
448
|
-
this.debugLog(
|
|
449
|
-
`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([
|
|
450
|
-
red,
|
|
451
|
-
green,
|
|
452
|
-
blue,
|
|
453
|
-
])}`,
|
|
454
|
-
);
|
|
352
|
+
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
353
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
455
354
|
|
|
456
355
|
const payload = {
|
|
457
|
-
commandType:
|
|
458
|
-
command:
|
|
356
|
+
commandType: 'command',
|
|
357
|
+
command: 'setColor',
|
|
459
358
|
parameter: `${red}:${green}:${blue}`,
|
|
460
|
-
} as
|
|
359
|
+
} as payload;
|
|
461
360
|
|
|
462
361
|
this.infoLog(
|
|
463
362
|
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -465,15 +364,8 @@ export class ColorBulb {
|
|
|
465
364
|
);
|
|
466
365
|
|
|
467
366
|
// Make the API request
|
|
468
|
-
const push: any = await this.platform.axios.post(
|
|
469
|
-
|
|
470
|
-
payload,
|
|
471
|
-
);
|
|
472
|
-
this.debugLog(
|
|
473
|
-
`Color Bulb: ${
|
|
474
|
-
this.accessory.displayName
|
|
475
|
-
} pushChanges: ${JSON.stringify(push.data)}`,
|
|
476
|
-
);
|
|
367
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
368
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
477
369
|
this.statusCode(push);
|
|
478
370
|
this.HueCached = this.Hue;
|
|
479
371
|
this.SaturationCached = this.Saturation;
|
|
@@ -484,15 +376,15 @@ export class ColorBulb {
|
|
|
484
376
|
);
|
|
485
377
|
}
|
|
486
378
|
} catch (e: any) {
|
|
487
|
-
this.errorLog(
|
|
488
|
-
|
|
489
|
-
);
|
|
490
|
-
if (this.deviceLogging.includes("debug")) {
|
|
379
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
380
|
+
if (this.deviceLogging === 'debug') {
|
|
491
381
|
this.errorLog(
|
|
492
|
-
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
493
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
382
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
494
383
|
);
|
|
495
384
|
}
|
|
385
|
+
if (this.platform.debugMode) {
|
|
386
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
387
|
+
}
|
|
496
388
|
this.apiError(e);
|
|
497
389
|
}
|
|
498
390
|
}
|
|
@@ -504,10 +396,10 @@ export class ColorBulb {
|
|
|
504
396
|
this.cacheKelvin = kelvin;
|
|
505
397
|
|
|
506
398
|
const payload = {
|
|
507
|
-
commandType:
|
|
508
|
-
command:
|
|
399
|
+
commandType: 'command',
|
|
400
|
+
command: 'setColorTemperature',
|
|
509
401
|
parameter: `${kelvin}`,
|
|
510
|
-
} as
|
|
402
|
+
} as payload;
|
|
511
403
|
|
|
512
404
|
this.infoLog(
|
|
513
405
|
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -515,15 +407,8 @@ export class ColorBulb {
|
|
|
515
407
|
);
|
|
516
408
|
|
|
517
409
|
// Make the API request
|
|
518
|
-
const push: any = await this.platform.axios.post(
|
|
519
|
-
|
|
520
|
-
payload,
|
|
521
|
-
);
|
|
522
|
-
this.debugLog(
|
|
523
|
-
`Color Bulb: ${
|
|
524
|
-
this.accessory.displayName
|
|
525
|
-
} pushChanges: ${JSON.stringify(push.data)}`,
|
|
526
|
-
);
|
|
410
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
411
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
527
412
|
this.statusCode(push);
|
|
528
413
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
529
414
|
} else {
|
|
@@ -533,15 +418,15 @@ export class ColorBulb {
|
|
|
533
418
|
);
|
|
534
419
|
}
|
|
535
420
|
} catch (e: any) {
|
|
536
|
-
this.errorLog(
|
|
537
|
-
|
|
538
|
-
);
|
|
539
|
-
if (this.deviceLogging.includes("debug")) {
|
|
421
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
422
|
+
if (this.deviceLogging === 'debug') {
|
|
540
423
|
this.errorLog(
|
|
541
|
-
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
542
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
424
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
543
425
|
);
|
|
544
426
|
}
|
|
427
|
+
if (this.platform.debugMode) {
|
|
428
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
429
|
+
}
|
|
545
430
|
this.apiError(e);
|
|
546
431
|
}
|
|
547
432
|
}
|
|
@@ -550,10 +435,10 @@ export class ColorBulb {
|
|
|
550
435
|
try {
|
|
551
436
|
if (this.Brightness !== this.BrightnessCached) {
|
|
552
437
|
const payload = {
|
|
553
|
-
commandType:
|
|
554
|
-
command:
|
|
438
|
+
commandType: 'command',
|
|
439
|
+
command: 'setBrightness',
|
|
555
440
|
parameter: `${this.Brightness}`,
|
|
556
|
-
} as
|
|
441
|
+
} as payload;
|
|
557
442
|
|
|
558
443
|
this.infoLog(
|
|
559
444
|
`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
@@ -561,33 +446,25 @@ export class ColorBulb {
|
|
|
561
446
|
);
|
|
562
447
|
|
|
563
448
|
// Make the API request
|
|
564
|
-
const push: any = await this.platform.axios.post(
|
|
565
|
-
|
|
566
|
-
payload,
|
|
567
|
-
);
|
|
568
|
-
this.debugLog(
|
|
569
|
-
`Color Bulb: ${
|
|
570
|
-
this.accessory.displayName
|
|
571
|
-
} pushChanges: ${JSON.stringify(push.data)}`,
|
|
572
|
-
);
|
|
449
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
450
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
573
451
|
this.statusCode(push);
|
|
574
452
|
this.BrightnessCached = this.Brightness;
|
|
575
453
|
} else {
|
|
576
454
|
this.debugLog(
|
|
577
|
-
`Color Bulb: ${this.accessory.displayName} No Changes.` +
|
|
578
|
-
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
455
|
+
`Color Bulb: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
579
456
|
);
|
|
580
457
|
}
|
|
581
458
|
} catch (e: any) {
|
|
582
|
-
this.errorLog(
|
|
583
|
-
|
|
584
|
-
);
|
|
585
|
-
if (this.deviceLogging.includes("debug")) {
|
|
459
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
460
|
+
if (this.deviceLogging === 'debug') {
|
|
586
461
|
this.errorLog(
|
|
587
|
-
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
588
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
462
|
+
`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
589
463
|
);
|
|
590
464
|
}
|
|
465
|
+
if (this.platform.debugMode) {
|
|
466
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
467
|
+
}
|
|
591
468
|
this.apiError(e);
|
|
592
469
|
}
|
|
593
470
|
}
|
|
@@ -596,113 +473,61 @@ export class ColorBulb {
|
|
|
596
473
|
if (this.On === undefined) {
|
|
597
474
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
598
475
|
} else {
|
|
599
|
-
this.service.updateCharacteristic(
|
|
600
|
-
|
|
601
|
-
this.On,
|
|
602
|
-
);
|
|
603
|
-
this.debugLog(
|
|
604
|
-
`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`,
|
|
605
|
-
);
|
|
476
|
+
this.service.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
477
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
606
478
|
}
|
|
607
479
|
if (this.Brightness === undefined) {
|
|
608
|
-
this.debugLog(
|
|
609
|
-
`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`,
|
|
610
|
-
);
|
|
480
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
611
481
|
} else {
|
|
612
|
-
this.service.updateCharacteristic(
|
|
613
|
-
|
|
614
|
-
this.Brightness,
|
|
615
|
-
);
|
|
616
|
-
this.debugLog(
|
|
617
|
-
`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`,
|
|
618
|
-
);
|
|
482
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
483
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
619
484
|
}
|
|
620
485
|
if (this.ColorTemperature === undefined) {
|
|
621
|
-
this.debugLog(
|
|
622
|
-
`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`,
|
|
623
|
-
);
|
|
486
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
624
487
|
} else {
|
|
625
|
-
this.service.updateCharacteristic(
|
|
626
|
-
|
|
627
|
-
this.ColorTemperature,
|
|
628
|
-
);
|
|
629
|
-
this.debugLog(
|
|
630
|
-
`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`,
|
|
631
|
-
);
|
|
488
|
+
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
489
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
632
490
|
}
|
|
633
491
|
if (this.Hue === undefined) {
|
|
634
|
-
this.debugLog(
|
|
635
|
-
`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`,
|
|
636
|
-
);
|
|
492
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
637
493
|
} else {
|
|
638
|
-
this.service.updateCharacteristic(
|
|
639
|
-
|
|
640
|
-
this.Hue,
|
|
641
|
-
);
|
|
642
|
-
this.debugLog(
|
|
643
|
-
`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`,
|
|
644
|
-
);
|
|
494
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
495
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
645
496
|
}
|
|
646
497
|
if (this.Saturation === undefined) {
|
|
647
|
-
this.debugLog(
|
|
648
|
-
`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`,
|
|
649
|
-
);
|
|
498
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
650
499
|
} else {
|
|
651
|
-
this.service.updateCharacteristic(
|
|
652
|
-
|
|
653
|
-
this.Saturation,
|
|
654
|
-
);
|
|
655
|
-
this.debugLog(
|
|
656
|
-
`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`,
|
|
657
|
-
);
|
|
500
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
501
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
658
502
|
}
|
|
659
503
|
}
|
|
660
504
|
|
|
661
505
|
public apiError(e: any) {
|
|
662
506
|
this.service.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
663
507
|
this.service.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
664
|
-
this.service.updateCharacteristic(
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
);
|
|
668
|
-
this.service.updateCharacteristic(
|
|
669
|
-
this.platform.Characteristic.Saturation,
|
|
670
|
-
e,
|
|
671
|
-
);
|
|
672
|
-
this.service.updateCharacteristic(
|
|
673
|
-
this.platform.Characteristic.ColorTemperature,
|
|
674
|
-
e,
|
|
675
|
-
);
|
|
508
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
509
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
510
|
+
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
|
|
676
511
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
677
512
|
}
|
|
678
513
|
|
|
679
|
-
private statusCode(push:
|
|
514
|
+
private statusCode(push: AxiosResponse<{ statusCode: number }>) {
|
|
680
515
|
switch (push.data.statusCode) {
|
|
681
516
|
case 151:
|
|
682
|
-
this.errorLog(
|
|
683
|
-
`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`,
|
|
684
|
-
);
|
|
517
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
685
518
|
break;
|
|
686
519
|
case 152:
|
|
687
|
-
this.errorLog(
|
|
688
|
-
`Color Bulb: ${this.accessory.displayName} Device not found.`,
|
|
689
|
-
);
|
|
520
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device not found.`);
|
|
690
521
|
break;
|
|
691
522
|
case 160:
|
|
692
|
-
this.errorLog(
|
|
693
|
-
`Color Bulb: ${this.accessory.displayName} Command is not supported.`,
|
|
694
|
-
);
|
|
523
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Command is not supported.`);
|
|
695
524
|
break;
|
|
696
525
|
case 161:
|
|
697
|
-
this.errorLog(
|
|
698
|
-
`Color Bulb: ${this.accessory.displayName} Device is offline.`,
|
|
699
|
-
);
|
|
526
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} Device is offline.`);
|
|
700
527
|
this.offlineOff();
|
|
701
528
|
break;
|
|
702
529
|
case 171:
|
|
703
|
-
this.errorLog(
|
|
704
|
-
`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`,
|
|
705
|
-
);
|
|
530
|
+
this.errorLog(`Color Bulb: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
706
531
|
this.offlineOff();
|
|
707
532
|
break;
|
|
708
533
|
case 190:
|
|
@@ -713,16 +538,12 @@ export class ColorBulb {
|
|
|
713
538
|
break;
|
|
714
539
|
case 100:
|
|
715
540
|
if (this.platform.debugMode) {
|
|
716
|
-
this.debugLog(
|
|
717
|
-
`Color Bulb: ${this.accessory.displayName} Command successfully sent.`,
|
|
718
|
-
);
|
|
541
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Command successfully sent.`);
|
|
719
542
|
}
|
|
720
543
|
break;
|
|
721
544
|
default:
|
|
722
545
|
if (this.platform.debugMode) {
|
|
723
|
-
this.debugLog(
|
|
724
|
-
`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`,
|
|
725
|
-
);
|
|
546
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Unknown statusCode.`);
|
|
726
547
|
}
|
|
727
548
|
}
|
|
728
549
|
}
|
|
@@ -730,16 +551,14 @@ export class ColorBulb {
|
|
|
730
551
|
private offlineOff() {
|
|
731
552
|
if (this.device.offline) {
|
|
732
553
|
this.On = false;
|
|
733
|
-
this.service
|
|
734
|
-
.getCharacteristic(this.platform.Characteristic.On)
|
|
735
|
-
.updateValue(this.On);
|
|
554
|
+
this.service.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
736
555
|
}
|
|
737
556
|
}
|
|
738
557
|
|
|
739
558
|
/**
|
|
740
559
|
* Handle requests to set the value of the "On" characteristic
|
|
741
560
|
*/
|
|
742
|
-
OnSet(value:
|
|
561
|
+
OnSet(value: CharacteristicValue) {
|
|
743
562
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} On: ${value}`);
|
|
744
563
|
|
|
745
564
|
this.On = value;
|
|
@@ -749,10 +568,8 @@ export class ColorBulb {
|
|
|
749
568
|
/**
|
|
750
569
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
751
570
|
*/
|
|
752
|
-
BrightnessSet(value:
|
|
753
|
-
this.debugLog(
|
|
754
|
-
`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`,
|
|
755
|
-
);
|
|
571
|
+
BrightnessSet(value: CharacteristicValue) {
|
|
572
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Brightness: ${value}`);
|
|
756
573
|
|
|
757
574
|
this.Brightness = value;
|
|
758
575
|
this.doColorBulbUpdate.next();
|
|
@@ -761,10 +578,8 @@ export class ColorBulb {
|
|
|
761
578
|
/**
|
|
762
579
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
763
580
|
*/
|
|
764
|
-
ColorTemperatureSet(value:
|
|
765
|
-
this.debugLog(
|
|
766
|
-
`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`,
|
|
767
|
-
);
|
|
581
|
+
ColorTemperatureSet(value: CharacteristicValue) {
|
|
582
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
768
583
|
|
|
769
584
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
770
585
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -777,12 +592,9 @@ export class ColorBulb {
|
|
|
777
592
|
}
|
|
778
593
|
|
|
779
594
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
780
|
-
const hs =
|
|
595
|
+
const hs = m2hs(value);
|
|
781
596
|
this.service.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
782
|
-
this.service.updateCharacteristic(
|
|
783
|
-
this.platform.Characteristic.Saturation,
|
|
784
|
-
hs[1],
|
|
785
|
-
);
|
|
597
|
+
this.service.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
786
598
|
|
|
787
599
|
this.ColorTemperature = value;
|
|
788
600
|
this.doColorBulbUpdate.next();
|
|
@@ -791,13 +603,10 @@ export class ColorBulb {
|
|
|
791
603
|
/**
|
|
792
604
|
* Handle requests to set the value of the "Hue" characteristic
|
|
793
605
|
*/
|
|
794
|
-
HueSet(value:
|
|
606
|
+
HueSet(value: CharacteristicValue) {
|
|
795
607
|
this.debugLog(`Color Bulb: ${this.accessory.displayName} Hue: ${value}`);
|
|
796
608
|
|
|
797
|
-
this.service.updateCharacteristic(
|
|
798
|
-
this.platform.Characteristic.ColorTemperature,
|
|
799
|
-
140,
|
|
800
|
-
);
|
|
609
|
+
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
801
610
|
|
|
802
611
|
this.Hue = value;
|
|
803
612
|
this.doColorBulbUpdate.next();
|
|
@@ -806,102 +615,74 @@ export class ColorBulb {
|
|
|
806
615
|
/**
|
|
807
616
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
808
617
|
*/
|
|
809
|
-
SaturationSet(value:
|
|
810
|
-
this.debugLog(
|
|
811
|
-
`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`,
|
|
812
|
-
);
|
|
618
|
+
SaturationSet(value: CharacteristicValue) {
|
|
619
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Saturation: ${value}`);
|
|
813
620
|
|
|
814
|
-
this.service.updateCharacteristic(
|
|
815
|
-
this.platform.Characteristic.ColorTemperature,
|
|
816
|
-
140,
|
|
817
|
-
);
|
|
621
|
+
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
818
622
|
|
|
819
623
|
this.Saturation = value;
|
|
820
624
|
this.doColorBulbUpdate.next();
|
|
821
625
|
}
|
|
822
626
|
|
|
823
|
-
config(device:
|
|
627
|
+
config(device: device & devicesConfig) {
|
|
824
628
|
let config = {};
|
|
825
629
|
if (device.colorbulb) {
|
|
826
630
|
config = device.colorbulb;
|
|
827
631
|
}
|
|
828
632
|
if (device.ble) {
|
|
829
|
-
config[
|
|
633
|
+
config['ble'] = device.ble;
|
|
830
634
|
}
|
|
831
635
|
if (device.logging !== undefined) {
|
|
832
|
-
config[
|
|
636
|
+
config['logging'] = device.logging;
|
|
833
637
|
}
|
|
834
638
|
if (device.refreshRate !== undefined) {
|
|
835
|
-
config[
|
|
639
|
+
config['refreshRate'] = device.refreshRate;
|
|
836
640
|
}
|
|
837
641
|
if (device.scanDuration !== undefined) {
|
|
838
|
-
config[
|
|
642
|
+
config['scanDuration'] = device.scanDuration;
|
|
839
643
|
}
|
|
840
644
|
if (Object.entries(config).length !== 0) {
|
|
841
|
-
this.warnLog(
|
|
842
|
-
`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(
|
|
843
|
-
config,
|
|
844
|
-
)}`,
|
|
845
|
-
);
|
|
645
|
+
this.warnLog(`Color Bulb: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
846
646
|
}
|
|
847
647
|
}
|
|
848
648
|
|
|
849
|
-
refreshRate(device:
|
|
649
|
+
refreshRate(device: device & devicesConfig) {
|
|
850
650
|
if (device.refreshRate) {
|
|
851
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
852
|
-
|
|
853
|
-
this.debugLog(
|
|
854
|
-
`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`,
|
|
855
|
-
);
|
|
651
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
652
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
856
653
|
} else if (this.platform.config.options!.refreshRate) {
|
|
857
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate =
|
|
858
|
-
|
|
859
|
-
this.debugLog(
|
|
860
|
-
`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`,
|
|
861
|
-
);
|
|
654
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
655
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
862
656
|
}
|
|
863
657
|
}
|
|
864
658
|
|
|
865
|
-
logs(device:
|
|
659
|
+
logs(device: device & devicesConfig) {
|
|
866
660
|
if (this.platform.debugMode) {
|
|
867
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
868
|
-
this.debugLog(
|
|
869
|
-
`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`,
|
|
870
|
-
);
|
|
661
|
+
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
662
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
871
663
|
} else if (device.logging) {
|
|
872
664
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
873
|
-
this.debugLog(
|
|
874
|
-
`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`,
|
|
875
|
-
);
|
|
665
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
876
666
|
} else if (this.platform.config.options?.logging) {
|
|
877
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
878
|
-
|
|
879
|
-
this.debugLog(
|
|
880
|
-
`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`,
|
|
881
|
-
);
|
|
667
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
668
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
882
669
|
} else {
|
|
883
|
-
this.deviceLogging = this.accessory.context.logging =
|
|
884
|
-
this.debugLog(
|
|
885
|
-
`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`,
|
|
886
|
-
);
|
|
670
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
671
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
887
672
|
}
|
|
888
673
|
}
|
|
889
674
|
|
|
890
|
-
adaptiveLighting(device:
|
|
675
|
+
adaptiveLighting(device: device & devicesConfig) {
|
|
891
676
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
892
677
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
893
|
-
this.debugLog(
|
|
894
|
-
`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
895
|
-
);
|
|
678
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
896
679
|
} else {
|
|
897
680
|
this.adaptiveLightingShift = 0;
|
|
898
|
-
this.debugLog(
|
|
899
|
-
`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
900
|
-
);
|
|
681
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
901
682
|
}
|
|
902
683
|
}
|
|
903
684
|
|
|
904
|
-
minStep(device:
|
|
685
|
+
minStep(device: device & devicesConfig): number {
|
|
905
686
|
if (device.colorbulb?.set_minStep) {
|
|
906
687
|
this.set_minStep = device.colorbulb?.set_minStep;
|
|
907
688
|
} else {
|
|
@@ -933,8 +714,8 @@ export class ColorBulb {
|
|
|
933
714
|
|
|
934
715
|
debugLog(...log: any[]) {
|
|
935
716
|
if (this.enablingDeviceLogging()) {
|
|
936
|
-
if (this.deviceLogging ===
|
|
937
|
-
this.platform.log.info(
|
|
717
|
+
if (this.deviceLogging === 'debug') {
|
|
718
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
938
719
|
} else {
|
|
939
720
|
this.platform.log.debug(String(...log));
|
|
940
721
|
}
|
|
@@ -942,8 +723,6 @@ export class ColorBulb {
|
|
|
942
723
|
}
|
|
943
724
|
|
|
944
725
|
enablingDeviceLogging(): boolean {
|
|
945
|
-
return
|
|
946
|
-
this.deviceLogging.includes("debug") || this.deviceLogging === "standard"
|
|
947
|
-
);
|
|
726
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
948
727
|
}
|
|
949
728
|
}
|