@switchbot/homebridge-switchbot 1.2.5 → 1.2.6-beta.3
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/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +37 -35
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +33 -23
- package/dist/devices/curtains.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +1 -4
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +27 -13
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +3 -0
- package/dist/platform.js.map +1 -1
- package/package.json +66 -66
- package/src/devices/colorbulb.ts +40 -37
- package/src/devices/curtains.ts +31 -23
- package/src/irdevices/airconditioners.ts +28 -19
- package/src/platform.ts +2 -0
package/src/devices/colorbulb.ts
CHANGED
|
@@ -46,7 +46,10 @@ export class ColorBulb {
|
|
|
46
46
|
|
|
47
47
|
// default placeholders
|
|
48
48
|
this.On = false;
|
|
49
|
+
this.ColorTemperature = 140;
|
|
49
50
|
this.Brightness = 0;
|
|
51
|
+
this.Saturation = 0;
|
|
52
|
+
this.Hue = 0;
|
|
50
53
|
|
|
51
54
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
52
55
|
this.doColorBulbUpdate = new Subject();
|
|
@@ -185,39 +188,41 @@ export class ColorBulb {
|
|
|
185
188
|
default:
|
|
186
189
|
this.On = false;
|
|
187
190
|
}
|
|
188
|
-
this.platform.
|
|
191
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} On: ${this.On}`);
|
|
189
192
|
|
|
190
193
|
// Brightness
|
|
191
194
|
this.Brightness = Number(this.deviceStatus.body.brightness);
|
|
192
|
-
this.platform.
|
|
195
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} Brightness: ${this.Brightness}`);
|
|
193
196
|
|
|
194
197
|
// Color, Hue & Brightness
|
|
195
198
|
if (this.deviceStatus.body.color) {
|
|
196
|
-
this.platform.
|
|
199
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} color: ${JSON.stringify(this.deviceStatus.body.color)}`);
|
|
197
200
|
const [red, green, blue] = this.deviceStatus.body.color!.split(':');
|
|
198
|
-
this.platform.
|
|
199
|
-
this.platform.
|
|
200
|
-
this.platform.
|
|
201
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} red: ${JSON.stringify(red)}`);
|
|
202
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} green: ${JSON.stringify(green)}`);
|
|
203
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
201
204
|
|
|
202
205
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
203
|
-
this.platform.
|
|
206
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
204
207
|
|
|
205
208
|
// Hue
|
|
206
209
|
this.Hue = hue;
|
|
207
|
-
this.platform.
|
|
210
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} Hue: ${this.Hue}`);
|
|
208
211
|
|
|
209
212
|
// Saturation
|
|
210
213
|
this.Saturation = saturation;
|
|
211
|
-
this.platform.
|
|
214
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} Saturation: ${this.Saturation}`);
|
|
212
215
|
}
|
|
213
216
|
|
|
214
217
|
// ColorTemperature
|
|
215
|
-
if (this.deviceStatus.body.colorTemperature) {
|
|
216
|
-
|
|
217
|
-
const mired = Math.round(1000000 / this.deviceStatus.body.colorTemperature);
|
|
218
|
+
if (!Number.isNaN(this.deviceStatus.body.colorTemperature)) {
|
|
219
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} OpenAPI ColorTemperature: ${this.deviceStatus.body.colorTemperature}`);
|
|
220
|
+
const mired = Math.round(1000000 / this.deviceStatus.body.colorTemperature!);
|
|
218
221
|
|
|
219
222
|
this.ColorTemperature = Number(mired);
|
|
220
|
-
|
|
223
|
+
|
|
224
|
+
this.ColorTemperature = Math.max(Math.min(this.ColorTemperature, 500), 140);
|
|
225
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
221
226
|
}
|
|
222
227
|
}
|
|
223
228
|
|
|
@@ -254,33 +259,31 @@ export class ColorBulb {
|
|
|
254
259
|
async pushChanges() {
|
|
255
260
|
try {
|
|
256
261
|
// Push On Update
|
|
262
|
+
const payload = {
|
|
263
|
+
commandType: 'command',
|
|
264
|
+
parameter: 'default',
|
|
265
|
+
} as payload;
|
|
266
|
+
|
|
257
267
|
if (this.On) {
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
268
|
+
payload.command = 'turnOn';
|
|
269
|
+
} else {
|
|
270
|
+
payload.command = 'turnOff';
|
|
271
|
+
}
|
|
262
272
|
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
} else {
|
|
266
|
-
payload.command = 'turnOff';
|
|
267
|
-
}
|
|
273
|
+
this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
274
|
+
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
268
275
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
274
|
-
this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
275
|
-
this.statusCode(push);
|
|
276
|
-
}
|
|
276
|
+
// Make the API request
|
|
277
|
+
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload));
|
|
278
|
+
this.platform.debug(`Color Bulb: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
279
|
+
this.statusCode(push);
|
|
277
280
|
|
|
278
281
|
// Push Brightness Update
|
|
279
282
|
if (this.On) {
|
|
280
283
|
const payload = {
|
|
281
284
|
commandType: 'command',
|
|
282
285
|
command: 'setBrightness',
|
|
283
|
-
parameter:
|
|
286
|
+
parameter: `${this.Brightness}`,
|
|
284
287
|
} as payload;
|
|
285
288
|
|
|
286
289
|
this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
@@ -299,7 +302,7 @@ export class ColorBulb {
|
|
|
299
302
|
const payload = {
|
|
300
303
|
commandType: 'command',
|
|
301
304
|
command: 'setColorTemperature',
|
|
302
|
-
parameter:
|
|
305
|
+
parameter: `${kelvin}`,
|
|
303
306
|
} as payload;
|
|
304
307
|
|
|
305
308
|
this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
@@ -313,16 +316,16 @@ export class ColorBulb {
|
|
|
313
316
|
|
|
314
317
|
// Push Hue & Saturation Update
|
|
315
318
|
if (this.On) {
|
|
316
|
-
this.platform.
|
|
317
|
-
this.platform.
|
|
319
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} Hue: ${JSON.stringify(this.Hue)}`);
|
|
320
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} Saturation: ${JSON.stringify(this.Saturation)}`);
|
|
318
321
|
|
|
319
322
|
const [red, green, blue] = hs2rgb(Number(this.Hue), Number(this.Saturation));
|
|
320
|
-
this.platform.
|
|
323
|
+
this.platform.device(`Color Bulb: ${this.accessory.displayName} rgb: ${JSON.stringify([red, green, blue])}`);
|
|
321
324
|
|
|
322
325
|
const payload = {
|
|
323
326
|
commandType: 'command',
|
|
324
327
|
command: 'setColor',
|
|
325
|
-
parameter:
|
|
328
|
+
parameter: `${red}:${green}:${blue}`,
|
|
326
329
|
} as payload;
|
|
327
330
|
|
|
328
331
|
this.platform.log.info(`Color Bulb: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
@@ -364,7 +367,7 @@ export class ColorBulb {
|
|
|
364
367
|
if (this.ColorTemperature === undefined) {
|
|
365
368
|
this.platform.debug(`Color Bulb: ${this.accessory.displayName} ColorTemperature: ${this.ColorTemperature}`);
|
|
366
369
|
} else {
|
|
367
|
-
this.service.updateCharacteristic(this.platform.Characteristic.
|
|
370
|
+
this.service.updateCharacteristic(this.platform.Characteristic.ColorTemperature, this.ColorTemperature);
|
|
368
371
|
this.platform.debug(`Color Bulb: ${this.accessory.displayName} updateCharacteristic ColorTemperature: ${this.ColorTemperature}`);
|
|
369
372
|
}
|
|
370
373
|
if (this.Hue === undefined) {
|
package/src/devices/curtains.ts
CHANGED
|
@@ -491,29 +491,34 @@ export class Curtain {
|
|
|
491
491
|
}
|
|
492
492
|
|
|
493
493
|
private async BLEpushChanges() {
|
|
494
|
-
this.
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
this.
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
this.
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
this.platform.
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
494
|
+
if (this.TargetPosition !== this.CurrentPosition) {
|
|
495
|
+
this.platform.debug(`Curtain: ${this.accessory.displayName} BLE pushChanges`);
|
|
496
|
+
const switchbot = this.connectBLE();
|
|
497
|
+
switchbot.discover({ model: 'c', quick: true, id: this.device.bleMac }).then((device_list) => {
|
|
498
|
+
this.platform.log.info(`${this.accessory.displayName} Target Position: ${this.TargetPosition}`);
|
|
499
|
+
return device_list[0].runToPos(100 - Number(this.TargetPosition));
|
|
500
|
+
}).then(() => {
|
|
501
|
+
this.platform.device(`Curtain: ${this.accessory.displayName} Done.`);
|
|
502
|
+
}).catch(async (e: any) => {
|
|
503
|
+
this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
504
|
+
if (this.deviceDebug) {
|
|
505
|
+
this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
506
|
+
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
507
|
+
}
|
|
508
|
+
if (this.debugDebug) {
|
|
509
|
+
this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with BLE Connection,`
|
|
510
|
+
+ ` Error: ${JSON.stringify(e)}`);
|
|
511
|
+
}
|
|
512
|
+
if (this.platform.config.credentials?.openToken) {
|
|
513
|
+
this.platform.log.warn(`Curtain: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
514
|
+
await this.OpenAPIpushChanges();
|
|
515
|
+
}
|
|
516
|
+
this.apiError(e);
|
|
517
|
+
});
|
|
518
|
+
} else {
|
|
519
|
+
this.platform.debug(`Curtain: ${this.accessory.displayName} No BLE Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
520
|
+
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
521
|
+
}
|
|
517
522
|
}
|
|
518
523
|
|
|
519
524
|
private async OpenAPIpushChanges() {
|
|
@@ -536,6 +541,9 @@ export class Curtain {
|
|
|
536
541
|
const push: any = (await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId!}/commands`, payload));
|
|
537
542
|
this.platform.debug(`Curtain: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
538
543
|
this.statusCode(push);
|
|
544
|
+
} else {
|
|
545
|
+
this.platform.debug(`Curtain: ${this.accessory.displayName} No OpenAPI Changes, CurrentPosition & TargetPosition Are the Same.`
|
|
546
|
+
+ ` CurrentPosition: ${this.CurrentPosition}, TargetPosition ${this.TargetPosition}`);
|
|
539
547
|
}
|
|
540
548
|
} catch (e: any) {
|
|
541
549
|
this.platform.log.error(`Curtain: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
@@ -14,18 +14,15 @@ export class AirConditioner {
|
|
|
14
14
|
|
|
15
15
|
// Characteristic Values
|
|
16
16
|
Active!: CharacteristicValue;
|
|
17
|
-
ARActive!: CharacteristicValue;
|
|
18
17
|
RotationSpeed!: CharacteristicValue;
|
|
19
|
-
CurrentARTemp!: CharacteristicValue;
|
|
20
|
-
CurrentARMode!: CharacteristicValue;
|
|
21
18
|
LastTemperature!: CharacteristicValue;
|
|
22
|
-
CurrentARFanSpeed!: CharacteristicValue;
|
|
23
19
|
CurrentTemperature!: CharacteristicValue;
|
|
24
20
|
TargetHeaterCoolerState?: CharacteristicValue;
|
|
25
21
|
CurrentHeaterCoolerState!: CharacteristicValue;
|
|
26
22
|
HeatingThresholdTemperature?: CharacteristicValue;
|
|
27
23
|
|
|
28
24
|
// Others
|
|
25
|
+
state!: string;
|
|
29
26
|
Busy: any;
|
|
30
27
|
Timeout: any = null;
|
|
31
28
|
CurrentMode!: number;
|
|
@@ -158,8 +155,10 @@ export class AirConditioner {
|
|
|
158
155
|
|
|
159
156
|
if (value === this.platform.Characteristic.Active.INACTIVE) {
|
|
160
157
|
this.pushAirConditionerOffChanges();
|
|
158
|
+
this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
161
159
|
} else {
|
|
162
160
|
this.pushAirConditionerOnChanges();
|
|
161
|
+
this.platform.device(`Air Conditioner: ${this.accessory.displayName} pushAirConditionerOffChanges, Active: ${this.Active}`);
|
|
163
162
|
}
|
|
164
163
|
this.Active = value;
|
|
165
164
|
}
|
|
@@ -180,7 +179,7 @@ export class AirConditioner {
|
|
|
180
179
|
if (this.CurrentTemperature === undefined) {
|
|
181
180
|
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
182
181
|
} else {
|
|
183
|
-
this.service?.updateCharacteristic(this.platform.Characteristic.
|
|
182
|
+
this.service?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
184
183
|
this.platform.device(`Air Conditioner: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
185
184
|
}
|
|
186
185
|
if (this.TargetHeaterCoolerState === undefined) {
|
|
@@ -207,9 +206,8 @@ export class AirConditioner {
|
|
|
207
206
|
}
|
|
208
207
|
|
|
209
208
|
private CurrentTemperatureGet(value: CharacteristicValue) {
|
|
210
|
-
this.platform.debug('Trigger Get CurrentTemperture');
|
|
211
|
-
|
|
212
209
|
value = Number(this.CurrentTemperature) || 24;
|
|
210
|
+
this.platform.debug(`Air Conditioner: ${this.accessory.displayName} Trigger Get CurrentTemperature: ${value}` );
|
|
213
211
|
|
|
214
212
|
this.service
|
|
215
213
|
.getCharacteristic(this.platform.Characteristic.CurrentTemperature)
|
|
@@ -236,7 +234,7 @@ export class AirConditioner {
|
|
|
236
234
|
}
|
|
237
235
|
|
|
238
236
|
private CurrentHeaterCoolerStateGet() {
|
|
239
|
-
if (this.Active ===
|
|
237
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
240
238
|
if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
|
|
241
239
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
242
240
|
} else {
|
|
@@ -273,7 +271,7 @@ export class AirConditioner {
|
|
|
273
271
|
* AirConditioner: "command" "highSpeed" "default" = fan speed to high
|
|
274
272
|
*/
|
|
275
273
|
async pushAirConditionerOnChanges() {
|
|
276
|
-
if (this.Active !==
|
|
274
|
+
if (this.Active !== this.platform.Characteristic.Active.ACTIVE) {
|
|
277
275
|
const payload = {
|
|
278
276
|
commandType: 'command',
|
|
279
277
|
parameter: 'default',
|
|
@@ -284,7 +282,7 @@ export class AirConditioner {
|
|
|
284
282
|
}
|
|
285
283
|
|
|
286
284
|
async pushAirConditionerOffChanges() {
|
|
287
|
-
if (this.Active !==
|
|
285
|
+
if (this.Active !== this.platform.Characteristic.Active.INACTIVE) {
|
|
288
286
|
const payload = {
|
|
289
287
|
commandType: 'command',
|
|
290
288
|
parameter: 'default',
|
|
@@ -311,14 +309,25 @@ export class AirConditioner {
|
|
|
311
309
|
command: 'setAll',
|
|
312
310
|
} as any;
|
|
313
311
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
312
|
+
if (this.CurrentTemperature === undefined) {
|
|
313
|
+
this.CurrentTemperature = 24;
|
|
314
|
+
}
|
|
315
|
+
if (this.CurrentMode === undefined) {
|
|
316
|
+
this.CurrentMode = 1;
|
|
317
|
+
}
|
|
318
|
+
if (this.CurrentFanSpeed === undefined) {
|
|
319
|
+
this.CurrentFanSpeed = 1;
|
|
320
|
+
}
|
|
321
|
+
this.Active = this.platform.Characteristic.Active.ACTIVE;
|
|
322
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
323
|
+
this.state = 'on';
|
|
324
|
+
} else {
|
|
325
|
+
this.state = 'off';
|
|
326
|
+
}
|
|
327
|
+
payload.parameter = `${this.CurrentTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`;
|
|
319
328
|
|
|
320
329
|
|
|
321
|
-
if (this.Active ===
|
|
330
|
+
if (this.Active === this.platform.Characteristic.Active.ACTIVE) {
|
|
322
331
|
if ((this.CurrentTemperature || 24) < (this.LastTemperature || 30)) {
|
|
323
332
|
this.CurrentHeaterCoolerState = this.platform.Characteristic.CurrentHeaterCoolerState.COOLING;
|
|
324
333
|
} else {
|
|
@@ -334,11 +343,11 @@ export class AirConditioner {
|
|
|
334
343
|
public async pushChanges(payload: payload) {
|
|
335
344
|
try {
|
|
336
345
|
this.platform.log.info(`Air Conditioner: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},`
|
|
337
|
-
+ ` parameter: ${payload.parameter}, commandType: ${payload.commandType}`);
|
|
346
|
+
+ ` parameter: [${payload.parameter}], commandType: ${payload.commandType}`);
|
|
338
347
|
|
|
339
348
|
// Make the API request
|
|
340
|
-
const push = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
341
|
-
this.platform.
|
|
349
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
350
|
+
this.platform.log.error(`Air Conditioner: ${this.accessory.displayName} pushChanges: ${JSON.stringify(push.data)}`);
|
|
342
351
|
this.statusCode(push);
|
|
343
352
|
this.updateHomeKitCharacteristics();
|
|
344
353
|
} catch (e: any) {
|
package/src/platform.ts
CHANGED
|
@@ -1451,6 +1451,8 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
|
|
|
1451
1451
|
device(...log: any[]) {
|
|
1452
1452
|
if (this.config.options!.debug === 'device') {
|
|
1453
1453
|
this.log.warn('[DEVICE]', String(...log));
|
|
1454
|
+
} else if (this.config.options!.debug === 'debug') {
|
|
1455
|
+
this.log.info('[DEBUG]', String(...log));
|
|
1454
1456
|
} else {
|
|
1455
1457
|
this.log.debug(String(...log));
|
|
1456
1458
|
}
|