@switchbot/homebridge-switchbot 1.10.2-beta.7 → 1.11.2
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/CHANGELOG.md +20 -3
- package/config.schema.json +49 -0
- package/dist/device/bot.d.ts +43 -40
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +26 -26
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +25 -21
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +176 -140
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -15
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +14 -13
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +25 -22
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +50 -37
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +23 -20
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -38
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +16 -13
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +17 -17
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +15 -15
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +11 -11
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts +14 -14
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +13 -13
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +10 -7
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +19 -19
- package/dist/device/plug.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +22 -22
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +44 -44
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +12 -9
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +20 -20
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +10 -7
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +11 -11
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +12 -9
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +29 -29
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +10 -7
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +13 -13
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +12 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +17 -17
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +13 -10
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +25 -25
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +10 -7
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +13 -13
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +10 -7
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +16 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/settings.d.ts +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +76 -76
- package/src/device/bot.ts +50 -50
- package/src/device/colorbulb.ts +206 -157
- package/src/device/contact.ts +31 -30
- package/src/device/curtain.ts +68 -57
- package/src/device/humidifier.ts +65 -53
- package/src/device/lock.ts +25 -25
- package/src/device/meter.ts +25 -25
- package/src/device/motion.ts +27 -27
- package/src/device/plug.ts +22 -22
- package/src/irdevice/airconditioner.ts +54 -54
- package/src/irdevice/airpurifier.ts +30 -30
- package/src/irdevice/camera.ts +19 -19
- package/src/irdevice/fan.ts +40 -40
- package/src/irdevice/light.ts +23 -23
- package/src/irdevice/other.ts +25 -25
- package/src/irdevice/tv.ts +42 -42
- package/src/irdevice/vacuumcleaner.ts +21 -21
- package/src/irdevice/waterheater.ts +24 -24
- package/src/platform.ts +4 -4
- package/src/settings.ts +5 -1
package/src/device/colorbulb.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payl
|
|
|
12
12
|
*/
|
|
13
13
|
export class ColorBulb {
|
|
14
14
|
// Services
|
|
15
|
-
|
|
15
|
+
lightBulbService!: Service;
|
|
16
16
|
|
|
17
17
|
// Characteristic Values
|
|
18
18
|
On!: CharacteristicValue;
|
|
@@ -23,14 +23,14 @@ export class ColorBulb {
|
|
|
23
23
|
SaturationCached!: CharacteristicValue;
|
|
24
24
|
Brightness!: CharacteristicValue;
|
|
25
25
|
BrightnessCached!: CharacteristicValue;
|
|
26
|
-
ColorTemperature
|
|
27
|
-
ColorTemperatureCached
|
|
26
|
+
ColorTemperature?: CharacteristicValue;
|
|
27
|
+
ColorTemperatureCached?: CharacteristicValue;
|
|
28
28
|
|
|
29
29
|
// OpenAPI Others
|
|
30
30
|
power: deviceStatus['power'];
|
|
31
31
|
color: deviceStatus['color'];
|
|
32
32
|
brightness: deviceStatus['brightness'];
|
|
33
|
-
colorTemperature
|
|
33
|
+
colorTemperature?: deviceStatus['colorTemperature'];
|
|
34
34
|
deviceStatus!: deviceStatusResponse;
|
|
35
35
|
|
|
36
36
|
// BLE Others
|
|
@@ -44,13 +44,15 @@ export class ColorBulb {
|
|
|
44
44
|
|
|
45
45
|
// Adaptive Lighting
|
|
46
46
|
AdaptiveLightingController?: ControllerConstructor | Controller<ControllerServiceMap>;
|
|
47
|
-
minKelvin
|
|
48
|
-
maxKelvin
|
|
47
|
+
minKelvin!: number;
|
|
48
|
+
maxKelvin!: number;
|
|
49
|
+
|
|
50
|
+
// Others
|
|
51
|
+
cacheKelvin!: number;
|
|
49
52
|
|
|
50
53
|
// Updates
|
|
51
54
|
colorBulbUpdateInProgress!: boolean;
|
|
52
55
|
doColorBulbUpdate!: Subject<void>;
|
|
53
|
-
cacheKelvin!: number;
|
|
54
56
|
|
|
55
57
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
56
58
|
// default placeholders
|
|
@@ -66,7 +68,9 @@ export class ColorBulb {
|
|
|
66
68
|
this.Hue = 0;
|
|
67
69
|
this.Brightness = 0;
|
|
68
70
|
this.Saturation = 0;
|
|
69
|
-
|
|
71
|
+
if (device.deviceType === 'Color Bulb') {
|
|
72
|
+
this.ColorTemperature = 140;
|
|
73
|
+
}
|
|
70
74
|
this.minKelvin = 2000;
|
|
71
75
|
this.maxKelvin = 9000;
|
|
72
76
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
@@ -80,19 +84,19 @@ export class ColorBulb {
|
|
|
80
84
|
accessory
|
|
81
85
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
82
86
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
83
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
87
|
+
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
84
88
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!);
|
|
85
89
|
|
|
86
90
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
87
91
|
// you can create multiple services for each accessory
|
|
88
|
-
(this.
|
|
89
|
-
`${accessory.displayName}
|
|
92
|
+
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
93
|
+
`${accessory.displayName} ${device.deviceType}`;
|
|
90
94
|
|
|
91
95
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
92
|
-
this.accessory.removeService(this.
|
|
93
|
-
this.
|
|
96
|
+
this.accessory.removeService(this.lightBulbService);
|
|
97
|
+
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
94
98
|
this.accessory.context.adaptiveLighting = false;
|
|
95
|
-
this.debugLog(
|
|
99
|
+
this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
@@ -101,13 +105,13 @@ export class ColorBulb {
|
|
|
101
105
|
|
|
102
106
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
103
107
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
104
|
-
this.
|
|
108
|
+
this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
105
109
|
|
|
106
110
|
// handle on / off events using the On characteristic
|
|
107
|
-
this.
|
|
111
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
108
112
|
|
|
109
113
|
// handle Brightness events using the Brightness characteristic
|
|
110
|
-
this.
|
|
114
|
+
this.lightBulbService
|
|
111
115
|
.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
112
116
|
.setProps({
|
|
113
117
|
minStep: this.minStep(device),
|
|
@@ -121,20 +125,25 @@ export class ColorBulb {
|
|
|
121
125
|
.onSet(this.BrightnessSet.bind(this));
|
|
122
126
|
|
|
123
127
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
124
|
-
|
|
125
|
-
.
|
|
126
|
-
.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
128
|
+
if (device.deviceType === 'Color Bulb') {
|
|
129
|
+
this.debugLog(`Color Bulb: ${accessory.displayName} Add ColorTemperature Characteristic`);
|
|
130
|
+
this.lightBulbService
|
|
131
|
+
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
132
|
+
.setProps({
|
|
133
|
+
minValue: 140,
|
|
134
|
+
maxValue: 500,
|
|
135
|
+
validValueRanges: [140, 500],
|
|
136
|
+
})
|
|
137
|
+
.onGet(() => {
|
|
138
|
+
return this.ColorTemperature!;
|
|
139
|
+
})
|
|
140
|
+
.onSet(this.ColorTemperatureSet.bind(this));
|
|
141
|
+
} else {
|
|
142
|
+
this.debugLog(`Color Bulb: ${accessory.displayName} ColorTemperature Characteristic Not Added`);
|
|
143
|
+
}
|
|
135
144
|
|
|
136
145
|
// handle Hue events using the Hue characteristic
|
|
137
|
-
this.
|
|
146
|
+
this.lightBulbService
|
|
138
147
|
.getCharacteristic(this.platform.Characteristic.Hue)
|
|
139
148
|
.setProps({
|
|
140
149
|
minValue: 0,
|
|
@@ -147,7 +156,7 @@ export class ColorBulb {
|
|
|
147
156
|
.onSet(this.HueSet.bind(this));
|
|
148
157
|
|
|
149
158
|
// handle Hue events using the Hue characteristic
|
|
150
|
-
this.
|
|
159
|
+
this.lightBulbService
|
|
151
160
|
.getCharacteristic(this.platform.Characteristic.Saturation)
|
|
152
161
|
.setProps({
|
|
153
162
|
minValue: 0,
|
|
@@ -159,15 +168,15 @@ export class ColorBulb {
|
|
|
159
168
|
})
|
|
160
169
|
.onSet(this.SaturationSet.bind(this));
|
|
161
170
|
|
|
162
|
-
this.debugLog(
|
|
171
|
+
this.debugLog(`${device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
163
172
|
if (this.adaptiveLightingShift !== -1) {
|
|
164
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.
|
|
173
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
165
174
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
166
175
|
});
|
|
167
176
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
168
177
|
this.accessory.context.adaptiveLighting = true;
|
|
169
178
|
this.debugLog(
|
|
170
|
-
|
|
179
|
+
`${device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
171
180
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`,
|
|
172
181
|
);
|
|
173
182
|
}
|
|
@@ -178,8 +187,8 @@ export class ColorBulb {
|
|
|
178
187
|
// Start an update interval
|
|
179
188
|
interval(this.deviceRefreshRate * 1000)
|
|
180
189
|
.pipe(skipWhile(() => this.colorBulbUpdateInProgress))
|
|
181
|
-
.subscribe(() => {
|
|
182
|
-
this.refreshStatus();
|
|
190
|
+
.subscribe(async () => {
|
|
191
|
+
await this.refreshStatus();
|
|
183
192
|
});
|
|
184
193
|
|
|
185
194
|
// Watch for Bulb change events
|
|
@@ -195,12 +204,12 @@ export class ColorBulb {
|
|
|
195
204
|
try {
|
|
196
205
|
await this.pushChanges();
|
|
197
206
|
} catch (e: any) {
|
|
198
|
-
this.errorLog(
|
|
207
|
+
this.errorLog(`${device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
199
208
|
if (this.deviceLogging === 'debug') {
|
|
200
|
-
this.errorLog(
|
|
209
|
+
this.errorLog(`${device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
201
210
|
}
|
|
202
211
|
if (this.platform.debugMode) {
|
|
203
|
-
this.errorLog(
|
|
212
|
+
this.errorLog(`${device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
204
213
|
}
|
|
205
214
|
this.apiError(e);
|
|
206
215
|
}
|
|
@@ -208,7 +217,7 @@ export class ColorBulb {
|
|
|
208
217
|
});
|
|
209
218
|
}
|
|
210
219
|
|
|
211
|
-
parseStatus() {
|
|
220
|
+
async parseStatus(): Promise<void> {
|
|
212
221
|
switch (this.power) {
|
|
213
222
|
case 'on':
|
|
214
223
|
this.On = true;
|
|
@@ -216,63 +225,72 @@ export class ColorBulb {
|
|
|
216
225
|
default:
|
|
217
226
|
this.On = false;
|
|
218
227
|
}
|
|
219
|
-
this.debugLog(
|
|
228
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
220
229
|
|
|
221
230
|
// Brightness
|
|
222
231
|
this.Brightness = Number(this.brightness);
|
|
223
|
-
this.debugLog(
|
|
232
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
224
233
|
|
|
225
234
|
// Color, Hue & Brightness
|
|
226
235
|
if (this.color) {
|
|
227
|
-
this.debugLog(
|
|
236
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
228
237
|
const [red, green, blue] = this.color!.split(':');
|
|
229
|
-
this.debugLog(
|
|
230
|
-
this.debugLog(
|
|
231
|
-
this.debugLog(
|
|
238
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
239
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
240
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
232
241
|
|
|
233
242
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
234
|
-
this.debugLog(
|
|
243
|
+
this.debugLog(
|
|
244
|
+
`${this.device.deviceType}: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
245
|
+
);
|
|
235
246
|
|
|
236
247
|
// Hue
|
|
237
248
|
this.Hue = hue;
|
|
238
|
-
this.debugLog(
|
|
249
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
239
250
|
|
|
240
251
|
// Saturation
|
|
241
252
|
this.Saturation = saturation;
|
|
242
|
-
this.debugLog(
|
|
253
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
243
254
|
}
|
|
244
255
|
|
|
245
256
|
// ColorTemperature
|
|
246
|
-
if (
|
|
247
|
-
|
|
248
|
-
|
|
257
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
258
|
+
if (!Number.isNaN(this.colorTemperature)) {
|
|
259
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
260
|
+
const mired = Math.round(1000000 / this.colorTemperature!);
|
|
249
261
|
|
|
250
|
-
|
|
262
|
+
this.ColorTemperature = Number(mired);
|
|
251
263
|
|
|
252
|
-
|
|
253
|
-
|
|
264
|
+
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
266
|
+
}
|
|
254
267
|
}
|
|
255
268
|
}
|
|
256
269
|
|
|
257
|
-
async refreshStatus() {
|
|
270
|
+
async refreshStatus(): Promise<void> {
|
|
258
271
|
try {
|
|
259
272
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
260
|
-
this.debugLog(
|
|
273
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
261
274
|
this.power = this.deviceStatus.body.power;
|
|
262
275
|
this.color = this.deviceStatus.body.color;
|
|
263
276
|
this.brightness = this.deviceStatus.body.brightness;
|
|
264
|
-
this.
|
|
277
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
278
|
+
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
279
|
+
}
|
|
265
280
|
this.parseStatus();
|
|
266
281
|
this.updateHomeKitCharacteristics();
|
|
267
282
|
} catch (e: any) {
|
|
268
|
-
this.errorLog(
|
|
283
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
269
284
|
if (this.deviceLogging === 'debug') {
|
|
270
285
|
this.errorLog(
|
|
271
|
-
|
|
286
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
287
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
272
288
|
);
|
|
273
289
|
}
|
|
274
290
|
if (this.platform.debugMode) {
|
|
275
|
-
this.errorLog(
|
|
291
|
+
this.errorLog(
|
|
292
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
293
|
+
);
|
|
276
294
|
}
|
|
277
295
|
this.apiError(e);
|
|
278
296
|
}
|
|
@@ -294,7 +312,7 @@ export class ColorBulb {
|
|
|
294
312
|
* Strip Light - "command" "setColor" "`"{0-255}:{0-255}:{0-255}"`" = set RGB color value |
|
|
295
313
|
*
|
|
296
314
|
*/
|
|
297
|
-
async pushChanges() {
|
|
315
|
+
async pushChanges(): Promise<void> {
|
|
298
316
|
try {
|
|
299
317
|
if (this.On !== this.OnCached) {
|
|
300
318
|
// Push On Update
|
|
@@ -310,13 +328,13 @@ export class ColorBulb {
|
|
|
310
328
|
}
|
|
311
329
|
|
|
312
330
|
this.infoLog(
|
|
313
|
-
|
|
331
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
314
332
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
315
333
|
);
|
|
316
334
|
|
|
317
335
|
// Make the API request
|
|
318
336
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
319
|
-
this.debugLog(
|
|
337
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
320
338
|
this.statusCode(push);
|
|
321
339
|
this.OnCached = this.On;
|
|
322
340
|
this.accessory.context.On = this.OnCached;
|
|
@@ -327,7 +345,7 @@ export class ColorBulb {
|
|
|
327
345
|
}
|
|
328
346
|
|
|
329
347
|
// Push ColorTemperature Update
|
|
330
|
-
if (this.On) {
|
|
348
|
+
if (this.On && this.device.deviceType === 'Color Bulb') {
|
|
331
349
|
await this.pushColorTemperatureChanges();
|
|
332
350
|
}
|
|
333
351
|
|
|
@@ -336,27 +354,30 @@ export class ColorBulb {
|
|
|
336
354
|
await this.pushHueSaturationChanges();
|
|
337
355
|
}
|
|
338
356
|
} catch (e: any) {
|
|
339
|
-
this.errorLog(
|
|
357
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
340
358
|
if (this.deviceLogging === 'debug') {
|
|
341
359
|
this.errorLog(
|
|
342
|
-
|
|
360
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
361
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
343
362
|
);
|
|
344
363
|
}
|
|
345
364
|
if (this.platform.debugMode) {
|
|
346
|
-
this.errorLog(
|
|
365
|
+
this.errorLog(
|
|
366
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
367
|
+
);
|
|
347
368
|
}
|
|
348
369
|
this.apiError(e);
|
|
349
370
|
}
|
|
350
371
|
}
|
|
351
372
|
|
|
352
|
-
|
|
373
|
+
async pushHueSaturationChanges(): Promise<void> {
|
|
353
374
|
try {
|
|
354
375
|
if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
|
|
355
|
-
this.debugLog(
|
|
356
|
-
this.debugLog(
|
|
376
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
377
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
357
378
|
|
|
358
379
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
359
|
-
this.debugLog(
|
|
380
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
360
381
|
|
|
361
382
|
const payload = {
|
|
362
383
|
commandType: 'command',
|
|
@@ -365,37 +386,40 @@ export class ColorBulb {
|
|
|
365
386
|
} as payload;
|
|
366
387
|
|
|
367
388
|
this.infoLog(
|
|
368
|
-
|
|
389
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
369
390
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
370
391
|
);
|
|
371
392
|
|
|
372
393
|
// Make the API request
|
|
373
394
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
374
|
-
this.debugLog(
|
|
395
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
375
396
|
this.statusCode(push);
|
|
376
397
|
this.HueCached = this.Hue;
|
|
377
398
|
this.SaturationCached = this.Saturation;
|
|
378
399
|
} else {
|
|
379
400
|
this.debugLog(
|
|
380
|
-
|
|
401
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
381
402
|
`Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`,
|
|
382
403
|
);
|
|
383
404
|
}
|
|
384
405
|
} catch (e: any) {
|
|
385
|
-
this.errorLog(
|
|
406
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
386
407
|
if (this.deviceLogging === 'debug') {
|
|
387
408
|
this.errorLog(
|
|
388
|
-
|
|
409
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
410
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
389
411
|
);
|
|
390
412
|
}
|
|
391
413
|
if (this.platform.debugMode) {
|
|
392
|
-
this.errorLog(
|
|
414
|
+
this.errorLog(
|
|
415
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
416
|
+
);
|
|
393
417
|
}
|
|
394
418
|
this.apiError(e);
|
|
395
419
|
}
|
|
396
420
|
}
|
|
397
421
|
|
|
398
|
-
|
|
422
|
+
async pushColorTemperatureChanges(): Promise<void> {
|
|
399
423
|
try {
|
|
400
424
|
if (this.ColorTemperature !== this.ColorTemperatureCached) {
|
|
401
425
|
const kelvin = Math.round(1000000 / Number(this.ColorTemperature));
|
|
@@ -408,36 +432,39 @@ export class ColorBulb {
|
|
|
408
432
|
} as payload;
|
|
409
433
|
|
|
410
434
|
this.infoLog(
|
|
411
|
-
|
|
435
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
412
436
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
413
437
|
);
|
|
414
438
|
|
|
415
439
|
// Make the API request
|
|
416
440
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
417
|
-
this.debugLog(
|
|
441
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
418
442
|
this.statusCode(push);
|
|
419
443
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
420
444
|
} else {
|
|
421
445
|
this.debugLog(
|
|
422
|
-
|
|
446
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
423
447
|
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`,
|
|
424
448
|
);
|
|
425
449
|
}
|
|
426
450
|
} catch (e: any) {
|
|
427
|
-
this.errorLog(
|
|
451
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
428
452
|
if (this.deviceLogging === 'debug') {
|
|
429
453
|
this.errorLog(
|
|
430
|
-
|
|
454
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
455
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
431
456
|
);
|
|
432
457
|
}
|
|
433
458
|
if (this.platform.debugMode) {
|
|
434
|
-
this.errorLog(
|
|
459
|
+
this.errorLog(
|
|
460
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
461
|
+
);
|
|
435
462
|
}
|
|
436
463
|
this.apiError(e);
|
|
437
464
|
}
|
|
438
465
|
}
|
|
439
466
|
|
|
440
|
-
|
|
467
|
+
async pushBrightnessChanges(): Promise<void> {
|
|
441
468
|
try {
|
|
442
469
|
if (this.Brightness !== this.BrightnessCached) {
|
|
443
470
|
const payload = {
|
|
@@ -447,125 +474,133 @@ export class ColorBulb {
|
|
|
447
474
|
} as payload;
|
|
448
475
|
|
|
449
476
|
this.infoLog(
|
|
450
|
-
|
|
477
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
451
478
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
452
479
|
);
|
|
453
480
|
|
|
454
481
|
// Make the API request
|
|
455
482
|
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
456
|
-
this.debugLog(
|
|
483
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
457
484
|
this.statusCode(push);
|
|
458
485
|
this.BrightnessCached = this.Brightness;
|
|
459
486
|
} else {
|
|
460
487
|
this.debugLog(
|
|
461
|
-
|
|
488
|
+
`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
489
|
+
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
462
490
|
);
|
|
463
491
|
}
|
|
464
492
|
} catch (e: any) {
|
|
465
|
-
this.errorLog(
|
|
493
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
466
494
|
if (this.deviceLogging === 'debug') {
|
|
467
495
|
this.errorLog(
|
|
468
|
-
|
|
496
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
497
|
+
` Error Message: ${JSON.stringify(e.message)}`,
|
|
469
498
|
);
|
|
470
499
|
}
|
|
471
500
|
if (this.platform.debugMode) {
|
|
472
|
-
this.errorLog(
|
|
501
|
+
this.errorLog(
|
|
502
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`,
|
|
503
|
+
);
|
|
473
504
|
}
|
|
474
505
|
this.apiError(e);
|
|
475
506
|
}
|
|
476
507
|
}
|
|
477
508
|
|
|
478
|
-
updateHomeKitCharacteristics() {
|
|
509
|
+
async updateHomeKitCharacteristics(): Promise<void> {
|
|
479
510
|
if (this.On === undefined) {
|
|
480
|
-
this.debugLog(
|
|
511
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
481
512
|
} else {
|
|
482
|
-
this.
|
|
483
|
-
this.debugLog(
|
|
513
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
514
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
484
515
|
}
|
|
485
516
|
if (this.Brightness === undefined) {
|
|
486
|
-
this.debugLog(
|
|
517
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
487
518
|
} else {
|
|
488
|
-
this.
|
|
489
|
-
this.debugLog(
|
|
519
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
520
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
490
521
|
}
|
|
491
|
-
if (this.
|
|
492
|
-
this.
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
522
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
523
|
+
if (this.ColorTemperature === undefined) {
|
|
524
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
525
|
+
} else {
|
|
526
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
527
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
528
|
+
}
|
|
496
529
|
}
|
|
497
530
|
if (this.Hue === undefined) {
|
|
498
|
-
this.debugLog(
|
|
531
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
499
532
|
} else {
|
|
500
|
-
this.
|
|
501
|
-
this.debugLog(
|
|
533
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
502
535
|
}
|
|
503
536
|
if (this.Saturation === undefined) {
|
|
504
|
-
this.debugLog(
|
|
537
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
505
538
|
} else {
|
|
506
|
-
this.
|
|
507
|
-
this.debugLog(
|
|
539
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
540
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
508
541
|
}
|
|
509
542
|
}
|
|
510
543
|
|
|
511
|
-
|
|
512
|
-
this.
|
|
513
|
-
this.
|
|
514
|
-
this.
|
|
515
|
-
this.
|
|
516
|
-
|
|
544
|
+
apiError(e: any): void {
|
|
545
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
546
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
547
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
548
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
549
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
550
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
|
|
551
|
+
}
|
|
517
552
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
518
553
|
}
|
|
519
554
|
|
|
520
|
-
|
|
555
|
+
statusCode(push: AxiosResponse<{ statusCode: number }>): void {
|
|
521
556
|
switch (push.data.statusCode) {
|
|
522
557
|
case 151:
|
|
523
|
-
this.errorLog(
|
|
558
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
524
559
|
break;
|
|
525
560
|
case 152:
|
|
526
|
-
this.errorLog(
|
|
561
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
527
562
|
break;
|
|
528
563
|
case 160:
|
|
529
|
-
this.errorLog(
|
|
564
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
530
565
|
break;
|
|
531
566
|
case 161:
|
|
532
|
-
this.errorLog(
|
|
567
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
533
568
|
this.offlineOff();
|
|
534
569
|
break;
|
|
535
570
|
case 171:
|
|
536
|
-
this.errorLog(
|
|
571
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
537
572
|
this.offlineOff();
|
|
538
573
|
break;
|
|
539
574
|
case 190:
|
|
540
575
|
this.errorLog(
|
|
541
|
-
|
|
576
|
+
`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
542
577
|
` Or command: ${JSON.stringify(push.data)} format is invalid`,
|
|
543
578
|
);
|
|
544
579
|
break;
|
|
545
580
|
case 100:
|
|
546
581
|
if (this.platform.debugMode) {
|
|
547
|
-
this.debugLog(
|
|
582
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
548
583
|
}
|
|
549
584
|
break;
|
|
550
585
|
default:
|
|
551
586
|
if (this.platform.debugMode) {
|
|
552
|
-
this.debugLog(
|
|
587
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
553
588
|
}
|
|
554
589
|
}
|
|
555
590
|
}
|
|
556
591
|
|
|
557
|
-
offlineOff() {
|
|
592
|
+
async offlineOff(): Promise<void> {
|
|
558
593
|
if (this.device.offline) {
|
|
559
594
|
this.On = false;
|
|
560
|
-
this.
|
|
595
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
561
596
|
}
|
|
562
597
|
}
|
|
563
598
|
|
|
564
599
|
/**
|
|
565
600
|
* Handle requests to set the value of the "On" characteristic
|
|
566
601
|
*/
|
|
567
|
-
OnSet(value: CharacteristicValue) {
|
|
568
|
-
this.debugLog(
|
|
602
|
+
async OnSet(value: CharacteristicValue): Promise<void> {
|
|
603
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
|
|
569
604
|
|
|
570
605
|
this.On = value;
|
|
571
606
|
this.doColorBulbUpdate.next();
|
|
@@ -574,8 +609,8 @@ export class ColorBulb {
|
|
|
574
609
|
/**
|
|
575
610
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
576
611
|
*/
|
|
577
|
-
BrightnessSet(value: CharacteristicValue) {
|
|
578
|
-
this.debugLog(
|
|
612
|
+
async BrightnessSet(value: CharacteristicValue): Promise<void> {
|
|
613
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
|
|
579
614
|
|
|
580
615
|
this.Brightness = value;
|
|
581
616
|
this.doColorBulbUpdate.next();
|
|
@@ -584,8 +619,8 @@ export class ColorBulb {
|
|
|
584
619
|
/**
|
|
585
620
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
586
621
|
*/
|
|
587
|
-
ColorTemperatureSet(value: CharacteristicValue) {
|
|
588
|
-
this.debugLog(
|
|
622
|
+
async ColorTemperatureSet(value: CharacteristicValue): Promise<void> {
|
|
623
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
589
624
|
|
|
590
625
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
591
626
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
@@ -599,8 +634,8 @@ export class ColorBulb {
|
|
|
599
634
|
|
|
600
635
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
601
636
|
const hs = m2hs(value);
|
|
602
|
-
this.
|
|
603
|
-
this.
|
|
637
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
638
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
604
639
|
|
|
605
640
|
this.ColorTemperature = value;
|
|
606
641
|
this.doColorBulbUpdate.next();
|
|
@@ -609,10 +644,12 @@ export class ColorBulb {
|
|
|
609
644
|
/**
|
|
610
645
|
* Handle requests to set the value of the "Hue" characteristic
|
|
611
646
|
*/
|
|
612
|
-
HueSet(value: CharacteristicValue) {
|
|
613
|
-
this.debugLog(
|
|
647
|
+
async HueSet(value: CharacteristicValue): Promise<void> {
|
|
648
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
|
|
614
649
|
|
|
615
|
-
|
|
650
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
651
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
652
|
+
}
|
|
616
653
|
|
|
617
654
|
this.Hue = value;
|
|
618
655
|
this.doColorBulbUpdate.next();
|
|
@@ -621,16 +658,28 @@ export class ColorBulb {
|
|
|
621
658
|
/**
|
|
622
659
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
623
660
|
*/
|
|
624
|
-
SaturationSet(value: CharacteristicValue) {
|
|
625
|
-
this.debugLog(
|
|
661
|
+
async SaturationSet(value: CharacteristicValue): Promise<void> {
|
|
662
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
|
|
626
663
|
|
|
627
|
-
|
|
664
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
665
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
666
|
+
}
|
|
628
667
|
|
|
629
668
|
this.Saturation = value;
|
|
630
669
|
this.doColorBulbUpdate.next();
|
|
631
670
|
}
|
|
632
671
|
|
|
633
|
-
|
|
672
|
+
model(device: device & devicesConfig): string {
|
|
673
|
+
let model: string;
|
|
674
|
+
if (device.deviceType === 'Strip Light') {
|
|
675
|
+
model = 'W1701100';
|
|
676
|
+
} else {
|
|
677
|
+
model = 'W1401400';
|
|
678
|
+
}
|
|
679
|
+
return model;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
async config(device: device & devicesConfig): Promise<void> {
|
|
634
683
|
let config = {};
|
|
635
684
|
if (device.colorbulb) {
|
|
636
685
|
config = device.colorbulb;
|
|
@@ -651,43 +700,43 @@ export class ColorBulb {
|
|
|
651
700
|
config['offline'] = device.offline;
|
|
652
701
|
}
|
|
653
702
|
if (Object.entries(config).length !== 0) {
|
|
654
|
-
this.warnLog(
|
|
703
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
655
704
|
}
|
|
656
705
|
}
|
|
657
706
|
|
|
658
|
-
refreshRate(device: device & devicesConfig) {
|
|
707
|
+
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
659
708
|
if (device.refreshRate) {
|
|
660
709
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
661
|
-
this.debugLog(
|
|
710
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
662
711
|
} else if (this.platform.config.options!.refreshRate) {
|
|
663
712
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
664
|
-
this.debugLog(
|
|
713
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
665
714
|
}
|
|
666
715
|
}
|
|
667
716
|
|
|
668
|
-
logs(device: device & devicesConfig) {
|
|
717
|
+
async logs(device: device & devicesConfig): Promise<void> {
|
|
669
718
|
if (this.platform.debugMode) {
|
|
670
719
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
671
|
-
this.debugLog(
|
|
720
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
672
721
|
} else if (device.logging) {
|
|
673
722
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
674
|
-
this.debugLog(
|
|
723
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
675
724
|
} else if (this.platform.config.options?.logging) {
|
|
676
725
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
677
|
-
this.debugLog(
|
|
726
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
678
727
|
} else {
|
|
679
728
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
680
|
-
this.debugLog(
|
|
729
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
681
730
|
}
|
|
682
731
|
}
|
|
683
732
|
|
|
684
|
-
adaptiveLighting(device: device & devicesConfig) {
|
|
733
|
+
async adaptiveLighting(device: device & devicesConfig): Promise<void> {
|
|
685
734
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
686
735
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
687
|
-
this.debugLog(
|
|
736
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
688
737
|
} else {
|
|
689
738
|
this.adaptiveLightingShift = 0;
|
|
690
|
-
this.debugLog(
|
|
739
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
691
740
|
}
|
|
692
741
|
}
|
|
693
742
|
|
|
@@ -703,25 +752,25 @@ export class ColorBulb {
|
|
|
703
752
|
/**
|
|
704
753
|
* Logging for Device
|
|
705
754
|
*/
|
|
706
|
-
infoLog(...log: any[]) {
|
|
755
|
+
infoLog(...log: any[]): void {
|
|
707
756
|
if (this.enablingDeviceLogging()) {
|
|
708
757
|
this.platform.log.info(String(...log));
|
|
709
758
|
}
|
|
710
759
|
}
|
|
711
760
|
|
|
712
|
-
warnLog(...log: any[]) {
|
|
761
|
+
warnLog(...log: any[]): void {
|
|
713
762
|
if (this.enablingDeviceLogging()) {
|
|
714
763
|
this.platform.log.warn(String(...log));
|
|
715
764
|
}
|
|
716
765
|
}
|
|
717
766
|
|
|
718
|
-
errorLog(...log: any[]) {
|
|
767
|
+
errorLog(...log: any[]): void {
|
|
719
768
|
if (this.enablingDeviceLogging()) {
|
|
720
769
|
this.platform.log.error(String(...log));
|
|
721
770
|
}
|
|
722
771
|
}
|
|
723
772
|
|
|
724
|
-
debugLog(...log: any[]) {
|
|
773
|
+
debugLog(...log: any[]): void {
|
|
725
774
|
if (this.enablingDeviceLogging()) {
|
|
726
775
|
if (this.deviceLogging === 'debug') {
|
|
727
776
|
this.platform.log.info('[DEBUG]', String(...log));
|