@switchbot/homebridge-switchbot 1.12.9-beta.7 → 1.13.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/.github/workflows/codeql-analysis.yml +3 -3
- package/.github/workflows/dependabot.yml +17 -0
- package/.github/workflows/nodejs-beta.yml +0 -3
- package/.github/workflows/nodejs.yml +0 -3
- package/CHANGELOG.md +3 -1
- package/config.schema.json +1 -1
- package/dist/device/bot.d.ts +3 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +18 -1
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +3 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +18 -1
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +3 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +18 -1
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +6 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +57 -1
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +3 -0
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +18 -1
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +3 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +18 -1
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +82 -6
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +3 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -1
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +3 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +18 -1
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +3 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +18 -1
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +3 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +18 -1
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/other.js +3 -3
- package/dist/irdevice/other.js.map +1 -1
- package/dist/platform.d.ts +1 -0
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +44 -41
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +5 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +78 -76
- package/src/device/bot.ts +18 -1
- package/src/device/colorbulb.ts +18 -1
- package/src/device/contact.ts +18 -1
- package/src/device/curtain.ts +60 -1
- package/src/device/humidifier.ts +18 -1
- package/src/device/lock.ts +18 -1
- package/src/device/meter.ts +90 -6
- package/src/device/meterplus.ts +18 -1
- package/src/device/motion.ts +18 -1
- package/src/device/plug.ts +18 -1
- package/src/device/striplight.ts +18 -1
- package/src/irdevice/other.ts +3 -3
- package/src/platform.ts +47 -41
- package/src/settings.ts +5 -0
package/src/device/meter.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { skipWhile } from 'rxjs/operators';
|
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
5
5
|
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature, deviceStatus } from '../settings';
|
|
6
|
+
import { Context } from 'vm';
|
|
7
|
+
import { MqttClient } from 'mqtt';
|
|
8
|
+
import { connectAsync } from 'async-mqtt';
|
|
9
|
+
import { hostname } from "os";
|
|
6
10
|
|
|
7
11
|
/**
|
|
8
12
|
* Platform Accessory
|
|
@@ -50,12 +54,20 @@ export class Meter {
|
|
|
50
54
|
meterUpdateInProgress!: boolean;
|
|
51
55
|
doMeterUpdate: Subject<void>;
|
|
52
56
|
|
|
57
|
+
//MQTT stuff
|
|
58
|
+
mqttClient: MqttClient | null = null;
|
|
59
|
+
|
|
60
|
+
// EVE history service handler
|
|
61
|
+
historyService: any;
|
|
62
|
+
|
|
53
63
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
54
64
|
// default placeholders
|
|
55
65
|
this.logs(device);
|
|
56
66
|
this.scan(device);
|
|
67
|
+
this.setupHistoryService(device);
|
|
57
68
|
this.refreshRate(device);
|
|
58
69
|
this.config(device);
|
|
70
|
+
this.setupMqtt(device);
|
|
59
71
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
60
72
|
this.CurrentRelativeHumidity = 0;
|
|
61
73
|
} else {
|
|
@@ -80,7 +92,8 @@ export class Meter {
|
|
|
80
92
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
81
93
|
.setCharacteristic(this.platform.Characteristic.Model, 'METERTH-S1')
|
|
82
94
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
83
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
95
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
96
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
84
97
|
|
|
85
98
|
// Temperature Sensor Service
|
|
86
99
|
if (device.meter?.hide_temperature) {
|
|
@@ -164,6 +177,48 @@ export class Meter {
|
|
|
164
177
|
});
|
|
165
178
|
}
|
|
166
179
|
|
|
180
|
+
/*
|
|
181
|
+
* Publish MQTT message for topics of
|
|
182
|
+
* 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
|
|
183
|
+
*/
|
|
184
|
+
mqttPublish(message: any) {
|
|
185
|
+
const mac = this.device.deviceId?.toLowerCase().match(/[\s\S]{1,2}/g)?.join(':');
|
|
186
|
+
const options = this.device.mqttPubOptions || {};
|
|
187
|
+
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
188
|
+
this.debugLog(`Meter: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/*
|
|
192
|
+
* Setup MQTT hadler if URL is specifed.
|
|
193
|
+
*/
|
|
194
|
+
async setupMqtt(device: device & devicesConfig): Promise<void> {
|
|
195
|
+
if (device.mqttURL) {
|
|
196
|
+
try {
|
|
197
|
+
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
198
|
+
this.debugLog(`Meter: ${this.accessory.displayName} MQTT connection has been established successfully.`)
|
|
199
|
+
this.mqttClient.on('error', (e: Error) => {
|
|
200
|
+
this.errorLog(`Meter: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`)
|
|
201
|
+
});
|
|
202
|
+
} catch (e) {
|
|
203
|
+
this.mqttClient = null;
|
|
204
|
+
this.errorLog(`Meter: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`)
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/*
|
|
210
|
+
* Setup EVE history graph feature if enabled.
|
|
211
|
+
*/
|
|
212
|
+
async setupHistoryService(device: device & devicesConfig): Promise<void> {
|
|
213
|
+
const mac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase();
|
|
214
|
+
this.historyService = device.history ?
|
|
215
|
+
new this.platform.fakegatoAPI('room', this.accessory,
|
|
216
|
+
{log: this.platform.log, storage: 'fs',
|
|
217
|
+
filename: `${hostname().split(".")[0]}_${mac}_persist.json`
|
|
218
|
+
}) :
|
|
219
|
+
null;
|
|
220
|
+
}
|
|
221
|
+
|
|
167
222
|
/**
|
|
168
223
|
* Parse the device status from the SwitchBot api
|
|
169
224
|
*/
|
|
@@ -185,7 +240,7 @@ export class Meter {
|
|
|
185
240
|
} else {
|
|
186
241
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
187
242
|
}
|
|
188
|
-
|
|
243
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
189
244
|
|
|
190
245
|
// Humidity
|
|
191
246
|
if (!this.device.meter?.hide_humidity) {
|
|
@@ -259,10 +314,12 @@ export class Meter {
|
|
|
259
314
|
this.infoLog(`Meter: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
260
315
|
this.infoLog(`Meter: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
261
316
|
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
317
|
+
if (ad.serviceData.humidity! > 0) { // reject unreliable data
|
|
318
|
+
this.serviceData = ad.serviceData;
|
|
319
|
+
this.temperature = ad.serviceData.temperature!.c;
|
|
320
|
+
this.humidity = ad.serviceData.humidity;
|
|
321
|
+
this.battery = ad.serviceData.battery;
|
|
322
|
+
}
|
|
266
323
|
this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
267
324
|
this.debugLog(
|
|
268
325
|
`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
@@ -363,12 +420,16 @@ export class Meter {
|
|
|
363
420
|
* Updates the status for each of the HomeKit Characteristics
|
|
364
421
|
*/
|
|
365
422
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
423
|
+
let mqttmessage: string[] = [];
|
|
424
|
+
let entry = {time: Math.round(new Date().valueOf()/1000)};
|
|
366
425
|
if (!this.device.meter?.hide_humidity) {
|
|
367
426
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
368
427
|
this.debugLog(`Meter: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
369
428
|
} else {
|
|
370
429
|
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
371
430
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
431
|
+
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
432
|
+
entry["humidity"] = this.CurrentRelativeHumidity;
|
|
372
433
|
}
|
|
373
434
|
}
|
|
374
435
|
if (!this.device.meter?.hide_temperature) {
|
|
@@ -377,6 +438,8 @@ export class Meter {
|
|
|
377
438
|
} else {
|
|
378
439
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
379
440
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
441
|
+
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
442
|
+
entry["temp"] = this.CurrentTemperature;
|
|
380
443
|
}
|
|
381
444
|
}
|
|
382
445
|
if (this.device.ble) {
|
|
@@ -385,14 +448,20 @@ export class Meter {
|
|
|
385
448
|
} else {
|
|
386
449
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
387
450
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
451
|
+
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
388
452
|
}
|
|
389
453
|
if (this.StatusLowBattery === undefined) {
|
|
390
454
|
this.debugLog(`Meter: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
391
455
|
} else {
|
|
392
456
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
393
457
|
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
458
|
+
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
394
459
|
}
|
|
395
460
|
}
|
|
461
|
+
this.mqttPublish(`{${mqttmessage.join(',')}}`)
|
|
462
|
+
if (this.CurrentRelativeHumidity > 0) { // reject unreliable data
|
|
463
|
+
this.historyService?.addEntry(entry);
|
|
464
|
+
}
|
|
396
465
|
}
|
|
397
466
|
|
|
398
467
|
async apiError(e: any): Promise<void> {
|
|
@@ -471,6 +540,21 @@ export class Meter {
|
|
|
471
540
|
}
|
|
472
541
|
}
|
|
473
542
|
|
|
543
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
544
|
+
let FirmwareRevision: string;
|
|
545
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
546
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
547
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
548
|
+
if (accessory.context.FirmwareRevision) {
|
|
549
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
550
|
+
} else if (device.firmware) {
|
|
551
|
+
FirmwareRevision = device.firmware;
|
|
552
|
+
} else {
|
|
553
|
+
FirmwareRevision = this.platform.version;
|
|
554
|
+
}
|
|
555
|
+
return FirmwareRevision;
|
|
556
|
+
}
|
|
557
|
+
|
|
474
558
|
/**
|
|
475
559
|
* Logging for Device
|
|
476
560
|
*/
|
package/src/device/meterplus.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { skipWhile } from 'rxjs/operators';
|
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
5
5
|
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature, deviceStatus } from '../settings';
|
|
6
|
+
import { Context } from 'vm';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Platform Accessory
|
|
@@ -80,7 +81,8 @@ export class MeterPlus {
|
|
|
80
81
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
81
82
|
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
82
83
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
83
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
84
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
85
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
84
86
|
|
|
85
87
|
// Temperature Sensor Service
|
|
86
88
|
if (device.meter?.hide_temperature) {
|
|
@@ -482,6 +484,21 @@ export class MeterPlus {
|
|
|
482
484
|
}
|
|
483
485
|
}
|
|
484
486
|
|
|
487
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
488
|
+
let FirmwareRevision: string;
|
|
489
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
490
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
491
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
492
|
+
if (accessory.context.FirmwareRevision) {
|
|
493
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
494
|
+
} else if (device.firmware) {
|
|
495
|
+
FirmwareRevision = device.firmware;
|
|
496
|
+
} else {
|
|
497
|
+
FirmwareRevision = this.platform.version;
|
|
498
|
+
}
|
|
499
|
+
return FirmwareRevision;
|
|
500
|
+
}
|
|
501
|
+
|
|
485
502
|
/**
|
|
486
503
|
* Logging for Device
|
|
487
504
|
*/
|
package/src/device/motion.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { skipWhile } from 'rxjs/operators';
|
|
|
3
3
|
import { SwitchBotPlatform } from '../platform';
|
|
4
4
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
5
5
|
import { DeviceURL, device, devicesConfig, serviceData, switchbot, deviceStatusResponse, deviceStatus, ad } from '../settings';
|
|
6
|
+
import { Context } from 'vm';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Platform Accessory
|
|
@@ -68,7 +69,8 @@ export class Motion {
|
|
|
68
69
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
69
70
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1101500')
|
|
70
71
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
71
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
72
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
73
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
72
74
|
|
|
73
75
|
// get the Battery service if it exists, otherwise create a new Motion service
|
|
74
76
|
// you can create multiple services for each accessory
|
|
@@ -454,6 +456,21 @@ export class Motion {
|
|
|
454
456
|
}
|
|
455
457
|
}
|
|
456
458
|
|
|
459
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
460
|
+
let FirmwareRevision: string;
|
|
461
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
462
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
463
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
464
|
+
if (accessory.context.FirmwareRevision) {
|
|
465
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
466
|
+
} else if (device.firmware) {
|
|
467
|
+
FirmwareRevision = device.firmware;
|
|
468
|
+
} else {
|
|
469
|
+
FirmwareRevision = this.platform.version;
|
|
470
|
+
}
|
|
471
|
+
return FirmwareRevision;
|
|
472
|
+
}
|
|
473
|
+
|
|
457
474
|
minLux(): number {
|
|
458
475
|
if (this.device.motion?.set_minLux) {
|
|
459
476
|
this.set_minLux = this.device.motion!.set_minLux!;
|
package/src/device/plug.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, deviceStatusResponse, payload, deviceStatus } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
7
8
|
|
|
8
9
|
export class Plug {
|
|
9
10
|
// Services
|
|
@@ -51,7 +52,8 @@ export class Plug {
|
|
|
51
52
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
52
53
|
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
53
54
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
54
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
55
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
56
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
55
57
|
|
|
56
58
|
// get the Outlet service if it exists, otherwise create a new Outlet service
|
|
57
59
|
// you can create multiple services for each accessory
|
|
@@ -316,6 +318,21 @@ export class Plug {
|
|
|
316
318
|
}
|
|
317
319
|
}
|
|
318
320
|
|
|
321
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
322
|
+
let FirmwareRevision: string;
|
|
323
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
324
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
325
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
326
|
+
if (accessory.context.FirmwareRevision) {
|
|
327
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
328
|
+
} else if (device.firmware) {
|
|
329
|
+
FirmwareRevision = device.firmware;
|
|
330
|
+
} else {
|
|
331
|
+
FirmwareRevision = this.platform.version;
|
|
332
|
+
}
|
|
333
|
+
return FirmwareRevision;
|
|
334
|
+
}
|
|
335
|
+
|
|
319
336
|
/**
|
|
320
337
|
* Logging for Device
|
|
321
338
|
*/
|
package/src/device/striplight.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { SwitchBotPlatform } from '../platform';
|
|
|
4
4
|
import { debounceTime, skipWhile, tap } from 'rxjs/operators';
|
|
5
5
|
import { Service, PlatformAccessory, CharacteristicValue, ControllerConstructor, Controller, ControllerServiceMap } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, switchbot, deviceStatusResponse, payload, hs2rgb, rgb2hs, deviceStatus } from '../settings';
|
|
7
|
+
import { Context } from 'vm';
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
@@ -79,7 +80,8 @@ export class StripLight {
|
|
|
79
80
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
80
81
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1701100')
|
|
81
82
|
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId!)
|
|
82
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision,
|
|
83
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision(accessory, device))
|
|
84
|
+
.getCharacteristic(this.platform.Characteristic.FirmwareRevision).updateValue(this.FirmwareRevision(accessory, device));
|
|
83
85
|
|
|
84
86
|
// get the Lightbulb service if it exists, otherwise create a new Lightbulb service
|
|
85
87
|
// you can create multiple services for each accessory
|
|
@@ -538,6 +540,21 @@ export class StripLight {
|
|
|
538
540
|
}
|
|
539
541
|
}
|
|
540
542
|
|
|
543
|
+
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
544
|
+
let FirmwareRevision: string;
|
|
545
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
546
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
547
|
+
this.debugLog(`Color Bulb: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
548
|
+
if (accessory.context.FirmwareRevision) {
|
|
549
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
550
|
+
} else if (device.firmware) {
|
|
551
|
+
FirmwareRevision = device.firmware;
|
|
552
|
+
} else {
|
|
553
|
+
FirmwareRevision = this.platform.version;
|
|
554
|
+
}
|
|
555
|
+
return FirmwareRevision;
|
|
556
|
+
}
|
|
557
|
+
|
|
541
558
|
minStep(device: device & devicesConfig): number {
|
|
542
559
|
if (device.colorbulb?.set_minStep) {
|
|
543
560
|
this.set_minStep = device.colorbulb?.set_minStep;
|
package/src/irdevice/other.ts
CHANGED
|
@@ -63,7 +63,7 @@ export class Others {
|
|
|
63
63
|
|
|
64
64
|
async ActiveSet(value: CharacteristicValue): Promise<void> {
|
|
65
65
|
this.debugLog(`Other: ${this.accessory.displayName} On: ${value}`);
|
|
66
|
-
if (
|
|
66
|
+
if (value) {
|
|
67
67
|
await this.pushOnChanges();
|
|
68
68
|
} else {
|
|
69
69
|
await this.pushOffChanges();
|
|
@@ -96,7 +96,7 @@ export class Others {
|
|
|
96
96
|
if (this.platform.config.options) {
|
|
97
97
|
if (this.device.other) {
|
|
98
98
|
if (this.device.other.commandOn) {
|
|
99
|
-
if (this.Active) {
|
|
99
|
+
if (!this.Active) {
|
|
100
100
|
const payload = {
|
|
101
101
|
commandType: 'customize',
|
|
102
102
|
parameter: 'default',
|
|
@@ -119,7 +119,7 @@ export class Others {
|
|
|
119
119
|
if (this.platform.config.options) {
|
|
120
120
|
if (this.device.other) {
|
|
121
121
|
if (this.device.other.commandOff) {
|
|
122
|
-
if (
|
|
122
|
+
if (this.Active) {
|
|
123
123
|
const payload = {
|
|
124
124
|
commandType: 'customize',
|
|
125
125
|
parameter: 'default',
|