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