@switchbot/homebridge-switchbot 2.14.0 → 3.0.0-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/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/dependabot.yml +10 -11
- package/CHANGELOG.md +11 -2
- package/LICENSE +1 -1
- package/config.schema.json +1 -0
- package/dist/device/blindtilt.d.ts +9 -5
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +151 -91
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -5
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +234 -184
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -5
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +110 -64
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +9 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +121 -69
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +111 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +9 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +164 -107
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +87 -51
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +9 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +133 -90
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +108 -66
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +9 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +110 -65
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -6
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +125 -84
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +102 -63
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +102 -63
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +95 -54
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -5
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +68 -40
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -5
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +86 -52
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/homebridge-ui/server.d.ts +2 -0
- package/dist/homebridge-ui/server.d.ts.map +1 -0
- package/dist/homebridge-ui/server.js +44 -0
- package/dist/homebridge-ui/server.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -4
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +105 -71
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -4
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +78 -46
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -4
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +41 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -4
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +62 -39
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -4
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +67 -45
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -4
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +176 -150
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -4
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +81 -62
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -4
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -25
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -4
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +48 -32
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +8 -9
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +147 -162
- package/dist/platform.js.map +1 -1
- package/dist/settings.js +7 -14
- package/dist/settings.js.map +1 -1
- package/dist/utils.js +1 -5
- package/dist/utils.js.map +1 -1
- package/package.json +28 -16
- package/src/device/blindtilt.ts +80 -69
- package/src/device/bot.ts +189 -178
- package/src/device/ceilinglight.ts +55 -42
- package/src/device/colorbulb.ts +51 -38
- package/src/device/contact.ts +69 -58
- package/src/device/curtain.ts +94 -83
- package/src/device/hub.ts +54 -43
- package/src/device/humidifier.ts +86 -75
- package/src/device/iosensor.ts +63 -52
- package/src/device/lightstrip.ts +54 -41
- package/src/device/lock.ts +89 -79
- package/src/device/meter.ts +59 -48
- package/src/device/meterplus.ts +63 -52
- package/src/device/motion.ts +56 -45
- package/src/device/plug.ts +36 -25
- package/src/device/robotvacuumcleaner.ts +47 -36
- package/src/homebridge-ui/public/index.html +240 -0
- package/src/homebridge-ui/server.ts +48 -0
- package/src/index.ts +10 -7
- package/src/irdevice/airconditioner.ts +70 -62
- package/src/irdevice/airpurifier.ts +47 -39
- package/src/irdevice/camera.ts +27 -19
- package/src/irdevice/fan.ts +41 -33
- package/src/irdevice/light.ts +47 -39
- package/src/irdevice/other.ts +163 -155
- package/src/irdevice/tv.ts +65 -57
- package/src/irdevice/vacuumcleaner.ts +27 -19
- package/src/irdevice/waterheater.ts +34 -26
- package/src/platform.ts +35 -21
- package/tsconfig.json +11 -13
- package/homebridge-ui/server.js +0 -50
- /package/{homebridge-ui → dist/homebridge-ui}/public/index.html +0 -0
package/src/device/lock.ts
CHANGED
|
@@ -3,10 +3,14 @@ import { sleep } from '../utils';
|
|
|
3
3
|
import { interval, Subject } from 'rxjs';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
5
|
import { debounceTime, skipWhile, take, tap } from 'rxjs/operators';
|
|
6
|
-
import { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
7
|
-
import { device, devicesConfig, deviceStatus, ad, Devices, serviceData } from '../settings';
|
|
6
|
+
import { Service, PlatformAccessory, CharacteristicValue, API, Logging, HAP } from 'homebridge';
|
|
7
|
+
import { device, devicesConfig, deviceStatus, ad, Devices, serviceData, SwitchBotPlatformConfig } from '../settings';
|
|
8
8
|
|
|
9
9
|
export class Lock {
|
|
10
|
+
public readonly api: API;
|
|
11
|
+
public readonly log: Logging;
|
|
12
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
13
|
+
protected readonly hap: HAP;
|
|
10
14
|
// Services
|
|
11
15
|
lockService: Service;
|
|
12
16
|
batteryService: Service;
|
|
@@ -46,20 +50,27 @@ export class Lock {
|
|
|
46
50
|
doLockUpdate!: Subject<void>;
|
|
47
51
|
|
|
48
52
|
// Connection
|
|
49
|
-
private readonly
|
|
50
|
-
private readonly
|
|
53
|
+
private readonly OpenAPI: boolean;
|
|
54
|
+
private readonly BLE: boolean;
|
|
51
55
|
|
|
52
56
|
constructor(
|
|
53
57
|
private readonly platform: SwitchBotPlatform,
|
|
54
58
|
private accessory: PlatformAccessory,
|
|
55
59
|
public device: device & devicesConfig,
|
|
56
60
|
) {
|
|
61
|
+
this.api = this.platform.api;
|
|
62
|
+
this.log = this.platform.log;
|
|
63
|
+
this.config = this.platform.config;
|
|
64
|
+
this.hap = this.api.hap;
|
|
65
|
+
// Connection
|
|
66
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
67
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
57
68
|
// default placeholders
|
|
58
|
-
this.
|
|
69
|
+
this.deviceLogs(device);
|
|
59
70
|
this.scan(device);
|
|
60
71
|
this.refreshRate(device);
|
|
61
72
|
this.context();
|
|
62
|
-
this.
|
|
73
|
+
this.deviceConfig(device);
|
|
63
74
|
|
|
64
75
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
65
76
|
this.doLockUpdate = new Subject();
|
|
@@ -70,21 +81,21 @@ export class Lock {
|
|
|
70
81
|
|
|
71
82
|
// set accessory information
|
|
72
83
|
accessory
|
|
73
|
-
.getService(this.
|
|
74
|
-
.setCharacteristic(this.
|
|
75
|
-
.setCharacteristic(this.
|
|
76
|
-
.setCharacteristic(this.
|
|
77
|
-
.setCharacteristic(this.
|
|
84
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
85
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
86
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'W1601700')
|
|
87
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
88
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
78
89
|
|
|
79
90
|
// get the LockMechanism service if it exists, otherwise create a new LockMechanism service
|
|
80
91
|
// you can create multiple services for each accessory
|
|
81
92
|
const lockService = `${accessory.displayName} ${device.deviceType}`;
|
|
82
|
-
(this.lockService = accessory.getService(this.
|
|
83
|
-
|| accessory.addService(this.
|
|
93
|
+
(this.lockService = accessory.getService(this.hap.Service.LockMechanism)
|
|
94
|
+
|| accessory.addService(this.hap.Service.LockMechanism)), lockService;
|
|
84
95
|
|
|
85
|
-
this.lockService.setCharacteristic(this.
|
|
86
|
-
if (!this.lockService.testCharacteristic(this.
|
|
87
|
-
this.lockService.addCharacteristic(this.
|
|
96
|
+
this.lockService.setCharacteristic(this.hap.Characteristic.Name, accessory.displayName);
|
|
97
|
+
if (!this.lockService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
98
|
+
this.lockService.addCharacteristic(this.hap.Characteristic.ConfiguredName, accessory.displayName);
|
|
88
99
|
}
|
|
89
100
|
|
|
90
101
|
// each service must implement at-minimum the "required characteristics" for the given service type
|
|
@@ -92,32 +103,31 @@ export class Lock {
|
|
|
92
103
|
|
|
93
104
|
|
|
94
105
|
// create handlers for required characteristics
|
|
95
|
-
this.lockService.getCharacteristic(this.
|
|
106
|
+
this.lockService.getCharacteristic(this.hap.Characteristic.LockTargetState).onSet(this.LockTargetStateSet.bind(this));
|
|
96
107
|
|
|
97
108
|
|
|
98
109
|
// Latch Button Service
|
|
99
110
|
if (device.lock?.activate_latchbutton === false) { // remove the service when this variable is false
|
|
100
111
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Latch Button Service`);
|
|
101
|
-
this.latchButtonService = accessory.getService(this.
|
|
112
|
+
this.latchButtonService = accessory.getService(this.hap.Service.Switch);
|
|
102
113
|
if (this.latchButtonService) {
|
|
103
114
|
accessory.removeService(this.latchButtonService);
|
|
104
115
|
this.latchButtonService = undefined; // Reset the service variable to undefined
|
|
105
116
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|| accessory.addService(this.platform.Service.Switch, latchServiceName, 'LatchButtonServiceIdentifier');
|
|
117
|
+
} else
|
|
118
|
+
if (!this.latchButtonService) {
|
|
119
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Adding Latch Button Service`);
|
|
120
|
+
const latchServiceName = `${accessory.displayName} Latch`;
|
|
121
|
+
this.latchButtonService = accessory.getService(this.hap.Service.Switch)
|
|
122
|
+
|| accessory.addService(this.hap.Service.Switch, latchServiceName, 'LatchButtonServiceIdentifier');
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
this.latchButtonService.setCharacteristic(this.hap.Characteristic.Name, latchServiceName);
|
|
115
125
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
if (!this.latchButtonService.testCharacteristic(this.hap.Characteristic.On)) {
|
|
127
|
+
this.latchButtonService.addCharacteristic(this.hap.Characteristic.On);
|
|
128
|
+
}
|
|
119
129
|
|
|
120
|
-
|
|
130
|
+
this.latchButtonService.getCharacteristic(this.hap.Characteristic.On)
|
|
121
131
|
.on('set', (value, callback) => {
|
|
122
132
|
if (typeof value === 'boolean') {
|
|
123
133
|
this.handleLatchCharacteristic(value, callback);
|
|
@@ -125,25 +135,25 @@ export class Lock {
|
|
|
125
135
|
callback(new Error('Wrong characteristic value type'));
|
|
126
136
|
}
|
|
127
137
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
138
|
+
} else {
|
|
139
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Latch Button Service already exists`);
|
|
140
|
+
}
|
|
131
141
|
|
|
132
142
|
|
|
133
143
|
// Contact Sensor Service
|
|
134
144
|
if (device.lock?.hide_contactsensor) {
|
|
135
145
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Contact Sensor Service`);
|
|
136
|
-
this.contactSensorService = this.accessory.getService(this.
|
|
146
|
+
this.contactSensorService = this.accessory.getService(this.hap.Service.ContactSensor);
|
|
137
147
|
accessory.removeService(this.contactSensorService!);
|
|
138
148
|
} else if (!this.contactSensorService) {
|
|
139
149
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Contact Sensor Service`);
|
|
140
150
|
const contactSensorService = `${accessory.displayName} Contact Sensor`;
|
|
141
|
-
(this.contactSensorService = this.accessory.getService(this.
|
|
142
|
-
|| this.accessory.addService(this.
|
|
151
|
+
(this.contactSensorService = this.accessory.getService(this.hap.Service.ContactSensor)
|
|
152
|
+
|| this.accessory.addService(this.hap.Service.ContactSensor)), contactSensorService;
|
|
143
153
|
|
|
144
|
-
this.contactSensorService.setCharacteristic(this.
|
|
145
|
-
if (!this.contactSensorService.testCharacteristic(this.
|
|
146
|
-
this.contactSensorService.addCharacteristic(this.
|
|
154
|
+
this.contactSensorService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Contact Sensor`);
|
|
155
|
+
if (!this.contactSensorService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
156
|
+
this.contactSensorService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Contact Sensor`);
|
|
147
157
|
}
|
|
148
158
|
} else {
|
|
149
159
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Contact Sensor Service Not Added`);
|
|
@@ -151,14 +161,14 @@ export class Lock {
|
|
|
151
161
|
|
|
152
162
|
// Battery Service
|
|
153
163
|
const batteryService = `${accessory.displayName} Battery`;
|
|
154
|
-
(this.batteryService = this.accessory.getService(this.
|
|
155
|
-
|| accessory.addService(this.
|
|
164
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
165
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
156
166
|
|
|
157
|
-
this.batteryService.setCharacteristic(this.
|
|
158
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
159
|
-
this.batteryService.addCharacteristic(this.
|
|
167
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
168
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
169
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
160
170
|
}
|
|
161
|
-
this.batteryService.setCharacteristic(this.
|
|
171
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
162
172
|
|
|
163
173
|
// Update Homekit
|
|
164
174
|
this.updateHomeKitCharacteristics();
|
|
@@ -179,14 +189,14 @@ export class Lock {
|
|
|
179
189
|
const { lockState } = context;
|
|
180
190
|
const { LockCurrentState } = this;
|
|
181
191
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
192
|
+
'(lockState) = ' +
|
|
193
|
+
`Webhook:(${lockState}), ` +
|
|
194
|
+
`current:(${LockCurrentState})`);
|
|
185
195
|
this.LockCurrentState = lockState === 'LOCKED' ? 1 : 0;
|
|
186
196
|
this.updateHomeKitCharacteristics();
|
|
187
197
|
} catch (e: any) {
|
|
188
198
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
189
|
-
|
|
199
|
+
+ `failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
190
200
|
}
|
|
191
201
|
};
|
|
192
202
|
}
|
|
@@ -217,7 +227,7 @@ export class Lock {
|
|
|
217
227
|
/**
|
|
218
228
|
* Method for handling the LatchCharacteristic
|
|
219
229
|
*/
|
|
220
|
-
|
|
230
|
+
async handleLatchCharacteristic(value: boolean, callback) {
|
|
221
231
|
this.debugLog(`handleLatchCharacteristic called with value: ${value}`);
|
|
222
232
|
|
|
223
233
|
if (value) {
|
|
@@ -232,7 +242,7 @@ export class Lock {
|
|
|
232
242
|
const latchButtonService = this.latchButtonService;
|
|
233
243
|
// Simulate a button press by waiting a short period before turning the switch off
|
|
234
244
|
setTimeout(() => {
|
|
235
|
-
latchButtonService.getCharacteristic(this.
|
|
245
|
+
latchButtonService.getCharacteristic(this.hap.Characteristic.On).updateValue(false);
|
|
236
246
|
this.debugLog('Latch button switched off automatically.');
|
|
237
247
|
}, 500); // 500 ms delay
|
|
238
248
|
}
|
|
@@ -243,7 +253,7 @@ export class Lock {
|
|
|
243
253
|
|
|
244
254
|
// Ensure we turn the switch back off even in case of an error
|
|
245
255
|
if (this.latchButtonService) {
|
|
246
|
-
this.latchButtonService.getCharacteristic(this.
|
|
256
|
+
this.latchButtonService.getCharacteristic(this.hap.Characteristic.On).updateValue(false);
|
|
247
257
|
this.debugLog('Latch button switched off after an error.');
|
|
248
258
|
}
|
|
249
259
|
|
|
@@ -279,27 +289,27 @@ export class Lock {
|
|
|
279
289
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
280
290
|
switch (this.BLE_LockCurrentState) {
|
|
281
291
|
case 'locked':
|
|
282
|
-
this.LockCurrentState = this.
|
|
283
|
-
this.LockTargetState = this.
|
|
292
|
+
this.LockCurrentState = this.hap.Characteristic.LockCurrentState.SECURED;
|
|
293
|
+
this.LockTargetState = this.hap.Characteristic.LockTargetState.SECURED;
|
|
284
294
|
break;
|
|
285
295
|
default:
|
|
286
|
-
this.LockCurrentState = this.
|
|
287
|
-
this.LockTargetState = this.
|
|
296
|
+
this.LockCurrentState = this.hap.Characteristic.LockCurrentState.UNSECURED;
|
|
297
|
+
this.LockTargetState = this.hap.Characteristic.LockTargetState.UNSECURED;
|
|
288
298
|
}
|
|
289
299
|
switch (this.BLE_ContactSensorState) {
|
|
290
300
|
case 'opened':
|
|
291
|
-
this.ContactSensorState = this.
|
|
301
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
292
302
|
break;
|
|
293
303
|
default:
|
|
294
|
-
this.ContactSensorState = this.
|
|
304
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
295
305
|
}
|
|
296
306
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
|
|
297
307
|
// Battery
|
|
298
308
|
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
299
309
|
if (this.BatteryLevel < 10) {
|
|
300
|
-
this.StatusLowBattery = this.
|
|
310
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
301
311
|
} else {
|
|
302
|
-
this.StatusLowBattery = this.
|
|
312
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
303
313
|
}
|
|
304
314
|
this.debugLog(
|
|
305
315
|
`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},` + ` StatusLowBattery: ${this.StatusLowBattery}`,
|
|
@@ -310,28 +320,28 @@ export class Lock {
|
|
|
310
320
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
311
321
|
switch (this.OpenAPI_LockCurrentState) {
|
|
312
322
|
case 'locked':
|
|
313
|
-
this.LockCurrentState = this.
|
|
314
|
-
this.LockTargetState = this.
|
|
323
|
+
this.LockCurrentState = this.hap.Characteristic.LockCurrentState.SECURED;
|
|
324
|
+
this.LockTargetState = this.hap.Characteristic.LockTargetState.SECURED;
|
|
315
325
|
break;
|
|
316
326
|
default:
|
|
317
|
-
this.LockCurrentState = this.
|
|
318
|
-
this.LockTargetState = this.
|
|
327
|
+
this.LockCurrentState = this.hap.Characteristic.LockCurrentState.UNSECURED;
|
|
328
|
+
this.LockTargetState = this.hap.Characteristic.LockTargetState.UNSECURED;
|
|
319
329
|
}
|
|
320
330
|
switch (this.OpenAPI_ContactSensorState) {
|
|
321
331
|
case 'opened':
|
|
322
|
-
this.ContactSensorState = this.
|
|
332
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED;
|
|
323
333
|
break;
|
|
324
334
|
default:
|
|
325
|
-
this.ContactSensorState = this.
|
|
335
|
+
this.ContactSensorState = this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED;
|
|
326
336
|
}
|
|
327
337
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} On: ${this.LockTargetState}`);
|
|
328
338
|
|
|
329
339
|
// Battery
|
|
330
340
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
331
341
|
if (this.BatteryLevel < 10) {
|
|
332
|
-
this.StatusLowBattery = this.
|
|
342
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
333
343
|
} else {
|
|
334
|
-
this.StatusLowBattery = this.
|
|
344
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
335
345
|
}
|
|
336
346
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
337
347
|
this.BatteryLevel = 100;
|
|
@@ -511,7 +521,7 @@ export class Lock {
|
|
|
511
521
|
})
|
|
512
522
|
.then(() => {
|
|
513
523
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Done.`);
|
|
514
|
-
this.LockTargetState = this.
|
|
524
|
+
this.LockTargetState = this.hap.Characteristic.LockTargetState.SECURED;
|
|
515
525
|
})
|
|
516
526
|
.catch(async (e: any) => {
|
|
517
527
|
this.apiError(e);
|
|
@@ -603,7 +613,7 @@ export class Lock {
|
|
|
603
613
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ContactSensorState: ${this.ContactSensorState}`);
|
|
604
614
|
} else {
|
|
605
615
|
this.accessory.context.ContactSensorState = this.ContactSensorState;
|
|
606
|
-
this.contactSensorService?.updateCharacteristic(this.
|
|
616
|
+
this.contactSensorService?.updateCharacteristic(this.hap.Characteristic.ContactSensorState, this.ContactSensorState);
|
|
607
617
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic ContactSensorState: ${this.ContactSensorState}`);
|
|
608
618
|
}
|
|
609
619
|
}
|
|
@@ -611,28 +621,28 @@ export class Lock {
|
|
|
611
621
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LockTargetState: ${this.LockTargetState}`);
|
|
612
622
|
} else {
|
|
613
623
|
this.accessory.context.LockTargetState = this.LockTargetState;
|
|
614
|
-
this.lockService.updateCharacteristic(this.
|
|
624
|
+
this.lockService.updateCharacteristic(this.hap.Characteristic.LockTargetState, this.LockTargetState);
|
|
615
625
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LockTargetState: ${this.LockTargetState}`);
|
|
616
626
|
}
|
|
617
627
|
if (this.LockCurrentState === undefined) {
|
|
618
628
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LockCurrentState: ${this.LockCurrentState}`);
|
|
619
629
|
} else {
|
|
620
630
|
this.accessory.context.LockCurrentState = this.LockCurrentState;
|
|
621
|
-
this.lockService.updateCharacteristic(this.
|
|
631
|
+
this.lockService.updateCharacteristic(this.hap.Characteristic.LockCurrentState, this.LockCurrentState);
|
|
622
632
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LockCurrentState: ${this.LockCurrentState}`);
|
|
623
633
|
}
|
|
624
634
|
if (this.BatteryLevel === undefined) {
|
|
625
635
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
626
636
|
} else {
|
|
627
637
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
628
|
-
this.batteryService?.updateCharacteristic(this.
|
|
638
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
629
639
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
630
640
|
}
|
|
631
641
|
if (this.StatusLowBattery === undefined) {
|
|
632
642
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
633
643
|
} else {
|
|
634
644
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
635
|
-
this.batteryService?.updateCharacteristic(this.
|
|
645
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
636
646
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
637
647
|
}
|
|
638
648
|
}
|
|
@@ -745,10 +755,10 @@ export class Lock {
|
|
|
745
755
|
|
|
746
756
|
async apiError(e: any): Promise<void> {
|
|
747
757
|
if (!this.device.lock?.hide_contactsensor) {
|
|
748
|
-
this.contactSensorService?.updateCharacteristic(this.
|
|
758
|
+
this.contactSensorService?.updateCharacteristic(this.hap.Characteristic.ContactSensorState, e);
|
|
749
759
|
}
|
|
750
|
-
this.lockService.updateCharacteristic(this.
|
|
751
|
-
this.lockService.updateCharacteristic(this.
|
|
760
|
+
this.lockService.updateCharacteristic(this.hap.Characteristic.LockTargetState, e);
|
|
761
|
+
this.lockService.updateCharacteristic(this.hap.Characteristic.LockCurrentState, e);
|
|
752
762
|
}
|
|
753
763
|
|
|
754
764
|
async context() {
|
|
@@ -773,7 +783,7 @@ export class Lock {
|
|
|
773
783
|
}
|
|
774
784
|
}
|
|
775
785
|
|
|
776
|
-
async
|
|
786
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
777
787
|
let config = {};
|
|
778
788
|
if (device.lock) {
|
|
779
789
|
config = device.lock;
|
|
@@ -798,7 +808,7 @@ export class Lock {
|
|
|
798
808
|
}
|
|
799
809
|
}
|
|
800
810
|
|
|
801
|
-
async
|
|
811
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
802
812
|
if (this.platform.debugMode) {
|
|
803
813
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
804
814
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
package/src/device/meter.ts
CHANGED
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { connectAsync } from 'async-mqtt';
|
|
2
|
-
import { CharacteristicValue, PlatformAccessory, Service, Units } from 'homebridge';
|
|
2
|
+
import { CharacteristicValue, PlatformAccessory, Service, Units, API, Logging, HAP } from 'homebridge';
|
|
3
3
|
import { MqttClient } from 'mqtt';
|
|
4
4
|
import { hostname } from 'os';
|
|
5
5
|
import { interval } from 'rxjs';
|
|
6
6
|
import { request } from 'undici';
|
|
7
7
|
import { SwitchBotPlatform } from '../platform';
|
|
8
|
-
import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature } from '../settings';
|
|
8
|
+
import { Devices, ad, device, deviceStatus, devicesConfig, serviceData, temperature, SwitchBotPlatformConfig } from '../settings';
|
|
9
9
|
import { sleep } from '../utils';
|
|
10
10
|
|
|
11
11
|
export class Meter {
|
|
12
|
+
public readonly api: API;
|
|
13
|
+
public readonly log: Logging;
|
|
14
|
+
public readonly config!: SwitchBotPlatformConfig;
|
|
15
|
+
protected readonly hap: HAP;
|
|
12
16
|
// Services
|
|
13
17
|
batteryService: Service;
|
|
14
18
|
humidityService?: Service;
|
|
@@ -49,22 +53,29 @@ export class Meter {
|
|
|
49
53
|
deviceRefreshRate!: number;
|
|
50
54
|
|
|
51
55
|
// Connection
|
|
52
|
-
private readonly
|
|
53
|
-
private readonly
|
|
56
|
+
private readonly OpenAPI: boolean;
|
|
57
|
+
private readonly BLE: boolean;
|
|
54
58
|
|
|
55
59
|
constructor(
|
|
56
60
|
private readonly platform: SwitchBotPlatform,
|
|
57
61
|
private accessory: PlatformAccessory,
|
|
58
62
|
public device: device & devicesConfig,
|
|
59
63
|
) {
|
|
64
|
+
this.api = this.platform.api;
|
|
65
|
+
this.log = this.platform.log;
|
|
66
|
+
this.config = this.platform.config;
|
|
67
|
+
this.hap = this.api.hap;
|
|
68
|
+
// Connection
|
|
69
|
+
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
70
|
+
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
60
71
|
// default placeholders
|
|
61
|
-
this.
|
|
72
|
+
this.deviceLogs(device);
|
|
62
73
|
this.scan(device);
|
|
63
74
|
this.refreshRate(device);
|
|
64
75
|
this.context();
|
|
65
76
|
this.setupHistoryService(device);
|
|
66
77
|
this.setupMqtt(device);
|
|
67
|
-
this.
|
|
78
|
+
this.deviceConfig(device);
|
|
68
79
|
|
|
69
80
|
this.CurrentRelativeHumidity = accessory.context.CurrentRelativeHumidity;
|
|
70
81
|
this.CurrentTemperature = accessory.context.CurrentTemperature;
|
|
@@ -74,29 +85,29 @@ export class Meter {
|
|
|
74
85
|
|
|
75
86
|
// set accessory information
|
|
76
87
|
accessory
|
|
77
|
-
.getService(this.
|
|
78
|
-
.setCharacteristic(this.
|
|
79
|
-
.setCharacteristic(this.
|
|
80
|
-
.setCharacteristic(this.
|
|
81
|
-
.setCharacteristic(this.
|
|
88
|
+
.getService(this.hap.Service.AccessoryInformation)!
|
|
89
|
+
.setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
|
|
90
|
+
.setCharacteristic(this.hap.Characteristic.Model, 'METERTH-S1')
|
|
91
|
+
.setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
|
|
92
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
|
|
82
93
|
|
|
83
94
|
// Temperature Sensor Service
|
|
84
95
|
if (device.meter?.hide_temperature) {
|
|
85
96
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
86
|
-
this.temperatureService = this.accessory.getService(this.
|
|
97
|
+
this.temperatureService = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
87
98
|
accessory.removeService(this.temperatureService!);
|
|
88
99
|
} else if (!this.temperatureService) {
|
|
89
100
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
90
101
|
const temperatureService = `${accessory.displayName} Temperature Sensor`;
|
|
91
|
-
(this.temperatureService = this.accessory.getService(this.
|
|
92
|
-
|| this.accessory.addService(this.
|
|
102
|
+
(this.temperatureService = this.accessory.getService(this.hap.Service.TemperatureSensor)
|
|
103
|
+
|| this.accessory.addService(this.hap.Service.TemperatureSensor)), temperatureService;
|
|
93
104
|
|
|
94
|
-
this.temperatureService.setCharacteristic(this.
|
|
95
|
-
if (!this.temperatureService.testCharacteristic(this.
|
|
96
|
-
this.temperatureService.addCharacteristic(this.
|
|
105
|
+
this.temperatureService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Temperature Sensor`);
|
|
106
|
+
if (!this.temperatureService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
107
|
+
this.temperatureService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Temperature Sensor`);
|
|
97
108
|
}
|
|
98
109
|
this.temperatureService
|
|
99
|
-
.getCharacteristic(this.
|
|
110
|
+
.getCharacteristic(this.hap.Characteristic.CurrentTemperature)
|
|
100
111
|
.setProps({
|
|
101
112
|
unit: Units['CELSIUS'],
|
|
102
113
|
validValueRanges: [-273.15, 100],
|
|
@@ -114,20 +125,20 @@ export class Meter {
|
|
|
114
125
|
// Humidity Sensor Service
|
|
115
126
|
if (device.meter?.hide_humidity) {
|
|
116
127
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
117
|
-
this.humidityService = this.accessory.getService(this.
|
|
128
|
+
this.humidityService = this.accessory.getService(this.hap.Service.HumiditySensor);
|
|
118
129
|
accessory.removeService(this.humidityService!);
|
|
119
130
|
} else if (!this.humidityService) {
|
|
120
131
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
121
132
|
const humidityService = `${accessory.displayName} Humidity Sensor`;
|
|
122
|
-
(this.humidityService = this.accessory.getService(this.
|
|
123
|
-
|| this.accessory.addService(this.
|
|
133
|
+
(this.humidityService = this.accessory.getService(this.hap.Service.HumiditySensor)
|
|
134
|
+
|| this.accessory.addService(this.hap.Service.HumiditySensor)), humidityService;
|
|
124
135
|
|
|
125
|
-
this.humidityService.setCharacteristic(this.
|
|
126
|
-
if (!this.humidityService.testCharacteristic(this.
|
|
127
|
-
this.humidityService.addCharacteristic(this.
|
|
136
|
+
this.humidityService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Humidity Sensor`);
|
|
137
|
+
if (!this.humidityService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
138
|
+
this.humidityService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Humidity Sensor`);
|
|
128
139
|
}
|
|
129
140
|
this.humidityService
|
|
130
|
-
.getCharacteristic(this.
|
|
141
|
+
.getCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity)
|
|
131
142
|
.setProps({
|
|
132
143
|
minStep: 0.1,
|
|
133
144
|
})
|
|
@@ -140,14 +151,14 @@ export class Meter {
|
|
|
140
151
|
|
|
141
152
|
// Battery Service
|
|
142
153
|
const batteryService = `${accessory.displayName} Battery`;
|
|
143
|
-
(this.batteryService = this.accessory.getService(this.
|
|
144
|
-
|| accessory.addService(this.
|
|
154
|
+
(this.batteryService = this.accessory.getService(this.hap.Service.Battery)
|
|
155
|
+
|| accessory.addService(this.hap.Service.Battery)), batteryService;
|
|
145
156
|
|
|
146
|
-
this.batteryService.setCharacteristic(this.
|
|
147
|
-
if (!this.batteryService.testCharacteristic(this.
|
|
148
|
-
this.batteryService.addCharacteristic(this.
|
|
157
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
158
|
+
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
159
|
+
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
149
160
|
}
|
|
150
|
-
this.batteryService.setCharacteristic(this.
|
|
161
|
+
this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
151
162
|
|
|
152
163
|
// Retrieve initial values and update Homekit
|
|
153
164
|
this.updateHomeKitCharacteristics();
|
|
@@ -207,9 +218,9 @@ export class Meter {
|
|
|
207
218
|
// BatteryLevel
|
|
208
219
|
this.BatteryLevel = Number(this.BLE_BatteryLevel);
|
|
209
220
|
if (this.BatteryLevel < 15) {
|
|
210
|
-
this.StatusLowBattery = this.
|
|
221
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
211
222
|
} else {
|
|
212
|
-
this.StatusLowBattery = this.
|
|
223
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
213
224
|
}
|
|
214
225
|
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
215
226
|
|
|
@@ -233,9 +244,9 @@ export class Meter {
|
|
|
233
244
|
// BatteryLevel
|
|
234
245
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
235
246
|
if (this.BatteryLevel < 15) {
|
|
236
|
-
this.StatusLowBattery = this.
|
|
247
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
237
248
|
} else {
|
|
238
|
-
this.StatusLowBattery = this.
|
|
249
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
239
250
|
}
|
|
240
251
|
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
241
252
|
|
|
@@ -254,9 +265,9 @@ export class Meter {
|
|
|
254
265
|
// Battery
|
|
255
266
|
this.BatteryLevel = Number(this.OpenAPI_BatteryLevel);
|
|
256
267
|
if (this.BatteryLevel < 10) {
|
|
257
|
-
this.StatusLowBattery = this.
|
|
268
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
258
269
|
} else {
|
|
259
|
-
this.StatusLowBattery = this.
|
|
270
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
260
271
|
}
|
|
261
272
|
if (Number.isNaN(this.BatteryLevel)) {
|
|
262
273
|
this.BatteryLevel = 100;
|
|
@@ -410,7 +421,7 @@ export class Meter {
|
|
|
410
421
|
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
411
422
|
}
|
|
412
423
|
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
413
|
-
this.humidityService?.updateCharacteristic(this.
|
|
424
|
+
this.humidityService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
414
425
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
415
426
|
+ `updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
416
427
|
}
|
|
@@ -427,7 +438,7 @@ export class Meter {
|
|
|
427
438
|
entry['temp'] = this.CurrentTemperature;
|
|
428
439
|
}
|
|
429
440
|
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
430
|
-
this.temperatureService?.updateCharacteristic(this.
|
|
441
|
+
this.temperatureService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
431
442
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
432
443
|
}
|
|
433
444
|
}
|
|
@@ -439,7 +450,7 @@ export class Meter {
|
|
|
439
450
|
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
440
451
|
}
|
|
441
452
|
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
442
|
-
this.batteryService?.updateCharacteristic(this.
|
|
453
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
443
454
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
444
455
|
}
|
|
445
456
|
if (this.StatusLowBattery === undefined) {
|
|
@@ -449,7 +460,7 @@ export class Meter {
|
|
|
449
460
|
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
450
461
|
}
|
|
451
462
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
452
|
-
this.batteryService?.updateCharacteristic(this.
|
|
463
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
453
464
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
454
465
|
}
|
|
455
466
|
|
|
@@ -615,13 +626,13 @@ export class Meter {
|
|
|
615
626
|
|
|
616
627
|
async apiError(e: any): Promise<void> {
|
|
617
628
|
if (!this.device.meter?.hide_humidity) {
|
|
618
|
-
this.humidityService?.updateCharacteristic(this.
|
|
629
|
+
this.humidityService?.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
619
630
|
}
|
|
620
631
|
if (!this.device.meter?.hide_temperature) {
|
|
621
|
-
this.temperatureService?.updateCharacteristic(this.
|
|
632
|
+
this.temperatureService?.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
622
633
|
}
|
|
623
|
-
this.batteryService?.updateCharacteristic(this.
|
|
624
|
-
this.batteryService?.updateCharacteristic(this.
|
|
634
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
635
|
+
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
625
636
|
}
|
|
626
637
|
|
|
627
638
|
async context() {
|
|
@@ -641,7 +652,7 @@ export class Meter {
|
|
|
641
652
|
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
642
653
|
}
|
|
643
654
|
if (this.StatusLowBattery === undefined) {
|
|
644
|
-
this.StatusLowBattery = this.
|
|
655
|
+
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
645
656
|
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
646
657
|
} else {
|
|
647
658
|
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
@@ -662,7 +673,7 @@ export class Meter {
|
|
|
662
673
|
}
|
|
663
674
|
}
|
|
664
675
|
|
|
665
|
-
async
|
|
676
|
+
async deviceConfig(device: device & devicesConfig): Promise<void> {
|
|
666
677
|
let config = {};
|
|
667
678
|
if (device.meter) {
|
|
668
679
|
config = device.meter;
|
|
@@ -690,7 +701,7 @@ export class Meter {
|
|
|
690
701
|
}
|
|
691
702
|
}
|
|
692
703
|
|
|
693
|
-
async
|
|
704
|
+
async deviceLogs(device: device & devicesConfig): Promise<void> {
|
|
694
705
|
if (this.platform.debugMode) {
|
|
695
706
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
696
707
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|