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