@switchbot/homebridge-switchbot 1.14.3-beta.0 → 1.15.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/config.schema.json +1 -1
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +3 -3
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +15 -1
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +140 -13
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +8 -5
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +6 -2
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +2 -1
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +2 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +25 -14
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +2 -1
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +2 -1
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -9
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +34 -32
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +7 -11
- package/dist/device/striplight.js.map +1 -1
- package/package.json +7 -6
- package/src/device/bot.ts +3 -3
- package/src/device/colorbulb.ts +169 -18
- package/src/device/contact.ts +9 -6
- package/src/device/curtain.ts +6 -2
- package/src/device/humidifier.ts +2 -1
- package/src/device/lock.ts +4 -3
- package/src/device/meter.ts +42 -32
- package/src/device/meterplus.ts +2 -1
- package/src/device/motion.ts +2 -1
- package/src/device/plug.ts +45 -43
- package/src/device/striplight.ts +8 -14
package/src/device/plug.ts
CHANGED
|
@@ -21,9 +21,16 @@ export class Plug {
|
|
|
21
21
|
// BLE Others
|
|
22
22
|
connected?: boolean;
|
|
23
23
|
switchbot!: switchbot;
|
|
24
|
+
address!: ad['address'];
|
|
24
25
|
SwitchToOpenAPI?: boolean;
|
|
25
26
|
serviceData!: serviceData;
|
|
26
|
-
|
|
27
|
+
state: serviceData['state'];
|
|
28
|
+
delay: serviceData['delay'];
|
|
29
|
+
timer: serviceData['timer'];
|
|
30
|
+
wifiRssi: serviceData['wifiRssi'];
|
|
31
|
+
overload: serviceData['overload'];
|
|
32
|
+
syncUtcTime: serviceData['syncUtcTime'];
|
|
33
|
+
currentPower: serviceData['currentPower'];
|
|
27
34
|
|
|
28
35
|
// Config
|
|
29
36
|
scanDuration!: number;
|
|
@@ -33,13 +40,6 @@ export class Plug {
|
|
|
33
40
|
// Updates
|
|
34
41
|
plugUpdateInProgress!: boolean;
|
|
35
42
|
doPlugUpdate!: Subject<void>;
|
|
36
|
-
state: serviceData['state'];
|
|
37
|
-
delay: serviceData['delay'];
|
|
38
|
-
timer: serviceData['timer'];
|
|
39
|
-
syncUtcTime: serviceData['syncUtcTime'];
|
|
40
|
-
wifiRssi: serviceData['wifiRssi'];
|
|
41
|
-
overload: serviceData['overload'];
|
|
42
|
-
currentPower: serviceData['currentPower'];
|
|
43
43
|
|
|
44
44
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
45
45
|
// default placeholders
|
|
@@ -87,7 +87,7 @@ export class Plug {
|
|
|
87
87
|
// see https://developers.homebridge.io/#/service/Outlet
|
|
88
88
|
|
|
89
89
|
// create handlers for required characteristics
|
|
90
|
-
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.
|
|
90
|
+
this.outletService.getCharacteristic(this.platform.Characteristic.On).onSet(this.handleOnSet.bind(this));
|
|
91
91
|
|
|
92
92
|
// Update Homekit
|
|
93
93
|
this.updateHomeKitCharacteristics();
|
|
@@ -271,7 +271,7 @@ export class Plug {
|
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
274
|
-
this.errorLog(`Plug: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-
|
|
274
|
+
this.errorLog(`Plug: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
275
275
|
if (this.platform.config.credentials?.openToken) {
|
|
276
276
|
this.warnLog(`Plug: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
277
277
|
this.SwitchToOpenAPI = true;
|
|
@@ -326,9 +326,12 @@ export class Plug {
|
|
|
326
326
|
.toLowerCase();
|
|
327
327
|
this.debugLog(`Plug: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
328
328
|
switchbot
|
|
329
|
-
.discover({
|
|
329
|
+
.discover({
|
|
330
|
+
model: this.BLEmodel(),
|
|
331
|
+
id: this.device.bleMac,
|
|
332
|
+
})
|
|
330
333
|
.then((device_list: any) => {
|
|
331
|
-
this.infoLog(`
|
|
334
|
+
this.infoLog(`Plug: ${this.accessory.displayName} On: ${this.On}`);
|
|
332
335
|
return this.turnOnOff(device_list);
|
|
333
336
|
})
|
|
334
337
|
.then(() => {
|
|
@@ -336,10 +339,6 @@ export class Plug {
|
|
|
336
339
|
this.On = false;
|
|
337
340
|
this.OnCached = this.On;
|
|
338
341
|
this.accessory.context.On = this.OnCached;
|
|
339
|
-
setTimeout(() => {
|
|
340
|
-
this.outletService?.getCharacteristic(this.platform.Characteristic.On).updateValue(this.On);
|
|
341
|
-
this.debugLog(`Plug: ${this.accessory.displayName} On: ${this.On}, Switch Timeout`);
|
|
342
|
-
}, 500);
|
|
343
342
|
})
|
|
344
343
|
.catch(async (e: any) => {
|
|
345
344
|
this.errorLog(`Plug: ${this.accessory.displayName} failed pushChanges with BLE Connection`);
|
|
@@ -374,36 +373,39 @@ export class Plug {
|
|
|
374
373
|
});
|
|
375
374
|
}
|
|
376
375
|
|
|
377
|
-
|
|
378
|
-
if (this.
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
376
|
+
async openAPIpushChanges() {
|
|
377
|
+
if (this.platform.config.credentials?.openToken) {
|
|
378
|
+
if (this.On !== this.OnCached) {
|
|
379
|
+
this.debugLog(`Plug: ${this.accessory.displayName} OpenAPI pushChanges`);
|
|
380
|
+
const payload = {
|
|
381
|
+
commandType: 'command',
|
|
382
|
+
parameter: 'default',
|
|
383
|
+
} as payload;
|
|
383
384
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
385
|
+
if (this.On) {
|
|
386
|
+
payload.command = 'turnOn';
|
|
387
|
+
} else {
|
|
388
|
+
payload.command = 'turnOff';
|
|
389
|
+
}
|
|
389
390
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
this.infoLog(
|
|
392
|
+
`Plug: ${this.accessory.displayName} Sending request to SwitchBot API. command: ${payload.command},` +
|
|
393
|
+
` parameter: ${payload.parameter}, commandType: ${payload.commandType}`,
|
|
394
|
+
);
|
|
394
395
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
396
|
+
// Make the API request
|
|
397
|
+
const push: any = await this.platform.axios.post(`${DeviceURL}/${this.device.deviceId}/commands`, payload);
|
|
398
|
+
this.debugLog(`Plug: ${this.accessory.displayName} pushchanges: ${JSON.stringify(push.data)}`);
|
|
399
|
+
this.statusCode(push);
|
|
400
|
+
this.OnCached = this.On;
|
|
401
|
+
this.accessory.context.On = this.OnCached;
|
|
402
|
+
}
|
|
403
|
+
interval(5000)
|
|
404
|
+
.pipe(take(1))
|
|
405
|
+
.subscribe(async () => {
|
|
406
|
+
await this.refreshStatus();
|
|
407
|
+
});
|
|
401
408
|
}
|
|
402
|
-
interval(5000)
|
|
403
|
-
.pipe(take(1))
|
|
404
|
-
.subscribe(async () => {
|
|
405
|
-
await this.refreshStatus();
|
|
406
|
-
});
|
|
407
409
|
}
|
|
408
410
|
|
|
409
411
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
@@ -463,7 +465,7 @@ export class Plug {
|
|
|
463
465
|
/**
|
|
464
466
|
* Handle requests to set the value of the "On" characteristic
|
|
465
467
|
*/
|
|
466
|
-
async
|
|
468
|
+
async handleOnSet(value: CharacteristicValue): Promise<void> {
|
|
467
469
|
this.debugLog(`Plug: ${this.accessory.displayName} - Set On: ${value}`);
|
|
468
470
|
|
|
469
471
|
this.On = value;
|
package/src/device/striplight.ts
CHANGED
|
@@ -81,7 +81,8 @@ export class StripLight {
|
|
|
81
81
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1701100')
|
|
82
82
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
83
83
|
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
84
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
84
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
85
|
+
.updateValue(this.FirmwareRevision(accessory, device));
|
|
85
86
|
|
|
86
87
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
87
88
|
// you can create multiple services for each accessory
|
|
@@ -195,9 +196,7 @@ export class StripLight {
|
|
|
195
196
|
this.debugLog(`Strip Light: ${this.accessory.displayName} blue: ${JSON.stringify(blue)}`);
|
|
196
197
|
|
|
197
198
|
const [hue, saturation] = rgb2hs(Number(red), Number(green), Number(blue));
|
|
198
|
-
this.debugLog(
|
|
199
|
-
`Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`,
|
|
200
|
-
);
|
|
199
|
+
this.debugLog(`Strip Light: ${this.accessory.displayName} hs: ${JSON.stringify(rgb2hs(Number(red), Number(green), Number(blue)))}`);
|
|
201
200
|
|
|
202
201
|
// Hue
|
|
203
202
|
this.Hue = hue;
|
|
@@ -223,8 +222,7 @@ export class StripLight {
|
|
|
223
222
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
224
223
|
if (this.deviceLogging.includes('debug')) {
|
|
225
224
|
this.errorLog(
|
|
226
|
-
`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` +
|
|
227
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
225
|
+
`Strip Light: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
228
226
|
);
|
|
229
227
|
}
|
|
230
228
|
this.apiError(e);
|
|
@@ -281,8 +279,7 @@ export class StripLight {
|
|
|
281
279
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
282
280
|
if (this.deviceLogging.includes('debug')) {
|
|
283
281
|
this.errorLog(
|
|
284
|
-
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
285
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
282
|
+
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
286
283
|
);
|
|
287
284
|
}
|
|
288
285
|
this.apiError(e);
|
|
@@ -325,8 +322,7 @@ export class StripLight {
|
|
|
325
322
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
326
323
|
if (this.deviceLogging.includes('debug')) {
|
|
327
324
|
this.errorLog(
|
|
328
|
-
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
329
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
325
|
+
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
330
326
|
);
|
|
331
327
|
}
|
|
332
328
|
this.apiError(e);
|
|
@@ -354,16 +350,14 @@ export class StripLight {
|
|
|
354
350
|
this.BrightnessCached = this.Brightness;
|
|
355
351
|
} else {
|
|
356
352
|
this.debugLog(
|
|
357
|
-
`Strip Light: ${this.accessory.displayName} No Changes.` +
|
|
358
|
-
`Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
353
|
+
`Strip Light: ${this.accessory.displayName} No Changes.` + `Brightness: ${this.Brightness}, BrightnessCached: ${this.BrightnessCached}`,
|
|
359
354
|
);
|
|
360
355
|
}
|
|
361
356
|
} catch (e: any) {
|
|
362
357
|
this.errorLog(`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection`);
|
|
363
358
|
if (this.deviceLogging.includes('debug')) {
|
|
364
359
|
this.errorLog(
|
|
365
|
-
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` +
|
|
366
|
-
` Error Message: ${JSON.stringify(e.message)}`,
|
|
360
|
+
`Strip Light: ${this.accessory.displayName} failed pushChanges with OpenAPI Connection,` + ` Error Message: ${JSON.stringify(e.message)}`,
|
|
367
361
|
);
|
|
368
362
|
}
|
|
369
363
|
this.apiError(e);
|