@switchbot/homebridge-switchbot 1.10.2-beta.5 → 1.11.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/CHANGELOG.md +3 -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 +29 -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 -145
- 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 +41 -41
- 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 +20 -22
- 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 -14
- package/dist/device/meter.js.map +1 -1
- package/dist/device/motion.d.ts +16 -16
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +16 -17
- 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 +22 -21
- package/dist/device/plug.js.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 +53 -50
- package/src/device/colorbulb.ts +208 -162
- package/src/device/contact.ts +31 -30
- package/src/device/curtain.ts +68 -57
- package/src/device/humidifier.ts +68 -59
- package/src/device/lock.ts +28 -31
- package/src/device/meter.ts +25 -31
- package/src/device/motion.ts +32 -36
- package/src/device/plug.ts +25 -25
- package/src/settings.ts +5 -1
package/dist/device/colorbulb.js
CHANGED
|
@@ -25,12 +25,6 @@ class ColorBulb {
|
|
|
25
25
|
else {
|
|
26
26
|
this.On = this.accessory.context.On;
|
|
27
27
|
}
|
|
28
|
-
this.Hue = 0;
|
|
29
|
-
this.Brightness = 0;
|
|
30
|
-
this.Saturation = 0;
|
|
31
|
-
this.ColorTemperature = 140;
|
|
32
|
-
this.minKelvin = 2000;
|
|
33
|
-
this.maxKelvin = 9000;
|
|
34
28
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
35
29
|
this.doColorBulbUpdate = new rxjs_1.Subject();
|
|
36
30
|
this.colorBulbUpdateInProgress = false;
|
|
@@ -40,28 +34,28 @@ class ColorBulb {
|
|
|
40
34
|
accessory
|
|
41
35
|
.getService(this.platform.Service.AccessoryInformation)
|
|
42
36
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
43
|
-
.setCharacteristic(this.platform.Characteristic.Model,
|
|
37
|
+
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
44
38
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId);
|
|
45
39
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
46
40
|
// you can create multiple services for each accessory
|
|
47
|
-
(this.
|
|
48
|
-
`${accessory.displayName}
|
|
41
|
+
(this.lightBulbService = accessory.getService(this.platform.Service.Lightbulb) || accessory.addService(this.platform.Service.Lightbulb)),
|
|
42
|
+
`${accessory.displayName} ${this.device.deviceType}`;
|
|
49
43
|
if (this.adaptiveLightingShift === -1 && this.accessory.context.adaptiveLighting) {
|
|
50
|
-
this.accessory.removeService(this.
|
|
51
|
-
this.
|
|
44
|
+
this.accessory.removeService(this.lightBulbService);
|
|
45
|
+
this.lightBulbService = this.accessory.addService(this.platform.Service.Lightbulb);
|
|
52
46
|
this.accessory.context.adaptiveLighting = false;
|
|
53
|
-
this.debugLog(
|
|
47
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting}`);
|
|
54
48
|
}
|
|
55
49
|
// To avoid "Cannot add a Service with the same UUID another Service without also defining a unique 'subtype' property." error,
|
|
56
50
|
// when creating multiple services of the same type, you need to use the following syntax to specify a name and subtype id:
|
|
57
51
|
// accessory.getService('NAME') ?? accessory.addService(this.platform.Service.Outlet, 'NAME', 'USER_DEFINED_SUBTYPE');
|
|
58
52
|
// set the service name, this is what is displayed as the default name on the Home app
|
|
59
53
|
// in this example we are using the name we stored in the `accessory.context` in the `discoverDevices` method.
|
|
60
|
-
this.
|
|
54
|
+
this.lightBulbService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
61
55
|
// handle on / off events using the On characteristic
|
|
62
|
-
this.
|
|
56
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).onSet(this.OnSet.bind(this));
|
|
63
57
|
// handle Brightness events using the Brightness characteristic
|
|
64
|
-
this.
|
|
58
|
+
this.lightBulbService
|
|
65
59
|
.getCharacteristic(this.platform.Characteristic.Brightness)
|
|
66
60
|
.setProps({
|
|
67
61
|
minStep: this.minStep(device),
|
|
@@ -74,19 +68,25 @@ class ColorBulb {
|
|
|
74
68
|
})
|
|
75
69
|
.onSet(this.BrightnessSet.bind(this));
|
|
76
70
|
// handle ColorTemperature events using the ColorTemperature characteristic
|
|
77
|
-
|
|
78
|
-
.
|
|
79
|
-
.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
if (device.deviceType === 'Color Bulb') {
|
|
72
|
+
this.debugLog(`Color Bulb: ${accessory.displayName} Add ColorTemperature Characteristic`);
|
|
73
|
+
this.lightBulbService
|
|
74
|
+
.getCharacteristic(this.platform.Characteristic.ColorTemperature)
|
|
75
|
+
.setProps({
|
|
76
|
+
minValue: 140,
|
|
77
|
+
maxValue: 500,
|
|
78
|
+
validValueRanges: [140, 500],
|
|
79
|
+
})
|
|
80
|
+
.onGet(() => {
|
|
81
|
+
return this.ColorTemperature;
|
|
82
|
+
})
|
|
83
|
+
.onSet(this.ColorTemperatureSet.bind(this));
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
this.debugLog(`Color Bulb: ${accessory.displayName} ColorTemperature Characteristic Not Added`);
|
|
87
|
+
}
|
|
88
88
|
// handle Hue events using the Hue characteristic
|
|
89
|
-
this.
|
|
89
|
+
this.lightBulbService
|
|
90
90
|
.getCharacteristic(this.platform.Characteristic.Hue)
|
|
91
91
|
.setProps({
|
|
92
92
|
minValue: 0,
|
|
@@ -98,7 +98,7 @@ class ColorBulb {
|
|
|
98
98
|
})
|
|
99
99
|
.onSet(this.HueSet.bind(this));
|
|
100
100
|
// handle Hue events using the Hue characteristic
|
|
101
|
-
this.
|
|
101
|
+
this.lightBulbService
|
|
102
102
|
.getCharacteristic(this.platform.Characteristic.Saturation)
|
|
103
103
|
.setProps({
|
|
104
104
|
minValue: 0,
|
|
@@ -109,14 +109,14 @@ class ColorBulb {
|
|
|
109
109
|
return this.Saturation;
|
|
110
110
|
})
|
|
111
111
|
.onSet(this.SaturationSet.bind(this));
|
|
112
|
-
this.debugLog(
|
|
112
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
113
113
|
if (this.adaptiveLightingShift !== -1) {
|
|
114
|
-
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.
|
|
114
|
+
this.AdaptiveLightingController = new platform.api.hap.AdaptiveLightingController(this.lightBulbService, {
|
|
115
115
|
customTemperatureAdjustment: this.adaptiveLightingShift,
|
|
116
116
|
});
|
|
117
117
|
this.accessory.configureController(this.AdaptiveLightingController);
|
|
118
118
|
this.accessory.context.adaptiveLighting = true;
|
|
119
|
-
this.debugLog(
|
|
119
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLighting: ${this.accessory.context.adaptiveLighting},` +
|
|
120
120
|
` adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
121
121
|
}
|
|
122
122
|
// Update Homekit
|
|
@@ -124,8 +124,8 @@ class ColorBulb {
|
|
|
124
124
|
// Start an update interval
|
|
125
125
|
(0, rxjs_1.interval)(this.deviceRefreshRate * 1000)
|
|
126
126
|
.pipe((0, operators_1.skipWhile)(() => this.colorBulbUpdateInProgress))
|
|
127
|
-
.subscribe(() => {
|
|
128
|
-
this.refreshStatus();
|
|
127
|
+
.subscribe(async () => {
|
|
128
|
+
await this.refreshStatus();
|
|
129
129
|
});
|
|
130
130
|
// Watch for Bulb change events
|
|
131
131
|
// We put in a debounce of 100ms so we don't make duplicate calls
|
|
@@ -138,19 +138,19 @@ class ColorBulb {
|
|
|
138
138
|
await this.pushChanges();
|
|
139
139
|
}
|
|
140
140
|
catch (e) {
|
|
141
|
-
this.errorLog(
|
|
141
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges`);
|
|
142
142
|
if (this.deviceLogging === 'debug') {
|
|
143
|
-
this.errorLog(
|
|
143
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
144
144
|
}
|
|
145
145
|
if (this.platform.debugMode) {
|
|
146
|
-
this.errorLog(
|
|
146
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges,` + ` Error: ${JSON.stringify(e)}`);
|
|
147
147
|
}
|
|
148
148
|
this.apiError(e);
|
|
149
149
|
}
|
|
150
150
|
this.colorBulbUpdateInProgress = false;
|
|
151
151
|
});
|
|
152
152
|
}
|
|
153
|
-
parseStatus() {
|
|
153
|
+
async parseStatus() {
|
|
154
154
|
switch (this.power) {
|
|
155
155
|
case 'on':
|
|
156
156
|
this.On = true;
|
|
@@ -158,53 +158,58 @@ class ColorBulb {
|
|
|
158
158
|
default:
|
|
159
159
|
this.On = false;
|
|
160
160
|
}
|
|
161
|
-
this.debugLog(
|
|
161
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
162
162
|
// Brightness
|
|
163
163
|
this.Brightness = Number(this.brightness);
|
|
164
|
-
this.debugLog(
|
|
164
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
165
165
|
// Color, Hue & Brightness
|
|
166
166
|
if (this.color) {
|
|
167
|
-
this.debugLog(
|
|
167
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} color: ${JSON.stringify(this.color)}`);
|
|
168
168
|
const [red, green, blue] = this.color.split(':');
|
|
169
|
-
this.debugLog(
|
|
170
|
-
this.debugLog(
|
|
171
|
-
this.debugLog(
|
|
169
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
170
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
171
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
172
172
|
const [hue, saturation] = (0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue));
|
|
173
|
-
this.debugLog(
|
|
173
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} hs: ${JSON.stringify((0, settings_1.rgb2hs)(Number(red), Number(green), Number(blue)))}`);
|
|
174
174
|
// Hue
|
|
175
175
|
this.Hue = hue;
|
|
176
|
-
this.debugLog(
|
|
176
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
177
177
|
// Saturation
|
|
178
178
|
this.Saturation = saturation;
|
|
179
|
-
this.debugLog(
|
|
179
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
180
180
|
}
|
|
181
181
|
// ColorTemperature
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
182
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
183
|
+
if (!Number.isNaN(this.colorTemperature)) {
|
|
184
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.colorTemperature}`);
|
|
185
|
+
const mired = Math.round(1000000 / this.colorTemperature);
|
|
186
|
+
this.ColorTemperature = Number(mired);
|
|
187
|
+
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
188
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
189
|
+
}
|
|
188
190
|
}
|
|
189
191
|
}
|
|
190
192
|
async refreshStatus() {
|
|
191
193
|
try {
|
|
192
194
|
this.deviceStatus = (await this.platform.axios.get(`${settings_1.DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
193
|
-
this.debugLog(
|
|
195
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
194
196
|
this.power = this.deviceStatus.body.power;
|
|
195
197
|
this.color = this.deviceStatus.body.color;
|
|
196
198
|
this.brightness = this.deviceStatus.body.brightness;
|
|
197
|
-
this.
|
|
199
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
200
|
+
this.colorTemperature = this.deviceStatus.body.colorTemperature;
|
|
201
|
+
}
|
|
198
202
|
this.parseStatus();
|
|
199
203
|
this.updateHomeKitCharacteristics();
|
|
200
204
|
}
|
|
201
205
|
catch (e) {
|
|
202
|
-
this.errorLog(
|
|
206
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
203
207
|
if (this.deviceLogging === 'debug') {
|
|
204
|
-
this.errorLog(
|
|
208
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
209
|
+
` Error Message: ${JSON.stringify(e.message)}`);
|
|
205
210
|
}
|
|
206
211
|
if (this.platform.debugMode) {
|
|
207
|
-
this.errorLog(
|
|
212
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
208
213
|
}
|
|
209
214
|
this.apiError(e);
|
|
210
215
|
}
|
|
@@ -239,11 +244,11 @@ class ColorBulb {
|
|
|
239
244
|
else {
|
|
240
245
|
payload.command = 'turnOff';
|
|
241
246
|
}
|
|
242
|
-
this.infoLog(
|
|
247
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
243
248
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
244
249
|
// Make the API request
|
|
245
250
|
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
246
|
-
this.debugLog(
|
|
251
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
247
252
|
this.statusCode(push);
|
|
248
253
|
this.OnCached = this.On;
|
|
249
254
|
this.accessory.context.On = this.OnCached;
|
|
@@ -253,7 +258,7 @@ class ColorBulb {
|
|
|
253
258
|
await this.pushBrightnessChanges();
|
|
254
259
|
}
|
|
255
260
|
// Push ColorTemperature Update
|
|
256
|
-
if (this.On) {
|
|
261
|
+
if (this.On && this.device.deviceType === 'Color Bulb') {
|
|
257
262
|
await this.pushColorTemperatureChanges();
|
|
258
263
|
}
|
|
259
264
|
// Push Hue & Saturation Update
|
|
@@ -262,12 +267,13 @@ class ColorBulb {
|
|
|
262
267
|
}
|
|
263
268
|
}
|
|
264
269
|
catch (e) {
|
|
265
|
-
this.errorLog(
|
|
270
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
266
271
|
if (this.deviceLogging === 'debug') {
|
|
267
|
-
this.errorLog(
|
|
272
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
273
|
+
` Error Message: ${JSON.stringify(e.message)}`);
|
|
268
274
|
}
|
|
269
275
|
if (this.platform.debugMode) {
|
|
270
|
-
this.errorLog(
|
|
276
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
271
277
|
}
|
|
272
278
|
this.apiError(e);
|
|
273
279
|
}
|
|
@@ -275,36 +281,37 @@ class ColorBulb {
|
|
|
275
281
|
async pushHueSaturationChanges() {
|
|
276
282
|
try {
|
|
277
283
|
if (this.Hue !== this.HueCached || this.Saturation !== this.SaturationCached) {
|
|
278
|
-
this.debugLog(
|
|
279
|
-
this.debugLog(
|
|
284
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
285
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
280
286
|
const [red, green, blue] = (0, settings_1.hs2rgb)(Number(this.Hue), Number(this.Saturation));
|
|
281
|
-
this.debugLog(
|
|
287
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
282
288
|
const payload = {
|
|
283
289
|
commandType: 'command',
|
|
284
290
|
command: 'setColor',
|
|
285
291
|
parameter: `${red}:${green}:${blue}`,
|
|
286
292
|
};
|
|
287
|
-
this.infoLog(
|
|
293
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
288
294
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
289
295
|
// Make the API request
|
|
290
296
|
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
291
|
-
this.debugLog(
|
|
297
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
292
298
|
this.statusCode(push);
|
|
293
299
|
this.HueCached = this.Hue;
|
|
294
300
|
this.SaturationCached = this.Saturation;
|
|
295
301
|
}
|
|
296
302
|
else {
|
|
297
|
-
this.debugLog(
|
|
303
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
298
304
|
`Hue: ${this.Hue}, HueCached: ${this.HueCached}, Saturation: ${this.Saturation}, SaturationCached: ${this.SaturationCached}`);
|
|
299
305
|
}
|
|
300
306
|
}
|
|
301
307
|
catch (e) {
|
|
302
|
-
this.errorLog(
|
|
308
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
303
309
|
if (this.deviceLogging === 'debug') {
|
|
304
|
-
this.errorLog(
|
|
310
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
311
|
+
` Error Message: ${JSON.stringify(e.message)}`);
|
|
305
312
|
}
|
|
306
313
|
if (this.platform.debugMode) {
|
|
307
|
-
this.errorLog(
|
|
314
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
308
315
|
}
|
|
309
316
|
this.apiError(e);
|
|
310
317
|
}
|
|
@@ -319,26 +326,27 @@ class ColorBulb {
|
|
|
319
326
|
command: 'setColorTemperature',
|
|
320
327
|
parameter: `${kelvin}`,
|
|
321
328
|
};
|
|
322
|
-
this.infoLog(
|
|
329
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
323
330
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
324
331
|
// Make the API request
|
|
325
332
|
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
326
|
-
this.debugLog(
|
|
333
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
327
334
|
this.statusCode(push);
|
|
328
335
|
this.ColorTemperatureCached = this.ColorTemperature;
|
|
329
336
|
}
|
|
330
337
|
else {
|
|
331
|
-
this.debugLog(
|
|
338
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
332
339
|
`ColorTemperature: ${this.ColorTemperature}, ColorTemperatureCached: ${this.ColorTemperatureCached}`);
|
|
333
340
|
}
|
|
334
341
|
}
|
|
335
342
|
catch (e) {
|
|
336
|
-
this.errorLog(
|
|
343
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
337
344
|
if (this.deviceLogging === 'debug') {
|
|
338
|
-
this.errorLog(
|
|
345
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
346
|
+
` Error Message: ${JSON.stringify(e.message)}`);
|
|
339
347
|
}
|
|
340
348
|
if (this.platform.debugMode) {
|
|
341
|
-
this.errorLog(
|
|
349
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
342
350
|
}
|
|
343
351
|
this.apiError(e);
|
|
344
352
|
}
|
|
@@ -351,135 +359,141 @@ class ColorBulb {
|
|
|
351
359
|
command: 'setBrightness',
|
|
352
360
|
parameter: `${this.Brightness}`,
|
|
353
361
|
};
|
|
354
|
-
this.infoLog(
|
|
362
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
355
363
|
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
356
364
|
// Make the API request
|
|
357
365
|
const push = await this.platform.axios.post(`${settings_1.DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
358
|
-
this.debugLog(
|
|
366
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
359
367
|
this.statusCode(push);
|
|
360
368
|
this.BrightnessCached = this.Brightness;
|
|
361
369
|
}
|
|
362
370
|
else {
|
|
363
|
-
this.debugLog(
|
|
371
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} No Changes.` +
|
|
372
|
+
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`);
|
|
364
373
|
}
|
|
365
374
|
}
|
|
366
375
|
catch (e) {
|
|
367
|
-
this.errorLog(
|
|
376
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
368
377
|
if (this.deviceLogging === 'debug') {
|
|
369
|
-
this.errorLog(
|
|
378
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
379
|
+
` Error Message: ${JSON.stringify(e.message)}`);
|
|
370
380
|
}
|
|
371
381
|
if (this.platform.debugMode) {
|
|
372
|
-
this.errorLog(
|
|
382
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error: ${JSON.stringify(e)}`);
|
|
373
383
|
}
|
|
374
384
|
this.apiError(e);
|
|
375
385
|
}
|
|
376
386
|
}
|
|
377
|
-
updateHomeKitCharacteristics() {
|
|
387
|
+
async updateHomeKitCharacteristics() {
|
|
378
388
|
if (this.On === undefined) {
|
|
379
|
-
this.debugLog(
|
|
389
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.On}`);
|
|
380
390
|
}
|
|
381
391
|
else {
|
|
382
|
-
this.
|
|
383
|
-
this.debugLog(
|
|
392
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
393
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
384
394
|
}
|
|
385
395
|
if (this.Brightness === undefined) {
|
|
386
|
-
this.debugLog(
|
|
396
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
387
397
|
}
|
|
388
398
|
else {
|
|
389
|
-
this.
|
|
390
|
-
this.debugLog(
|
|
391
|
-
}
|
|
392
|
-
if (this.ColorTemperature === undefined) {
|
|
393
|
-
this.debugLog(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
399
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, this.Brightness);
|
|
400
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Brightness: ${this.Brightness}`);
|
|
394
401
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
402
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
403
|
+
if (this.ColorTemperature === undefined) {
|
|
404
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
405
|
+
}
|
|
406
|
+
else {
|
|
407
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
408
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
409
|
+
}
|
|
398
410
|
}
|
|
399
411
|
if (this.Hue === undefined) {
|
|
400
|
-
this.debugLog(
|
|
412
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
401
413
|
}
|
|
402
414
|
else {
|
|
403
|
-
this.
|
|
404
|
-
this.debugLog(
|
|
415
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, this.Hue);
|
|
416
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Hue: ${this.Hue}`);
|
|
405
417
|
}
|
|
406
418
|
if (this.Saturation === undefined) {
|
|
407
|
-
this.debugLog(
|
|
419
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
408
420
|
}
|
|
409
421
|
else {
|
|
410
|
-
this.
|
|
411
|
-
this.debugLog(
|
|
422
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, this.Saturation);
|
|
423
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic Saturation: ${this.Saturation}`);
|
|
412
424
|
}
|
|
413
425
|
}
|
|
414
426
|
apiError(e) {
|
|
415
|
-
this.
|
|
416
|
-
this.
|
|
417
|
-
this.
|
|
418
|
-
this.
|
|
419
|
-
|
|
427
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
428
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, e);
|
|
429
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Brightness, e);
|
|
430
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, e);
|
|
431
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
432
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, e);
|
|
433
|
+
}
|
|
420
434
|
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
421
435
|
}
|
|
422
436
|
statusCode(push) {
|
|
423
437
|
switch (push.data.statusCode) {
|
|
424
438
|
case 151:
|
|
425
|
-
this.errorLog(
|
|
439
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
426
440
|
break;
|
|
427
441
|
case 152:
|
|
428
|
-
this.errorLog(
|
|
442
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
429
443
|
break;
|
|
430
444
|
case 160:
|
|
431
|
-
this.errorLog(
|
|
445
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
432
446
|
break;
|
|
433
447
|
case 161:
|
|
434
|
-
this.errorLog(
|
|
448
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
435
449
|
this.offlineOff();
|
|
436
450
|
break;
|
|
437
451
|
case 171:
|
|
438
|
-
this.errorLog(
|
|
452
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
439
453
|
this.offlineOff();
|
|
440
454
|
break;
|
|
441
455
|
case 190:
|
|
442
|
-
this.errorLog(
|
|
456
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
443
457
|
` Or command: ${JSON.stringify(push.data)} format is invalid`);
|
|
444
458
|
break;
|
|
445
459
|
case 100:
|
|
446
460
|
if (this.platform.debugMode) {
|
|
447
|
-
this.debugLog(
|
|
461
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
448
462
|
}
|
|
449
463
|
break;
|
|
450
464
|
default:
|
|
451
465
|
if (this.platform.debugMode) {
|
|
452
|
-
this.debugLog(
|
|
466
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
453
467
|
}
|
|
454
468
|
}
|
|
455
469
|
}
|
|
456
|
-
offlineOff() {
|
|
470
|
+
async offlineOff() {
|
|
457
471
|
if (this.device.offline) {
|
|
458
472
|
this.On = false;
|
|
459
|
-
this.
|
|
473
|
+
this.lightBulbService.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
460
474
|
}
|
|
461
475
|
}
|
|
462
476
|
/**
|
|
463
477
|
* Handle requests to set the value of the "On" characteristic
|
|
464
478
|
*/
|
|
465
|
-
OnSet(value) {
|
|
466
|
-
this.debugLog(
|
|
479
|
+
async OnSet(value) {
|
|
480
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${value}`);
|
|
467
481
|
this.On = value;
|
|
468
482
|
this.doColorBulbUpdate.next();
|
|
469
483
|
}
|
|
470
484
|
/**
|
|
471
485
|
* Handle requests to set the value of the "Brightness" characteristic
|
|
472
486
|
*/
|
|
473
|
-
BrightnessSet(value) {
|
|
474
|
-
this.debugLog(
|
|
487
|
+
async BrightnessSet(value) {
|
|
488
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Brightness: ${value}`);
|
|
475
489
|
this.Brightness = value;
|
|
476
490
|
this.doColorBulbUpdate.next();
|
|
477
491
|
}
|
|
478
492
|
/**
|
|
479
493
|
* Handle requests to set the value of the "ColorTemperature" characteristic
|
|
480
494
|
*/
|
|
481
|
-
ColorTemperatureSet(value) {
|
|
482
|
-
this.debugLog(
|
|
495
|
+
async ColorTemperatureSet(value) {
|
|
496
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ColorTemperature: ${value}`);
|
|
483
497
|
// Convert mired to kelvin to nearest 100 (SwitchBot seems to need this)
|
|
484
498
|
const kelvin = Math.round(1000000 / Number(value) / 100) * 100;
|
|
485
499
|
// Check and increase/decrease kelvin to range of device
|
|
@@ -489,30 +503,44 @@ class ColorBulb {
|
|
|
489
503
|
}
|
|
490
504
|
// Updating the hue/sat to the corresponding values mimics native adaptive lighting
|
|
491
505
|
const hs = (0, settings_1.m2hs)(value);
|
|
492
|
-
this.
|
|
493
|
-
this.
|
|
506
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Hue, hs[0]);
|
|
507
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.Saturation, hs[1]);
|
|
494
508
|
this.ColorTemperature = value;
|
|
495
509
|
this.doColorBulbUpdate.next();
|
|
496
510
|
}
|
|
497
511
|
/**
|
|
498
512
|
* Handle requests to set the value of the "Hue" characteristic
|
|
499
513
|
*/
|
|
500
|
-
HueSet(value) {
|
|
501
|
-
this.debugLog(
|
|
502
|
-
|
|
514
|
+
async HueSet(value) {
|
|
515
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Hue: ${value}`);
|
|
516
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
517
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
518
|
+
}
|
|
503
519
|
this.Hue = value;
|
|
504
520
|
this.doColorBulbUpdate.next();
|
|
505
521
|
}
|
|
506
522
|
/**
|
|
507
523
|
* Handle requests to set the value of the "Saturation" characteristic
|
|
508
524
|
*/
|
|
509
|
-
SaturationSet(value) {
|
|
510
|
-
this.debugLog(
|
|
511
|
-
|
|
525
|
+
async SaturationSet(value) {
|
|
526
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Saturation: ${value}`);
|
|
527
|
+
if (this.device.deviceType === 'Color Bulb') {
|
|
528
|
+
this.lightBulbService.updateCharacteristic(this.platform.Characteristic.ColorTemperature, 140);
|
|
529
|
+
}
|
|
512
530
|
this.Saturation = value;
|
|
513
531
|
this.doColorBulbUpdate.next();
|
|
514
532
|
}
|
|
515
|
-
|
|
533
|
+
model(device) {
|
|
534
|
+
let model;
|
|
535
|
+
if (device.deviceType === 'Strip Light') {
|
|
536
|
+
model = 'W1701100';
|
|
537
|
+
}
|
|
538
|
+
else {
|
|
539
|
+
model = 'W1401400';
|
|
540
|
+
}
|
|
541
|
+
return model;
|
|
542
|
+
}
|
|
543
|
+
async config(device) {
|
|
516
544
|
let config = {};
|
|
517
545
|
if (device.colorbulb) {
|
|
518
546
|
config = device.colorbulb;
|
|
@@ -529,46 +557,49 @@ class ColorBulb {
|
|
|
529
557
|
if (device.scanDuration !== undefined) {
|
|
530
558
|
config['scanDuration'] = device.scanDuration;
|
|
531
559
|
}
|
|
560
|
+
if (device.offline !== undefined) {
|
|
561
|
+
config['offline'] = device.offline;
|
|
562
|
+
}
|
|
532
563
|
if (Object.entries(config).length !== 0) {
|
|
533
|
-
this.warnLog(
|
|
564
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
534
565
|
}
|
|
535
566
|
}
|
|
536
|
-
refreshRate(device) {
|
|
567
|
+
async refreshRate(device) {
|
|
537
568
|
if (device.refreshRate) {
|
|
538
569
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
539
|
-
this.debugLog(
|
|
570
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
540
571
|
}
|
|
541
572
|
else if (this.platform.config.options.refreshRate) {
|
|
542
573
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
543
|
-
this.debugLog(
|
|
574
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
544
575
|
}
|
|
545
576
|
}
|
|
546
|
-
logs(device) {
|
|
577
|
+
async logs(device) {
|
|
547
578
|
if (this.platform.debugMode) {
|
|
548
579
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
549
|
-
this.debugLog(
|
|
580
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
550
581
|
}
|
|
551
582
|
else if (device.logging) {
|
|
552
583
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
553
|
-
this.debugLog(
|
|
584
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
554
585
|
}
|
|
555
586
|
else if (this.platform.config.options?.logging) {
|
|
556
587
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
557
|
-
this.debugLog(
|
|
588
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
558
589
|
}
|
|
559
590
|
else {
|
|
560
591
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
561
|
-
this.debugLog(
|
|
592
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
562
593
|
}
|
|
563
594
|
}
|
|
564
|
-
adaptiveLighting(device) {
|
|
595
|
+
async adaptiveLighting(device) {
|
|
565
596
|
if (device.colorbulb?.adaptiveLightingShift) {
|
|
566
597
|
this.adaptiveLightingShift = device.colorbulb.adaptiveLightingShift;
|
|
567
|
-
this.debugLog(
|
|
598
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
568
599
|
}
|
|
569
600
|
else {
|
|
570
601
|
this.adaptiveLightingShift = 0;
|
|
571
|
-
this.debugLog(
|
|
602
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} adaptiveLightingShift: ${this.adaptiveLightingShift}`);
|
|
572
603
|
}
|
|
573
604
|
}
|
|
574
605
|
minStep(device) {
|