@switchbot/homebridge-switchbot 2.0.0-beta.17 → 2.0.0-beta.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1 -1
- package/config.schema.json +14 -4
- package/dist/device/bot.d.ts +2 -0
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +201 -163
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +2 -0
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +250 -218
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +2 -0
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +85 -66
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +2 -0
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +166 -136
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +126 -115
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +2 -0
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +156 -130
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +2 -0
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +85 -64
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +2 -0
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +78 -59
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +2 -0
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +76 -57
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +2 -0
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +133 -107
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +2 -0
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +224 -195
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -0
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +127 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -0
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +83 -66
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +8 -6
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +83 -68
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +7 -5
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +90 -75
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +8 -6
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +83 -68
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +8 -6
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +93 -78
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -6
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +68 -52
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +8 -6
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +83 -69
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -0
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +75 -60
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/settings.d.ts +12 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +1 -1
- package/src/device/bot.ts +200 -163
- package/src/device/colorbulb.ts +252 -221
- package/src/device/contact.ts +85 -66
- package/src/device/curtain.ts +165 -136
- package/src/device/humidifier.ts +126 -115
- package/src/device/lock.ts +156 -131
- package/src/device/meter.ts +85 -64
- package/src/device/meterplus.ts +78 -59
- package/src/device/motion.ts +76 -57
- package/src/device/plug.ts +132 -107
- package/src/device/striplight.ts +226 -198
- package/src/irdevice/airconditioner.ts +126 -103
- package/src/irdevice/airpurifier.ts +84 -66
- package/src/irdevice/camera.ts +84 -68
- package/src/irdevice/fan.ts +91 -75
- package/src/irdevice/light.ts +84 -68
- package/src/irdevice/other.ts +94 -78
- package/src/irdevice/tv.ts +69 -53
- package/src/irdevice/vacuumcleaner.ts +83 -68
- package/src/irdevice/waterheater.ts +76 -60
- package/src/settings.ts +12 -11
package/src/device/meter.ts
CHANGED
|
@@ -45,6 +45,7 @@ export class Meter {
|
|
|
45
45
|
humidity!: serviceData['humidity'];
|
|
46
46
|
|
|
47
47
|
// Config
|
|
48
|
+
OpenAPI?: boolean;
|
|
48
49
|
scanDuration!: number;
|
|
49
50
|
deviceLogging!: string;
|
|
50
51
|
deviceRefreshRate!: number;
|
|
@@ -62,6 +63,7 @@ export class Meter {
|
|
|
62
63
|
constructor(private readonly platform: SwitchBotPlatform, private accessory: PlatformAccessory, public device: device & devicesConfig) {
|
|
63
64
|
// default placeholders
|
|
64
65
|
this.logs(device);
|
|
66
|
+
this.openAPI();
|
|
65
67
|
this.scan(device);
|
|
66
68
|
this.setupHistoryService(device);
|
|
67
69
|
this.refreshRate(device);
|
|
@@ -97,11 +99,11 @@ export class Meter {
|
|
|
97
99
|
|
|
98
100
|
// Temperature Sensor Service
|
|
99
101
|
if (device.meter?.hide_temperature) {
|
|
100
|
-
this.debugLog(
|
|
102
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
101
103
|
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
102
104
|
accessory.removeService(this.temperatureservice!);
|
|
103
105
|
} else if (!this.temperatureservice) {
|
|
104
|
-
this.debugLog(
|
|
106
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
105
107
|
(this.temperatureservice =
|
|
106
108
|
this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
107
109
|
`${accessory.displayName} Temperature Sensor`;
|
|
@@ -121,16 +123,16 @@ export class Meter {
|
|
|
121
123
|
return this.CurrentTemperature!;
|
|
122
124
|
});
|
|
123
125
|
} else {
|
|
124
|
-
this.debugLog(
|
|
126
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
125
127
|
}
|
|
126
128
|
|
|
127
129
|
// Humidity Sensor Service
|
|
128
130
|
if (device.meter?.hide_humidity) {
|
|
129
|
-
this.debugLog(
|
|
131
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
130
132
|
this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor);
|
|
131
133
|
accessory.removeService(this.humidityservice!);
|
|
132
134
|
} else if (!this.humidityservice) {
|
|
133
|
-
this.debugLog(
|
|
135
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
134
136
|
(this.humidityservice =
|
|
135
137
|
this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)),
|
|
136
138
|
`${accessory.displayName} Humidity Sensor`;
|
|
@@ -146,16 +148,16 @@ export class Meter {
|
|
|
146
148
|
return this.CurrentRelativeHumidity;
|
|
147
149
|
});
|
|
148
150
|
} else {
|
|
149
|
-
this.debugLog(
|
|
151
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
150
152
|
}
|
|
151
153
|
|
|
152
154
|
// Battery Service
|
|
153
155
|
if (!device.ble) {
|
|
154
|
-
this.debugLog(
|
|
156
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
155
157
|
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
156
158
|
accessory.removeService(this.batteryService!);
|
|
157
159
|
} else if (device.ble && !this.batteryService) {
|
|
158
|
-
this.debugLog(
|
|
160
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
159
161
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
160
162
|
`${accessory.displayName} Battery`;
|
|
161
163
|
|
|
@@ -163,7 +165,7 @@ export class Meter {
|
|
|
163
165
|
|
|
164
166
|
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
165
167
|
} else {
|
|
166
|
-
this.debugLog(
|
|
168
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
167
169
|
}
|
|
168
170
|
|
|
169
171
|
// Retrieve initial values and updateHomekit
|
|
@@ -188,7 +190,7 @@ export class Meter {
|
|
|
188
190
|
?.join(':');
|
|
189
191
|
const options = this.device.mqttPubOptions || {};
|
|
190
192
|
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
191
|
-
this.debugLog(
|
|
193
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${superStringify(options)}`);
|
|
192
194
|
}
|
|
193
195
|
|
|
194
196
|
/*
|
|
@@ -198,13 +200,13 @@ export class Meter {
|
|
|
198
200
|
if (device.mqttURL) {
|
|
199
201
|
try {
|
|
200
202
|
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
201
|
-
this.debugLog(
|
|
203
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
202
204
|
this.mqttClient.on('error', (e: Error) => {
|
|
203
|
-
this.errorLog(
|
|
205
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
204
206
|
});
|
|
205
207
|
} catch (e) {
|
|
206
208
|
this.mqttClient = null;
|
|
207
|
-
this.errorLog(
|
|
209
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
208
210
|
}
|
|
209
211
|
}
|
|
210
212
|
}
|
|
@@ -238,7 +240,7 @@ export class Meter {
|
|
|
238
240
|
}
|
|
239
241
|
|
|
240
242
|
async BLEparseStatus(): Promise<void> {
|
|
241
|
-
this.debugLog(
|
|
243
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE parseStatus`);
|
|
242
244
|
|
|
243
245
|
// Battery
|
|
244
246
|
this.BatteryLevel = Number(this.battery);
|
|
@@ -247,19 +249,20 @@ export class Meter {
|
|
|
247
249
|
} else {
|
|
248
250
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
249
251
|
}
|
|
250
|
-
this.debugLog(
|
|
252
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel},`
|
|
253
|
+
+ ` StatusLowBattery: ${this.StatusLowBattery}`);
|
|
251
254
|
|
|
252
255
|
// Humidity
|
|
253
256
|
if (!this.device.meter?.hide_humidity) {
|
|
254
257
|
this.CurrentRelativeHumidity = this.humidity!;
|
|
255
|
-
this.debugLog(
|
|
258
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
256
259
|
}
|
|
257
260
|
|
|
258
261
|
// Current Temperature
|
|
259
262
|
if (!this.device.meter?.hide_temperature) {
|
|
260
263
|
this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
|
|
261
264
|
this.CurrentTemperature = this.temperature;
|
|
262
|
-
this.debugLog(
|
|
265
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
263
266
|
}
|
|
264
267
|
}
|
|
265
268
|
|
|
@@ -268,17 +271,17 @@ export class Meter {
|
|
|
268
271
|
this.SwitchToOpenAPI = false;
|
|
269
272
|
}
|
|
270
273
|
if (this.platform.config.credentials?.token) {
|
|
271
|
-
this.debugLog(
|
|
274
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
272
275
|
// Current Relative Humidity
|
|
273
276
|
if (!this.device.meter?.hide_humidity) {
|
|
274
277
|
this.CurrentRelativeHumidity = this.Humidity!;
|
|
275
|
-
this.debugLog(
|
|
278
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
276
279
|
}
|
|
277
280
|
|
|
278
281
|
// Current Temperature
|
|
279
282
|
if (!this.device.meter?.hide_temperature) {
|
|
280
283
|
this.CurrentTemperature = this.Temperature!;
|
|
281
|
-
this.debugLog(
|
|
284
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
282
285
|
}
|
|
283
286
|
}
|
|
284
287
|
}
|
|
@@ -295,14 +298,14 @@ export class Meter {
|
|
|
295
298
|
}
|
|
296
299
|
|
|
297
300
|
async BLErefreshStatus(): Promise<void> {
|
|
298
|
-
this.debugLog(
|
|
301
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
299
302
|
const switchbot = await this.platform.connectBLE();
|
|
300
303
|
// Convert to BLE Address
|
|
301
304
|
this.device.bleMac = this.device
|
|
302
305
|
.deviceId!.match(/.{1,2}/g)!
|
|
303
306
|
.join(':')
|
|
304
307
|
.toLowerCase();
|
|
305
|
-
this.debugLog(
|
|
308
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
306
309
|
this.getCustomBLEAddress(switchbot);
|
|
307
310
|
// Start to monitor advertisement packets
|
|
308
311
|
if (switchbot !== false) {
|
|
@@ -318,8 +321,8 @@ export class Meter {
|
|
|
318
321
|
if (this.deviceLogging.includes('debug')) {
|
|
319
322
|
this.infoLog(this.address);
|
|
320
323
|
this.infoLog(this.device.bleMac);
|
|
321
|
-
this.infoLog(
|
|
322
|
-
this.infoLog(
|
|
324
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address Found: ${this.address}`);
|
|
325
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac}`);
|
|
323
326
|
}
|
|
324
327
|
if (ad.serviceData.humidity! > 0) {
|
|
325
328
|
// reject unreliable data
|
|
@@ -328,19 +331,19 @@ export class Meter {
|
|
|
328
331
|
this.humidity = ad.serviceData.humidity;
|
|
329
332
|
this.battery = ad.serviceData.battery;
|
|
330
333
|
}
|
|
331
|
-
this.debugLog(
|
|
334
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${superStringify(ad.serviceData)}`);
|
|
332
335
|
this.debugLog(
|
|
333
|
-
|
|
336
|
+
`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
334
337
|
`temperature: ${superStringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
|
|
335
338
|
`battery: ${ad.serviceData.battery}`,
|
|
336
339
|
);
|
|
337
340
|
|
|
338
341
|
if (this.serviceData) {
|
|
339
342
|
this.connected = true;
|
|
340
|
-
this.debugLog(
|
|
343
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
341
344
|
} else {
|
|
342
345
|
this.connected = false;
|
|
343
|
-
this.debugLog(
|
|
346
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
344
347
|
}
|
|
345
348
|
};
|
|
346
349
|
// Wait 10 seconds
|
|
@@ -357,14 +360,15 @@ export class Meter {
|
|
|
357
360
|
}
|
|
358
361
|
})
|
|
359
362
|
.catch(async (e: any) => {
|
|
360
|
-
this.errorLog(
|
|
363
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
361
364
|
if (this.deviceLogging.includes('debug')) {
|
|
362
365
|
this.errorLog(
|
|
363
|
-
|
|
366
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
367
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
364
368
|
);
|
|
365
369
|
}
|
|
366
370
|
if (this.platform.config.credentials?.token) {
|
|
367
|
-
this.warnLog(
|
|
371
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
368
372
|
this.SwitchToOpenAPI = true;
|
|
369
373
|
this.openAPIRefreshStatus();
|
|
370
374
|
}
|
|
@@ -384,7 +388,7 @@ export class Meter {
|
|
|
384
388
|
});
|
|
385
389
|
// Set an event handler
|
|
386
390
|
switchbot.onadvertisement = (ad: any) => {
|
|
387
|
-
this.warnLog(
|
|
391
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${superStringify(ad, null, ' ')}`);
|
|
388
392
|
};
|
|
389
393
|
await switchbot.wait(10000);
|
|
390
394
|
// Stop to monitor
|
|
@@ -394,24 +398,24 @@ export class Meter {
|
|
|
394
398
|
}
|
|
395
399
|
|
|
396
400
|
async BLEconnection(switchbot: any): Promise<void> {
|
|
397
|
-
this.errorLog(
|
|
401
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
398
402
|
if (this.platform.config.credentials?.token) {
|
|
399
|
-
this.warnLog(
|
|
403
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
400
404
|
this.SwitchToOpenAPI = true;
|
|
401
405
|
await this.openAPIRefreshStatus();
|
|
402
406
|
}
|
|
403
407
|
}
|
|
404
408
|
|
|
405
409
|
async openAPIRefreshStatus(): Promise<void> {
|
|
406
|
-
if (this.platform.config.credentials?.token) {
|
|
407
|
-
this.debugLog(
|
|
410
|
+
if (this.platform.config.credentials?.token && this.OpenAPI) {
|
|
411
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI RefreshStatus`);
|
|
408
412
|
try {
|
|
409
413
|
const t = Date.now();
|
|
410
414
|
const nonce = 'requestID';
|
|
411
415
|
const data = this.platform.config.credentials?.token + t + nonce;
|
|
412
416
|
const signTerm = crypto.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
413
417
|
const sign = signTerm.toString('base64');
|
|
414
|
-
this.debugLog(
|
|
418
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
415
419
|
const options = {
|
|
416
420
|
hostname: HostDomain,
|
|
417
421
|
port: 443,
|
|
@@ -426,38 +430,41 @@ export class Meter {
|
|
|
426
430
|
},
|
|
427
431
|
};
|
|
428
432
|
const req = https.request(options, (res) => {
|
|
429
|
-
this.debugLog(
|
|
433
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${res.statusCode}`);
|
|
430
434
|
let rawData = '';
|
|
431
435
|
res.on('data', (d) => {
|
|
432
436
|
rawData += d;
|
|
433
|
-
this.debugLog(
|
|
437
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
434
438
|
});
|
|
435
439
|
res.on('end', () => {
|
|
436
440
|
try {
|
|
437
441
|
this.deviceStatus = JSON.parse(rawData);
|
|
438
|
-
this.debugLog(
|
|
442
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${superStringify(this.deviceStatus)}`);
|
|
439
443
|
this.Humidity = this.deviceStatus.body.humidity!;
|
|
440
444
|
this.Temperature = this.deviceStatus.body.temperature!;
|
|
441
445
|
this.parseStatus();
|
|
442
446
|
this.updateHomeKitCharacteristics();
|
|
443
447
|
} catch (e: any) {
|
|
444
|
-
this.errorLog(
|
|
448
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
445
449
|
}
|
|
446
450
|
});
|
|
447
451
|
});
|
|
448
452
|
req.on('error', (e: any) => {
|
|
449
|
-
this.errorLog(
|
|
453
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
450
454
|
});
|
|
451
455
|
req.end();
|
|
452
456
|
} catch (e: any) {
|
|
453
|
-
this.errorLog(
|
|
457
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
454
458
|
if (this.deviceLogging.includes('debug')) {
|
|
455
459
|
this.errorLog(
|
|
456
|
-
|
|
460
|
+
`${this.device.deviceType}: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
461
|
+
+ ` Error Message: ${superStringify(e.message)}`,
|
|
457
462
|
);
|
|
458
463
|
}
|
|
459
464
|
this.apiError(e);
|
|
460
465
|
}
|
|
466
|
+
} else {
|
|
467
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} OpenAPI is disabled, commands will not be sent.`);
|
|
461
468
|
}
|
|
462
469
|
}
|
|
463
470
|
|
|
@@ -469,37 +476,38 @@ export class Meter {
|
|
|
469
476
|
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
470
477
|
if (!this.device.meter?.hide_humidity) {
|
|
471
478
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
472
|
-
this.debugLog(
|
|
479
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
473
480
|
} else {
|
|
474
481
|
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
475
|
-
this.debugLog(
|
|
482
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
483
|
+
+ ` CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
476
484
|
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
477
485
|
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
478
486
|
}
|
|
479
487
|
}
|
|
480
488
|
if (!this.device.meter?.hide_temperature) {
|
|
481
489
|
if (this.CurrentTemperature === undefined) {
|
|
482
|
-
this.debugLog(
|
|
490
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
483
491
|
} else {
|
|
484
492
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
485
|
-
this.debugLog(
|
|
493
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
486
494
|
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
487
495
|
entry['temp'] = this.CurrentTemperature;
|
|
488
496
|
}
|
|
489
497
|
}
|
|
490
498
|
if (this.device.ble) {
|
|
491
499
|
if (this.BatteryLevel === undefined) {
|
|
492
|
-
this.debugLog(
|
|
500
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
493
501
|
} else {
|
|
494
502
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
495
|
-
this.debugLog(
|
|
503
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
496
504
|
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
497
505
|
}
|
|
498
506
|
if (this.StatusLowBattery === undefined) {
|
|
499
|
-
this.debugLog(
|
|
507
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
500
508
|
} else {
|
|
501
509
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
502
|
-
this.debugLog(
|
|
510
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
503
511
|
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
504
512
|
}
|
|
505
513
|
}
|
|
@@ -532,6 +540,9 @@ export class Meter {
|
|
|
532
540
|
if (device.ble !== undefined) {
|
|
533
541
|
config['ble'] = device.ble;
|
|
534
542
|
}
|
|
543
|
+
if (device.openAPI !== undefined) {
|
|
544
|
+
config['openAPI'] = device.openAPI;
|
|
545
|
+
}
|
|
535
546
|
if (device.logging !== undefined) {
|
|
536
547
|
config['logging'] = device.logging;
|
|
537
548
|
}
|
|
@@ -542,30 +553,39 @@ export class Meter {
|
|
|
542
553
|
config['scanDuration'] = device.scanDuration;
|
|
543
554
|
}
|
|
544
555
|
if (Object.entries(config).length !== 0) {
|
|
545
|
-
this.infoLog(
|
|
556
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${superStringify(config)}`);
|
|
546
557
|
}
|
|
547
558
|
}
|
|
548
559
|
|
|
549
560
|
async refreshRate(device: device & devicesConfig): Promise<void> {
|
|
550
561
|
if (device.refreshRate) {
|
|
551
562
|
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
552
|
-
this.debugLog(
|
|
563
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
553
564
|
} else if (this.platform.config.options!.refreshRate) {
|
|
554
565
|
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
555
|
-
this.debugLog(
|
|
566
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
async openAPI() {
|
|
571
|
+
if (!this.device.openAPI) {
|
|
572
|
+
this.OpenAPI = true;
|
|
573
|
+
} else {
|
|
574
|
+
this.OpenAPI = this.device.openAPI;
|
|
556
575
|
}
|
|
576
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI: ${this.OpenAPI}`);
|
|
557
577
|
}
|
|
558
578
|
|
|
559
579
|
async scan(device: device & devicesConfig): Promise<void> {
|
|
560
580
|
if (device.scanDuration) {
|
|
561
581
|
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
562
582
|
if (device.ble) {
|
|
563
|
-
this.debugLog(
|
|
583
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
564
584
|
}
|
|
565
585
|
} else {
|
|
566
586
|
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
567
587
|
if (this.device.ble) {
|
|
568
|
-
this.debugLog(
|
|
588
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
569
589
|
}
|
|
570
590
|
}
|
|
571
591
|
}
|
|
@@ -573,24 +593,25 @@ export class Meter {
|
|
|
573
593
|
async logs(device: device & devicesConfig): Promise<void> {
|
|
574
594
|
if (this.platform.debugMode) {
|
|
575
595
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
576
|
-
this.debugLog(
|
|
596
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
577
597
|
} else if (device.logging) {
|
|
578
598
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
579
|
-
this.debugLog(
|
|
599
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
580
600
|
} else if (this.platform.config.options?.logging) {
|
|
581
601
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
582
|
-
this.debugLog(
|
|
602
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
583
603
|
} else {
|
|
584
604
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
585
|
-
this.debugLog(
|
|
605
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
586
606
|
}
|
|
587
607
|
}
|
|
588
608
|
|
|
589
609
|
FirmwareRevision(accessory: PlatformAccessory<Context>, device: device & devicesConfig): CharacteristicValue {
|
|
590
610
|
let FirmwareRevision: string;
|
|
591
|
-
this.debugLog(
|
|
592
|
-
|
|
593
|
-
this.debugLog(
|
|
611
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
612
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
613
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
614
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
594
615
|
if (accessory.context.FirmwareRevision) {
|
|
595
616
|
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
596
617
|
} else if (device.firmware) {
|