@switchbot/homebridge-switchbot 2.9.1-beta.3 → 2.9.1
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/.eslintrc +47 -14
- package/.vscode/settings.json +7 -1
- package/CHANGELOG.md +79 -70
- package/SECURITY.md +2 -2
- package/config.schema.json +348 -114
- package/dist/device/blindtilt.d.ts +0 -3
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +13 -62
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +0 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +49 -116
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +0 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +17 -60
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +0 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +13 -56
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +0 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +19 -69
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +0 -3
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +16 -66
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +1 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +16 -69
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +0 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +16 -63
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +0 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +16 -65
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +0 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +13 -56
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +0 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +22 -68
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +0 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +16 -68
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +16 -69
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +0 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +12 -62
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +0 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +6 -53
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +0 -3
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +18 -65
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +0 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +9 -47
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +0 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +9 -47
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +0 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -47
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +0 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +9 -47
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +0 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +0 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +44 -77
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +0 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +18 -56
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +0 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -47
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +0 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -47
- package/dist/irdevice/waterheater.js.map +1 -1
- package/nodemon.json +4 -2
- package/package.json +9 -14
- package/src/device/blindtilt.ts +14 -62
- package/src/device/bot.ts +51 -108
- package/src/device/ceilinglight.ts +17 -61
- package/src/device/colorbulb.ts +13 -56
- package/src/device/contact.ts +20 -69
- package/src/device/curtain.ts +17 -66
- package/src/device/hub.ts +16 -70
- package/src/device/humidifier.ts +16 -64
- package/src/device/iosensor.ts +17 -66
- package/src/device/lightstrip.ts +13 -56
- package/src/device/lock.ts +22 -69
- package/src/device/meter.ts +18 -69
- package/src/device/meterplus.ts +17 -70
- package/src/device/motion.ts +13 -62
- package/src/device/plug.ts +6 -52
- package/src/device/robotvacuumcleaner.ts +18 -65
- package/src/irdevice/airconditioner.ts +9 -46
- package/src/irdevice/airpurifier.ts +9 -48
- package/src/irdevice/camera.ts +9 -48
- package/src/irdevice/fan.ts +9 -48
- package/src/irdevice/light.ts +9 -48
- package/src/irdevice/other.ts +44 -78
- package/src/irdevice/tv.ts +18 -57
- package/src/irdevice/vacuumcleaner.ts +9 -48
- package/src/irdevice/waterheater.ts +9 -48
- package/tsconfig.json +16 -4
- package/.github/npm-version-script.js +0 -81
- package/.prettierrc +0 -9
package/src/device/meter.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { MqttClient } from 'mqtt';
|
|
|
4
4
|
import { hostname } from 'os';
|
|
5
5
|
import { interval } from 'rxjs';
|
|
6
6
|
import { request } from 'undici';
|
|
7
|
-
import { Context } from 'vm';
|
|
8
7
|
import { SwitchBotPlatform } from '../platform';
|
|
9
8
|
import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature } from '../settings';
|
|
10
9
|
import { sleep } from '../utils';
|
|
@@ -78,20 +77,8 @@ export class Meter {
|
|
|
78
77
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
79
78
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
80
79
|
.setCharacteristic(this.platform.Characteristic.Model, 'METERTH-S1')
|
|
81
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId
|
|
82
|
-
|
|
83
|
-
if (accessory.context.FirmwareRevision) {
|
|
84
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
85
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
86
|
-
accessory
|
|
87
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
88
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
89
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
90
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
91
|
-
.updateValue(accessory.context.FirmwareRevision);
|
|
92
|
-
} else {
|
|
93
|
-
this.setFirmwareRevision(accessory, device);
|
|
94
|
-
}
|
|
80
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
|
|
81
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
95
82
|
|
|
96
83
|
// Temperature Sensor Service
|
|
97
84
|
if (device.meter?.hide_temperature) {
|
|
@@ -100,9 +87,9 @@ export class Meter {
|
|
|
100
87
|
accessory.removeService(this.temperatureService!);
|
|
101
88
|
} else if (!this.temperatureService) {
|
|
102
89
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
90
|
+
const temperatureService = `${accessory.displayName} Temperature Sensor`;
|
|
91
|
+
(this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor)
|
|
92
|
+
|| this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureService;
|
|
106
93
|
|
|
107
94
|
this.temperatureService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
108
95
|
if (!this.temperatureService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -131,9 +118,9 @@ export class Meter {
|
|
|
131
118
|
accessory.removeService(this.humidityService!);
|
|
132
119
|
} else if (!this.humidityService) {
|
|
133
120
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
121
|
+
const humidityService = `${accessory.displayName} Humidity Sensor`;
|
|
122
|
+
(this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor)
|
|
123
|
+
|| this.accessory.addService(this.platform.Service.HumiditySensor)), humidityService;
|
|
137
124
|
|
|
138
125
|
this.humidityService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
139
126
|
if (!this.humidityService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -152,8 +139,9 @@ export class Meter {
|
|
|
152
139
|
}
|
|
153
140
|
|
|
154
141
|
// Battery Service
|
|
155
|
-
|
|
156
|
-
|
|
142
|
+
const batteryService = `${accessory.displayName} Battery`;
|
|
143
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery)
|
|
144
|
+
|| accessory.addService(this.platform.Service.Battery)), batteryService;
|
|
157
145
|
|
|
158
146
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
159
147
|
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -250,10 +238,11 @@ export class Meter {
|
|
|
250
238
|
this.BatteryLevel = 100;
|
|
251
239
|
}
|
|
252
240
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
253
|
-
|
|
241
|
+
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
254
242
|
|
|
255
243
|
// FirmwareRevision
|
|
256
244
|
this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
|
|
245
|
+
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
257
246
|
}
|
|
258
247
|
|
|
259
248
|
/**
|
|
@@ -399,7 +388,7 @@ export class Meter {
|
|
|
399
388
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
400
389
|
this.humidityService?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
401
390
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
402
|
-
|
|
391
|
+
+ `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
403
392
|
}
|
|
404
393
|
}
|
|
405
394
|
// CurrentTemperature
|
|
@@ -439,24 +428,6 @@ export class Meter {
|
|
|
439
428
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
440
429
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
441
430
|
}
|
|
442
|
-
// FirmwareRevision
|
|
443
|
-
if (this.FirmwareRevision === undefined) {
|
|
444
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
|
|
445
|
-
} else {
|
|
446
|
-
if (this.device.mqttURL) {
|
|
447
|
-
mqttmessage.push(`"FirmwareRevision": ${this.FirmwareRevision}`);
|
|
448
|
-
}
|
|
449
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
450
|
-
this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
451
|
-
if (!this.device.meter?.hide_humidity) {
|
|
452
|
-
this.humidityService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
453
|
-
}
|
|
454
|
-
if (!this.device.meter?.hide_temperature) {
|
|
455
|
-
this.temperatureService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
456
|
-
}
|
|
457
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
458
|
-
+ `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
|
|
459
|
-
}
|
|
460
431
|
|
|
461
432
|
// MQTT
|
|
462
433
|
if (this.device.mqttURL) {
|
|
@@ -629,32 +600,6 @@ export class Meter {
|
|
|
629
600
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
630
601
|
}
|
|
631
602
|
|
|
632
|
-
async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
|
|
633
|
-
await this.refreshStatus();
|
|
634
|
-
if (device.firmware) {
|
|
635
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
636
|
-
accessory.context.FirmwareRevision = device.firmware;
|
|
637
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
638
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
639
|
-
} else if (device.version) {
|
|
640
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
|
|
641
|
-
accessory.context.FirmwareRevision = device.version;
|
|
642
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
643
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
644
|
-
} else {
|
|
645
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
646
|
-
accessory.context.FirmwareRevision = this.platform.version;
|
|
647
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
648
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
649
|
-
}
|
|
650
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
|
|
651
|
-
accessory
|
|
652
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
653
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
654
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
655
|
-
.updateValue(this.FirmwareRevision);
|
|
656
|
-
}
|
|
657
|
-
|
|
658
603
|
async context() {
|
|
659
604
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
660
605
|
this.CurrentRelativeHumidity = 0;
|
|
@@ -677,6 +622,10 @@ export class Meter {
|
|
|
677
622
|
} else {
|
|
678
623
|
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
679
624
|
}
|
|
625
|
+
if (this.FirmwareRevision === undefined) {
|
|
626
|
+
this.FirmwareRevision = this.platform.version;
|
|
627
|
+
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
628
|
+
}
|
|
680
629
|
}
|
|
681
630
|
|
|
682
631
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
package/src/device/meterplus.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { MqttClient } from 'mqtt';
|
|
|
4
4
|
import { hostname } from 'os';
|
|
5
5
|
import { interval } from 'rxjs';
|
|
6
6
|
import { request } from 'undici';
|
|
7
|
-
import { Context } from 'vm';
|
|
8
7
|
import { SwitchBotPlatform } from '../platform';
|
|
9
8
|
import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature } from '../settings';
|
|
10
9
|
import { sleep } from '../utils';
|
|
@@ -67,7 +66,7 @@ export class MeterPlus {
|
|
|
67
66
|
this.logs(device);
|
|
68
67
|
this.scan(device);
|
|
69
68
|
this.refreshRate(device);
|
|
70
|
-
this.context(
|
|
69
|
+
this.context();
|
|
71
70
|
this.setupHistoryService(device);
|
|
72
71
|
this.setupMqtt(device);
|
|
73
72
|
this.config(device);
|
|
@@ -80,20 +79,8 @@ export class MeterPlus {
|
|
|
80
79
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
81
80
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
82
81
|
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
83
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId
|
|
84
|
-
|
|
85
|
-
if (accessory.context.FirmwareRevision) {
|
|
86
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
87
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
88
|
-
accessory
|
|
89
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
90
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
91
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
92
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
93
|
-
.updateValue(accessory.context.FirmwareRevision);
|
|
94
|
-
} else {
|
|
95
|
-
this.setFirmwareRevision(accessory, device);
|
|
96
|
-
}
|
|
82
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
|
|
83
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
97
84
|
|
|
98
85
|
// Temperature Sensor Service
|
|
99
86
|
if (device.meter?.hide_temperature) {
|
|
@@ -102,9 +89,9 @@ export class MeterPlus {
|
|
|
102
89
|
accessory.removeService(this.temperatureService!);
|
|
103
90
|
} else if (!this.temperatureService) {
|
|
104
91
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
92
|
+
const temperatureService = `${accessory.displayName} Temperature Sensor`;
|
|
93
|
+
(this.temperatureService = this.accessory.getService(this.platform.Service.TemperatureSensor)
|
|
94
|
+
|| this.accessory.addService(this.platform.Service.TemperatureSensor)), temperatureService;
|
|
108
95
|
|
|
109
96
|
this.temperatureService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
110
97
|
if (!this.temperatureService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -133,9 +120,9 @@ export class MeterPlus {
|
|
|
133
120
|
accessory.removeService(this.humidityService!);
|
|
134
121
|
} else if (!this.humidityService) {
|
|
135
122
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
123
|
+
const humidityService = `${accessory.displayName} Humidity Sensor`;
|
|
124
|
+
(this.humidityService = this.accessory.getService(this.platform.Service.HumiditySensor)
|
|
125
|
+
|| this.accessory.addService(this.platform.Service.HumiditySensor)), humidityService;
|
|
139
126
|
|
|
140
127
|
this.humidityService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
141
128
|
if (!this.humidityService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -154,8 +141,9 @@ export class MeterPlus {
|
|
|
154
141
|
}
|
|
155
142
|
|
|
156
143
|
// Battery Service
|
|
157
|
-
|
|
158
|
-
|
|
144
|
+
const batteryService = `${accessory.displayName} Battery`;
|
|
145
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery)
|
|
146
|
+
|| accessory.addService(this.platform.Service.Battery)), batteryService;
|
|
159
147
|
|
|
160
148
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
161
149
|
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -252,10 +240,11 @@ export class MeterPlus {
|
|
|
252
240
|
this.BatteryLevel = 100;
|
|
253
241
|
}
|
|
254
242
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
255
|
-
|
|
243
|
+
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
256
244
|
|
|
257
245
|
// FirmwareRevision
|
|
258
246
|
this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
|
|
247
|
+
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
259
248
|
}
|
|
260
249
|
|
|
261
250
|
/**
|
|
@@ -444,25 +433,6 @@ export class MeterPlus {
|
|
|
444
433
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
445
434
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
446
435
|
}
|
|
447
|
-
// FirmwareRevision
|
|
448
|
-
if (this.FirmwareRevision === undefined) {
|
|
449
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
|
|
450
|
-
} else {
|
|
451
|
-
if (this.device.mqttURL) {
|
|
452
|
-
mqttmessage.push(`"FirmwareRevision": ${this.FirmwareRevision}`);
|
|
453
|
-
}
|
|
454
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
455
|
-
|
|
456
|
-
this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
457
|
-
if (!this.device.meter?.hide_humidity) {
|
|
458
|
-
this.humidityService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
459
|
-
}
|
|
460
|
-
if (!this.device.meter?.hide_temperature) {
|
|
461
|
-
this.temperatureService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
462
|
-
}
|
|
463
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
464
|
-
+ `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
|
|
465
|
-
}
|
|
466
436
|
|
|
467
437
|
// MQTT
|
|
468
438
|
if (this.device.mqttURL) {
|
|
@@ -629,7 +599,7 @@ export class MeterPlus {
|
|
|
629
599
|
|
|
630
600
|
async offlineOff(): Promise<void> {
|
|
631
601
|
if (this.device.offline) {
|
|
632
|
-
await this.context(
|
|
602
|
+
await this.context();
|
|
633
603
|
await this.updateHomeKitCharacteristics();
|
|
634
604
|
}
|
|
635
605
|
}
|
|
@@ -645,28 +615,7 @@ export class MeterPlus {
|
|
|
645
615
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
646
616
|
}
|
|
647
617
|
|
|
648
|
-
async
|
|
649
|
-
await this.refreshStatus();
|
|
650
|
-
if (device.firmware) {
|
|
651
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
652
|
-
accessory.context.FirmwareRevision = device.firmware;
|
|
653
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
654
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
655
|
-
} else {
|
|
656
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
|
|
657
|
-
accessory.context.FirmwareRevision = device.version;
|
|
658
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
659
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
660
|
-
}
|
|
661
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
|
|
662
|
-
accessory
|
|
663
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
664
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
665
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
666
|
-
.updateValue(this.FirmwareRevision);
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
async context(accessory, device) {
|
|
618
|
+
async context() {
|
|
670
619
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
671
620
|
this.CurrentRelativeHumidity = 0;
|
|
672
621
|
} else {
|
|
@@ -690,9 +639,7 @@ export class MeterPlus {
|
|
|
690
639
|
}
|
|
691
640
|
if (this.FirmwareRevision === undefined) {
|
|
692
641
|
this.FirmwareRevision = this.platform.version;
|
|
693
|
-
|
|
694
|
-
this.setFirmwareRevision(accessory, device);
|
|
695
|
-
this.FirmwareRevision = this.accessory.context.FirmwareRevision;
|
|
642
|
+
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
696
643
|
}
|
|
697
644
|
}
|
|
698
645
|
|
package/src/device/motion.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Context } from 'vm';
|
|
2
1
|
import { request } from 'undici';
|
|
3
2
|
import { sleep } from '../utils';
|
|
4
3
|
import { interval, Subject } from 'rxjs';
|
|
@@ -79,25 +78,14 @@ export class Motion {
|
|
|
79
78
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
80
79
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
81
80
|
.setCharacteristic(this.platform.Characteristic.Model, 'W1101500')
|
|
82
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId
|
|
83
|
-
|
|
84
|
-
if (accessory.context.FirmwareRevision) {
|
|
85
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
86
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
87
|
-
accessory
|
|
88
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
89
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
90
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
91
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
92
|
-
.updateValue(accessory.context.FirmwareRevision);
|
|
93
|
-
} else {
|
|
94
|
-
this.setFirmwareRevision(accessory, device);
|
|
95
|
-
}
|
|
81
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
|
|
82
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
96
83
|
|
|
97
84
|
// get the Battery service if it exists, otherwise create a new Motion service
|
|
98
85
|
// you can create multiple services for each accessory
|
|
99
|
-
|
|
100
|
-
|
|
86
|
+
const motionSensorService = `${accessory.displayName} Motion Sensor`;
|
|
87
|
+
(this.motionSensorService = accessory.getService(this.platform.Service.MotionSensor)
|
|
88
|
+
|| accessory.addService(this.platform.Service.MotionSensor)), motionSensorService;
|
|
101
89
|
|
|
102
90
|
this.motionSensorService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
103
91
|
if (!this.motionSensorService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -113,9 +101,9 @@ export class Motion {
|
|
|
113
101
|
accessory.removeService(this.lightSensorService!);
|
|
114
102
|
} else if (!this.lightSensorService) {
|
|
115
103
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Light Sensor Service`);
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
104
|
+
const lightSensorService = `${accessory.displayName} Light Sensor`;
|
|
105
|
+
(this.lightSensorService = this.accessory.getService(this.platform.Service.LightSensor)
|
|
106
|
+
|| this.accessory.addService(this.platform.Service.LightSensor)), lightSensorService;
|
|
119
107
|
|
|
120
108
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Light Sensor`);
|
|
121
109
|
this.lightSensorService.setCharacteristic(this.platform.Characteristic.ConfiguredName, `${accessory.displayName} Light Sensor`);
|
|
@@ -124,8 +112,9 @@ export class Motion {
|
|
|
124
112
|
}
|
|
125
113
|
|
|
126
114
|
// Battery Service
|
|
127
|
-
|
|
128
|
-
|
|
115
|
+
const batteryService = `${accessory.displayName} Battery`;
|
|
116
|
+
(this.batteryService = this.accessory.getService(this.platform.Service.Battery)
|
|
117
|
+
|| accessory.addService(this.platform.Service.Battery)), batteryService;
|
|
129
118
|
|
|
130
119
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
131
120
|
if (!this.batteryService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -236,10 +225,11 @@ export class Motion {
|
|
|
236
225
|
this.BatteryLevel = 100;
|
|
237
226
|
}
|
|
238
227
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
239
|
-
|
|
228
|
+
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
240
229
|
|
|
241
230
|
// FirmwareRevision
|
|
242
231
|
this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
|
|
232
|
+
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
243
233
|
}
|
|
244
234
|
|
|
245
235
|
/**
|
|
@@ -412,19 +402,6 @@ export class Motion {
|
|
|
412
402
|
);
|
|
413
403
|
}
|
|
414
404
|
}
|
|
415
|
-
// FirmwareRevision
|
|
416
|
-
if (this.FirmwareRevision === undefined) {
|
|
417
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
|
|
418
|
-
} else {
|
|
419
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
420
|
-
this.motionSensorService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
421
|
-
this.batteryService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
422
|
-
if (!this.device.motion?.hide_lightsensor) {
|
|
423
|
-
this.lightSensorService!.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
424
|
-
}
|
|
425
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
426
|
-
+ `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
|
|
427
|
-
}
|
|
428
405
|
}
|
|
429
406
|
|
|
430
407
|
async stopScanning(switchbot: any) {
|
|
@@ -573,32 +550,6 @@ export class Motion {
|
|
|
573
550
|
}
|
|
574
551
|
}
|
|
575
552
|
|
|
576
|
-
async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
|
|
577
|
-
await this.refreshStatus();
|
|
578
|
-
if (device.firmware) {
|
|
579
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
580
|
-
accessory.context.FirmwareRevision = device.firmware;
|
|
581
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
582
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
583
|
-
} else if (device.version) {
|
|
584
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
|
|
585
|
-
accessory.context.FirmwareRevision = device.version;
|
|
586
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
587
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
588
|
-
} else {
|
|
589
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
590
|
-
accessory.context.FirmwareRevision = this.platform.version;
|
|
591
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
592
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
593
|
-
}
|
|
594
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
|
|
595
|
-
accessory
|
|
596
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
597
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
598
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
599
|
-
.updateValue(this.FirmwareRevision);
|
|
600
|
-
}
|
|
601
|
-
|
|
602
553
|
async context() {
|
|
603
554
|
if (this.MotionDetected === undefined) {
|
|
604
555
|
this.MotionDetected = false;
|
package/src/device/plug.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { Context } from 'vm';
|
|
2
1
|
import { request } from 'undici';
|
|
3
2
|
import { sleep } from '../utils';
|
|
4
3
|
import { interval, Subject } from 'rxjs';
|
|
@@ -60,25 +59,14 @@ export class Plug {
|
|
|
60
59
|
.getService(this.platform.Service.AccessoryInformation)!
|
|
61
60
|
.setCharacteristic(this.platform.Characteristic.Manufacturer, 'SwitchBot')
|
|
62
61
|
.setCharacteristic(this.platform.Characteristic.Model, this.model(device))
|
|
63
|
-
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId
|
|
64
|
-
|
|
65
|
-
if (accessory.context.FirmwareRevision) {
|
|
66
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
67
|
-
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
68
|
-
accessory
|
|
69
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
70
|
-
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
71
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
72
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
73
|
-
.updateValue(accessory.context.FirmwareRevision);
|
|
74
|
-
} else {
|
|
75
|
-
this.setFirmwareRevision(accessory, device);
|
|
76
|
-
}
|
|
62
|
+
.setCharacteristic(this.platform.Characteristic.SerialNumber, device.deviceId)
|
|
63
|
+
.setCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
77
64
|
|
|
78
65
|
// get the Outlet service if it exists, otherwise create a new Outlet service
|
|
79
66
|
// you can create multiple services for each accessory
|
|
80
|
-
|
|
81
|
-
|
|
67
|
+
const outletService = `${accessory.displayName} ${device.deviceType}`;
|
|
68
|
+
(this.outletService = accessory.getService(this.platform.Service.Outlet)
|
|
69
|
+
|| accessory.addService(this.platform.Service.Outlet)), outletService;
|
|
82
70
|
|
|
83
71
|
this.outletService.setCharacteristic(this.platform.Characteristic.Name, accessory.displayName);
|
|
84
72
|
if (!this.outletService.testCharacteristic(this.platform.Characteristic.ConfiguredName)) {
|
|
@@ -167,6 +155,7 @@ export class Plug {
|
|
|
167
155
|
|
|
168
156
|
// FirmwareRevision
|
|
169
157
|
this.FirmwareRevision = this.OpenAPI_FirmwareRevision!;
|
|
158
|
+
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
170
159
|
}
|
|
171
160
|
|
|
172
161
|
/**
|
|
@@ -435,15 +424,6 @@ export class Plug {
|
|
|
435
424
|
this.outletService.updateCharacteristic(this.platform.Characteristic.On, this.On);
|
|
436
425
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic On: ${this.On}`);
|
|
437
426
|
}
|
|
438
|
-
// FirmwareRevision
|
|
439
|
-
if (this.FirmwareRevision === undefined) {
|
|
440
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} FirmwareRevision: ${this.FirmwareRevision}`);
|
|
441
|
-
} else {
|
|
442
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
443
|
-
this.outletService.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, this.FirmwareRevision);
|
|
444
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
445
|
-
+ `updateCharacteristic FirmwareRevision: ${this.FirmwareRevision}`);
|
|
446
|
-
}
|
|
447
427
|
}
|
|
448
428
|
|
|
449
429
|
async stopScanning(switchbot: any) {
|
|
@@ -597,32 +577,6 @@ export class Plug {
|
|
|
597
577
|
this.outletService.updateCharacteristic(this.platform.Characteristic.On, e);
|
|
598
578
|
}
|
|
599
579
|
|
|
600
|
-
async setFirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig) {
|
|
601
|
-
await this.refreshStatus();
|
|
602
|
-
if (device.firmware) {
|
|
603
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
604
|
-
accessory.context.FirmwareRevision = device.firmware;
|
|
605
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
606
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
607
|
-
} else if (device.version) {
|
|
608
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version: ${device.version}`);
|
|
609
|
-
accessory.context.FirmwareRevision = device.version;
|
|
610
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
611
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} device.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
612
|
-
} else {
|
|
613
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
614
|
-
accessory.context.FirmwareRevision = this.platform.version;
|
|
615
|
-
this.FirmwareRevision = accessory.context.FirmwareRevision;
|
|
616
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version, FirmwareRevision: ${this.FirmwareRevision}`);
|
|
617
|
-
}
|
|
618
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} setFirmwareRevision: ${this.FirmwareRevision}`);
|
|
619
|
-
accessory
|
|
620
|
-
.getService(this.platform.Service.AccessoryInformation)!
|
|
621
|
-
.updateCharacteristic(this.platform.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision)
|
|
622
|
-
.getCharacteristic(this.platform.Characteristic.FirmwareRevision)
|
|
623
|
-
.updateValue(this.FirmwareRevision);
|
|
624
|
-
}
|
|
625
|
-
|
|
626
580
|
async context() {
|
|
627
581
|
if (this.On === undefined) {
|
|
628
582
|
this.On = false;
|