@switchbot/homebridge-switchbot 1.4.0 → 1.4.1-beta.3
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 +18 -0
- package/config.schema.json +83 -11
- package/dist/devices/bots.d.ts +13 -3
- package/dist/devices/bots.d.ts.map +1 -1
- package/dist/devices/bots.js +162 -105
- package/dist/devices/bots.js.map +1 -1
- package/dist/devices/colorbulb.d.ts +13 -3
- package/dist/devices/colorbulb.d.ts.map +1 -1
- package/dist/devices/colorbulb.js +161 -96
- package/dist/devices/colorbulb.js.map +1 -1
- package/dist/devices/contact.d.ts +13 -3
- package/dist/devices/contact.d.ts.map +1 -1
- package/dist/devices/contact.js +117 -63
- package/dist/devices/contact.js.map +1 -1
- package/dist/devices/curtains.d.ts +14 -5
- package/dist/devices/curtains.d.ts.map +1 -1
- package/dist/devices/curtains.js +198 -140
- package/dist/devices/curtains.js.map +1 -1
- package/dist/devices/humidifiers.d.ts +13 -3
- package/dist/devices/humidifiers.d.ts.map +1 -1
- package/dist/devices/humidifiers.js +180 -127
- package/dist/devices/humidifiers.js.map +1 -1
- package/dist/devices/meters.d.ts +13 -3
- package/dist/devices/meters.d.ts.map +1 -1
- package/dist/devices/meters.js +121 -63
- package/dist/devices/meters.js.map +1 -1
- package/dist/devices/motion.d.ts +13 -3
- package/dist/devices/motion.d.ts.map +1 -1
- package/dist/devices/motion.js +104 -45
- package/dist/devices/motion.js.map +1 -1
- package/dist/devices/plugs.d.ts +13 -3
- package/dist/devices/plugs.d.ts.map +1 -1
- package/dist/devices/plugs.js +99 -35
- package/dist/devices/plugs.js.map +1 -1
- package/dist/irdevices/airconditioners.d.ts +11 -3
- package/dist/irdevices/airconditioners.d.ts.map +1 -1
- package/dist/irdevices/airconditioners.js +80 -45
- package/dist/irdevices/airconditioners.js.map +1 -1
- package/dist/irdevices/airpurifiers.d.ts +11 -3
- package/dist/irdevices/airpurifiers.d.ts.map +1 -1
- package/dist/irdevices/airpurifiers.js +68 -31
- package/dist/irdevices/airpurifiers.js.map +1 -1
- package/dist/irdevices/cameras.d.ts +11 -3
- package/dist/irdevices/cameras.d.ts.map +1 -1
- package/dist/irdevices/cameras.js +64 -24
- package/dist/irdevices/cameras.js.map +1 -1
- package/dist/irdevices/fans.d.ts +11 -3
- package/dist/irdevices/fans.d.ts.map +1 -1
- package/dist/irdevices/fans.js +74 -35
- package/dist/irdevices/fans.js.map +1 -1
- package/dist/irdevices/lights.d.ts +11 -3
- package/dist/irdevices/lights.d.ts.map +1 -1
- package/dist/irdevices/lights.js +65 -25
- package/dist/irdevices/lights.js.map +1 -1
- package/dist/irdevices/others.d.ts +11 -3
- package/dist/irdevices/others.d.ts.map +1 -1
- package/dist/irdevices/others.js +71 -31
- package/dist/irdevices/others.js.map +1 -1
- package/dist/irdevices/tvs.d.ts +11 -3
- package/dist/irdevices/tvs.d.ts.map +1 -1
- package/dist/irdevices/tvs.js +81 -42
- package/dist/irdevices/tvs.js.map +1 -1
- package/dist/irdevices/vacuumcleaners.d.ts +11 -3
- package/dist/irdevices/vacuumcleaners.d.ts.map +1 -1
- package/dist/irdevices/vacuumcleaners.js +64 -24
- package/dist/irdevices/vacuumcleaners.js.map +1 -1
- package/dist/irdevices/waterheaters.d.ts +11 -3
- package/dist/irdevices/waterheaters.d.ts.map +1 -1
- package/dist/irdevices/waterheaters.js +64 -24
- package/dist/irdevices/waterheaters.js.map +1 -1
- package/dist/platform.d.ts +10 -10
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +290 -307
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/nodemon.json +1 -1
- package/package.json +70 -66
- package/src/devices/bots.ts +169 -105
- package/src/devices/colorbulb.ts +170 -99
- package/src/devices/contact.ts +124 -64
- package/src/devices/curtains.ts +207 -145
- package/src/devices/humidifiers.ts +187 -129
- package/src/devices/meters.ts +128 -64
- package/src/devices/motion.ts +110 -45
- package/src/devices/plugs.ts +104 -36
- package/src/irdevices/airconditioners.ts +85 -45
- package/src/irdevices/airpurifiers.ts +73 -31
- package/src/irdevices/cameras.ts +69 -24
- package/src/irdevices/fans.ts +79 -36
- package/src/irdevices/lights.ts +70 -25
- package/src/irdevices/others.ts +76 -31
- package/src/irdevices/tvs.ts +86 -42
- package/src/irdevices/vacuumcleaners.ts +69 -24
- package/src/irdevices/waterheaters.ts +69 -24
- package/src/platform.ts +285 -302
- package/src/settings.ts +4 -1
- package/dist/devices/indoorcam.d.ts +0 -64
- package/dist/devices/indoorcam.d.ts.map +0 -1
- package/dist/devices/indoorcam.js +0 -249
- package/dist/devices/indoorcam.js.map +0 -1
- package/src/devices/indoorcam.ts +0 -309
package/src/devices/meters.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Switchbot from 'node-switchbot';
|
|
|
2
2
|
import { interval, Subject } from 'rxjs';
|
|
3
3
|
import { skipWhile } from 'rxjs/operators';
|
|
4
4
|
import { SwitchBotPlatform } from '../platform';
|
|
5
|
-
import { Service, PlatformAccessory, Units, CharacteristicValue } from 'homebridge';
|
|
5
|
+
import { Service, PlatformAccessory, Units, CharacteristicValue, HAPStatus } from 'homebridge';
|
|
6
6
|
import { DeviceURL, device, devicesConfig, serviceData, ad, switchbot, deviceStatusResponse, temperature } from '../settings';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -40,8 +40,8 @@ export class Meter {
|
|
|
40
40
|
humidity!: serviceData['humidity'];
|
|
41
41
|
|
|
42
42
|
// Config
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
deviceLogging!: string;
|
|
44
|
+
deviceRefreshRate!: number;
|
|
45
45
|
|
|
46
46
|
// Updates
|
|
47
47
|
meterUpdateInProgress!: boolean;
|
|
@@ -52,11 +52,9 @@ export class Meter {
|
|
|
52
52
|
private accessory: PlatformAccessory,
|
|
53
53
|
public device: device & devicesConfig,
|
|
54
54
|
) {
|
|
55
|
-
// Meter Config
|
|
56
|
-
this.platform.device(`Meter: ${this.accessory.displayName} Config: (ble: ${device.ble}, hide_temperature: ${device.meter?.hide_temperature},`
|
|
57
|
-
+ ` hide_humidity: ${device.meter?.hide_humidity})`);
|
|
58
|
-
|
|
59
55
|
// default placeholders
|
|
56
|
+
this.refreshRate();
|
|
57
|
+
this.logs();
|
|
60
58
|
if (this.BatteryLevel === undefined) {
|
|
61
59
|
this.BatteryLevel = 100;
|
|
62
60
|
} else {
|
|
@@ -79,6 +77,10 @@ export class Meter {
|
|
|
79
77
|
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
80
78
|
}
|
|
81
79
|
|
|
80
|
+
// Meter Config
|
|
81
|
+
this.debugLog(`Meter: ${this.accessory.displayName} Config: (ble: ${device.ble}, hide_temperature: ${device.meter?.hide_temperature},`
|
|
82
|
+
+ ` hide_humidity: ${device.meter?.hide_humidity})`);
|
|
83
|
+
|
|
82
84
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
83
85
|
this.doMeterUpdate = new Subject();
|
|
84
86
|
this.meterUpdateInProgress = false;
|
|
@@ -115,11 +117,11 @@ export class Meter {
|
|
|
115
117
|
|
|
116
118
|
// Temperature Sensor Service
|
|
117
119
|
if (device.meter?.hide_temperature) {
|
|
118
|
-
this.
|
|
120
|
+
this.debugLog(`Meter: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
119
121
|
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
120
122
|
accessory.removeService(this.temperatureservice!);
|
|
121
123
|
} else if (!this.temperatureservice) {
|
|
122
|
-
this.
|
|
124
|
+
this.debugLog(`Meter: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
123
125
|
(this.temperatureservice =
|
|
124
126
|
this.accessory.getService(this.platform.Service.TemperatureSensor) ||
|
|
125
127
|
this.accessory.addService(this.platform.Service.TemperatureSensor)), `${accessory.displayName} Temperature Sensor`;
|
|
@@ -139,16 +141,16 @@ export class Meter {
|
|
|
139
141
|
return this.CurrentTemperature;
|
|
140
142
|
});
|
|
141
143
|
} else {
|
|
142
|
-
this.
|
|
144
|
+
this.debugLog(`Meter: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
143
145
|
}
|
|
144
146
|
|
|
145
147
|
// Humidity Sensor Service
|
|
146
148
|
if (device.meter?.hide_humidity) {
|
|
147
|
-
this.
|
|
149
|
+
this.debugLog(`Meter: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
148
150
|
this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor);
|
|
149
151
|
accessory.removeService(this.humidityservice!);
|
|
150
152
|
} else if (!this.humidityservice) {
|
|
151
|
-
this.
|
|
153
|
+
this.debugLog(`Meter: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
152
154
|
(this.humidityservice =
|
|
153
155
|
this.accessory.getService(this.platform.Service.HumiditySensor) ||
|
|
154
156
|
this.accessory.addService(this.platform.Service.HumiditySensor)), `${accessory.displayName} Humidity Sensor`;
|
|
@@ -164,20 +166,53 @@ export class Meter {
|
|
|
164
166
|
return this.CurrentRelativeHumidity;
|
|
165
167
|
});
|
|
166
168
|
} else {
|
|
167
|
-
this.
|
|
169
|
+
this.debugLog(`Meter: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
168
170
|
}
|
|
169
171
|
|
|
170
172
|
// Retrieve initial values and updateHomekit
|
|
171
173
|
this.updateHomeKitCharacteristics();
|
|
172
174
|
|
|
173
175
|
// Start an update interval
|
|
174
|
-
interval(this.
|
|
176
|
+
interval(this.deviceRefreshRate * 1000)
|
|
175
177
|
.pipe(skipWhile(() => this.meterUpdateInProgress))
|
|
176
178
|
.subscribe(() => {
|
|
177
179
|
this.refreshStatus();
|
|
178
180
|
});
|
|
179
181
|
}
|
|
180
182
|
|
|
183
|
+
refreshRate() {
|
|
184
|
+
if (this.device.refreshRate) {
|
|
185
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.device.refreshRate;
|
|
186
|
+
if (this.platform.debugMode) {
|
|
187
|
+
this.warnLog(`Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
188
|
+
}
|
|
189
|
+
} else if (this.platform.config.options!.refreshRate) {
|
|
190
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options!.refreshRate;
|
|
191
|
+
if (this.platform.debugMode) {
|
|
192
|
+
this.warnLog(`Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
logs() {
|
|
198
|
+
if (this.device.logging) {
|
|
199
|
+
this.deviceLogging = this.accessory.context.logging = this.device.logging;
|
|
200
|
+
if (this.platform.debugMode) {
|
|
201
|
+
this.warnLog(`Using Device Config Logging: ${this.deviceLogging}`);
|
|
202
|
+
}
|
|
203
|
+
} else if (this.platform.config.options?.logging) {
|
|
204
|
+
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
205
|
+
if (this.platform.debugMode) {
|
|
206
|
+
this.warnLog(`Using Platform Config Logging: ${this.deviceLogging}`);
|
|
207
|
+
}
|
|
208
|
+
} else {
|
|
209
|
+
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
210
|
+
if (this.platform.debugMode) {
|
|
211
|
+
this.warnLog('Using Device Standard Logging');
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
181
216
|
/**
|
|
182
217
|
* Parse the device status from the SwitchBot api
|
|
183
218
|
*/
|
|
@@ -190,7 +225,7 @@ export class Meter {
|
|
|
190
225
|
}
|
|
191
226
|
|
|
192
227
|
private async BLEparseStatus() {
|
|
193
|
-
this.
|
|
228
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BLE parseStatus`);
|
|
194
229
|
|
|
195
230
|
// Battery
|
|
196
231
|
this.BatteryLevel = Number(this.battery);
|
|
@@ -199,25 +234,25 @@ export class Meter {
|
|
|
199
234
|
} else {
|
|
200
235
|
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
201
236
|
}
|
|
202
|
-
this.
|
|
237
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
203
238
|
|
|
204
239
|
if (!this.device.meter?.hide_humidity) {
|
|
205
240
|
// Humidity
|
|
206
241
|
this.CurrentRelativeHumidity = Number(this.humidity);
|
|
207
|
-
this.
|
|
242
|
+
this.debugLog(`Meter: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
208
243
|
}
|
|
209
244
|
|
|
210
245
|
// Current Temperature
|
|
211
246
|
if (!this.device.meter?.hide_temperature) {
|
|
212
247
|
this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
|
|
213
248
|
this.CurrentTemperature = this.temperature;
|
|
214
|
-
this.
|
|
249
|
+
this.debugLog(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
215
250
|
}
|
|
216
251
|
}
|
|
217
252
|
|
|
218
253
|
private async openAPIparseStatus() {
|
|
219
254
|
if (this.platform.config.credentials?.openToken) {
|
|
220
|
-
this.
|
|
255
|
+
this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI parseStatus`);
|
|
221
256
|
if (this.deviceStatus.body) {
|
|
222
257
|
this.BatteryLevel = 100;
|
|
223
258
|
} else {
|
|
@@ -231,13 +266,13 @@ export class Meter {
|
|
|
231
266
|
// Current Relative Humidity
|
|
232
267
|
if (!this.device.meter?.hide_humidity) {
|
|
233
268
|
this.CurrentRelativeHumidity = this.deviceStatus.body.humidity!;
|
|
234
|
-
this.
|
|
269
|
+
this.debugLog(`Meter: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
235
270
|
}
|
|
236
271
|
|
|
237
272
|
// Current Temperature
|
|
238
273
|
if (!this.device.meter?.hide_temperature) {
|
|
239
274
|
this.CurrentTemperature = Number(this.deviceStatus.body.temperature);
|
|
240
|
-
this.
|
|
275
|
+
this.debugLog(`Meter: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
241
276
|
}
|
|
242
277
|
}
|
|
243
278
|
}
|
|
@@ -247,25 +282,26 @@ export class Meter {
|
|
|
247
282
|
*/
|
|
248
283
|
async refreshStatus() {
|
|
249
284
|
if (this.device.ble) {
|
|
250
|
-
|
|
285
|
+
this.BLErefreshStatus();
|
|
251
286
|
} else {
|
|
252
|
-
|
|
287
|
+
this.openAPIRefreshStatus();
|
|
253
288
|
}
|
|
254
289
|
}
|
|
255
290
|
|
|
256
291
|
private connectBLE() {
|
|
257
292
|
const switchbot = new Switchbot();
|
|
258
293
|
this.device.bleMac = ((this.device.deviceId!.match(/.{1,2}/g))!.join(':')).toLowerCase();
|
|
259
|
-
this.
|
|
294
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
260
295
|
return switchbot;
|
|
261
296
|
}
|
|
262
297
|
|
|
263
|
-
private
|
|
264
|
-
this.
|
|
298
|
+
private BLErefreshStatus() {
|
|
299
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BLE RefreshStatus`);
|
|
265
300
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
266
301
|
const switchbot = this.connectBLE();
|
|
267
302
|
// Start to monitor advertisement packets
|
|
268
303
|
switchbot.startScan({
|
|
304
|
+
model: 'T',
|
|
269
305
|
id: this.device.bleMac,
|
|
270
306
|
}).then(() => {
|
|
271
307
|
// Set an event hander
|
|
@@ -274,17 +310,17 @@ export class Meter {
|
|
|
274
310
|
this.temperature = ad.serviceData.temperature!.c;
|
|
275
311
|
this.humidity = ad.serviceData.humidity;
|
|
276
312
|
this.battery = ad.serviceData.battery;
|
|
277
|
-
this.
|
|
278
|
-
this.
|
|
313
|
+
this.debugLog(`Meter: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
314
|
+
this.debugLog(`Meter: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, `
|
|
279
315
|
+ `temperature: ${JSON.stringify(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, `
|
|
280
316
|
+ `battery: ${ad.serviceData.battery}`);
|
|
281
317
|
|
|
282
318
|
if (this.serviceData) {
|
|
283
319
|
this.connected = true;
|
|
284
|
-
this.
|
|
320
|
+
this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
285
321
|
} else {
|
|
286
322
|
this.connected = false;
|
|
287
|
-
this.
|
|
323
|
+
this.debugLog(`Meter: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
288
324
|
}
|
|
289
325
|
};
|
|
290
326
|
// Wait 10 seconds
|
|
@@ -302,36 +338,36 @@ export class Meter {
|
|
|
302
338
|
this.parseStatus();
|
|
303
339
|
this.updateHomeKitCharacteristics();
|
|
304
340
|
} else {
|
|
305
|
-
this.
|
|
341
|
+
this.errorLog(`Meter: ${this.accessory.displayName} wasn't able to establish BLE Connection`);
|
|
306
342
|
if (this.platform.config.credentials?.openToken) {
|
|
307
|
-
this.
|
|
308
|
-
|
|
343
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
344
|
+
this.openAPIRefreshStatus();
|
|
309
345
|
}
|
|
310
346
|
}
|
|
311
347
|
}).catch(async (e: any) => {
|
|
312
|
-
this.
|
|
313
|
-
if (this.
|
|
314
|
-
this.
|
|
348
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
349
|
+
if (this.deviceLogging === 'debug') {
|
|
350
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
315
351
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
316
352
|
}
|
|
317
|
-
if (this.
|
|
318
|
-
this.
|
|
353
|
+
if (this.platform.debugMode) {
|
|
354
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with BLE Connection,`
|
|
319
355
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
320
356
|
}
|
|
321
357
|
if (this.platform.config.credentials?.openToken) {
|
|
322
|
-
this.
|
|
323
|
-
|
|
358
|
+
this.warnLog(`Meter: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
359
|
+
this.openAPIRefreshStatus();
|
|
324
360
|
}
|
|
325
|
-
this.apiError(
|
|
361
|
+
this.apiError();
|
|
326
362
|
});
|
|
327
363
|
}
|
|
328
364
|
|
|
329
365
|
private async openAPIRefreshStatus() {
|
|
330
366
|
if (this.platform.config.credentials?.openToken) {
|
|
331
|
-
this.
|
|
367
|
+
this.debugLog(`Meter: ${this.accessory.displayName} OpenAPI RefreshStatus`);
|
|
332
368
|
try {
|
|
333
369
|
this.deviceStatus = (await this.platform.axios.get(`${DeviceURL}/${this.device.deviceId}/status`)).data;
|
|
334
|
-
this.
|
|
370
|
+
this.debugLog(`Meter: ${this.accessory.displayName} openAPIRefreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
335
371
|
this.CurrentTemperatureCached = this.deviceStatus.body.humidity!;
|
|
336
372
|
this.accessory.context.CurrentTemperature = this.CurrentTemperatureCached;
|
|
337
373
|
this.CurrentRelativeHumidityCached = this.deviceStatus.body.humidity!;
|
|
@@ -341,16 +377,16 @@ export class Meter {
|
|
|
341
377
|
this.parseStatus();
|
|
342
378
|
this.updateHomeKitCharacteristics();
|
|
343
379
|
} catch (e: any) {
|
|
344
|
-
this.
|
|
345
|
-
if (this.
|
|
346
|
-
this.
|
|
380
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection`);
|
|
381
|
+
if (this.deviceLogging === 'debug') {
|
|
382
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
347
383
|
+ ` Error Message: ${JSON.stringify(e.message)}`);
|
|
348
384
|
}
|
|
349
|
-
if (this.
|
|
350
|
-
this.
|
|
385
|
+
if (this.platform.debugMode) {
|
|
386
|
+
this.errorLog(`Meter: ${this.accessory.displayName} failed refreshStatus with OpenAPI Connection,`
|
|
351
387
|
+ ` Error: ${JSON.stringify(e)}`);
|
|
352
388
|
}
|
|
353
|
-
this.apiError(
|
|
389
|
+
this.apiError();
|
|
354
390
|
}
|
|
355
391
|
}
|
|
356
392
|
}
|
|
@@ -360,43 +396,71 @@ export class Meter {
|
|
|
360
396
|
*/
|
|
361
397
|
updateHomeKitCharacteristics() {
|
|
362
398
|
if (this.StatusLowBattery === undefined) {
|
|
363
|
-
this.
|
|
399
|
+
this.debugLog(`Meter: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
364
400
|
} else {
|
|
365
401
|
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
366
|
-
this.
|
|
402
|
+
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
367
403
|
}
|
|
368
404
|
if (this.BatteryLevel === undefined) {
|
|
369
|
-
this.
|
|
405
|
+
this.debugLog(`Meter: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
370
406
|
} else {
|
|
371
407
|
this.service.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
372
|
-
this.
|
|
408
|
+
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
373
409
|
}
|
|
374
410
|
if (!this.device.meter?.hide_humidity) {
|
|
375
411
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
376
|
-
this.
|
|
412
|
+
this.debugLog(`Meter: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
377
413
|
} else {
|
|
378
414
|
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
379
|
-
this.
|
|
415
|
+
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
380
416
|
}
|
|
381
417
|
}
|
|
382
418
|
if (!this.device.meter?.hide_temperature) {
|
|
383
419
|
if (this.CurrentTemperature === undefined) {
|
|
384
|
-
this.
|
|
420
|
+
this.debugLog(`Meter: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
385
421
|
} else {
|
|
386
422
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
387
|
-
this.
|
|
423
|
+
this.debugLog(`Meter: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
388
424
|
}
|
|
389
425
|
}
|
|
390
426
|
}
|
|
391
427
|
|
|
392
|
-
public apiError(
|
|
393
|
-
this.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
428
|
+
public apiError() {
|
|
429
|
+
throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Logging for Device
|
|
434
|
+
*/
|
|
435
|
+
infoLog(...log: any[]) {
|
|
436
|
+
if (this.enablingDeviceLogging()) {
|
|
437
|
+
this.platform.log.info(String(...log));
|
|
397
438
|
}
|
|
398
|
-
|
|
399
|
-
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
warnLog(...log: any[]) {
|
|
442
|
+
if (this.enablingDeviceLogging()) {
|
|
443
|
+
this.platform.log.warn(String(...log));
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
errorLog(...log: any[]) {
|
|
448
|
+
if (this.enablingDeviceLogging()) {
|
|
449
|
+
this.platform.log.error(String(...log));
|
|
400
450
|
}
|
|
401
451
|
}
|
|
452
|
+
|
|
453
|
+
debugLog(...log: any[]) {
|
|
454
|
+
if (this.enablingDeviceLogging()) {
|
|
455
|
+
if (this.deviceLogging === 'debug') {
|
|
456
|
+
this.platform.log.info('[DEBUG]', String(...log));
|
|
457
|
+
} else {
|
|
458
|
+
this.platform.log.debug(String(...log));
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
enablingDeviceLogging(): boolean {
|
|
464
|
+
return this.deviceLogging === 'debug' || this.deviceLogging === 'standard';
|
|
465
|
+
}
|
|
402
466
|
}
|