@switchbot/homebridge-switchbot 2.0.0-beta.3 → 2.0.0-beta.31
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 +8 -1
- package/README.md +1 -2
- package/config.schema.json +75 -20
- package/dist/device/bot.d.ts +34 -28
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +655 -649
- package/dist/device/bot.js.map +1 -1
- package/dist/device/colorbulb.d.ts +36 -19
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +483 -309
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +18 -8
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +303 -237
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +23 -16
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +541 -498
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/humidifier.d.ts +24 -18
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +450 -369
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/lock.d.ts +27 -8
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +302 -148
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +22 -16
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +340 -262
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +24 -12
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +359 -213
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +18 -8
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +276 -216
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +27 -17
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +292 -251
- package/dist/device/plug.js.map +1 -1
- package/dist/device/striplight.d.ts +43 -19
- package/dist/device/striplight.d.ts.map +1 -1
- package/dist/device/striplight.js +503 -262
- package/dist/device/striplight.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -12
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +275 -230
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +5 -3
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +151 -104
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +11 -8
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +130 -86
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -7
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +157 -109
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/light.d.ts +11 -8
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +134 -103
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +11 -8
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +142 -98
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +12 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +140 -93
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +9 -10
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +129 -89
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +8 -9
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +129 -89
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +14 -12
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +456 -434
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +16 -11
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/package.json +12 -10
- package/src/device/bot.ts +654 -660
- package/src/device/colorbulb.ts +487 -344
- package/src/device/contact.ts +306 -241
- package/src/device/curtain.ts +546 -512
- package/src/device/humidifier.ts +453 -403
- package/src/device/lock.ts +311 -149
- package/src/device/meter.ts +351 -275
- package/src/device/meterplus.ts +369 -219
- package/src/device/motion.ts +282 -222
- package/src/device/plug.ts +296 -260
- package/src/device/striplight.ts +519 -289
- package/src/irdevice/airconditioner.ts +279 -241
- package/src/irdevice/airpurifier.ts +148 -103
- package/src/irdevice/camera.ts +128 -85
- package/src/irdevice/fan.ts +154 -106
- package/src/irdevice/light.ts +132 -103
- package/src/irdevice/other.ts +140 -97
- package/src/irdevice/tv.ts +139 -93
- package/src/irdevice/vacuumcleaner.ts +128 -89
- package/src/irdevice/waterheater.ts +127 -89
- package/src/platform.ts +447 -457
- package/src/settings.ts +16 -11
package/dist/device/meterplus.js
CHANGED
|
@@ -6,8 +6,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.MeterPlus = void 0;
|
|
7
7
|
const https_1 = __importDefault(require("https"));
|
|
8
8
|
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
const os_1 = require("os");
|
|
10
|
+
const async_mqtt_1 = require("async-mqtt");
|
|
9
11
|
const rxjs_1 = require("rxjs");
|
|
10
12
|
const operators_1 = require("rxjs/operators");
|
|
13
|
+
const super_stringify_1 = __importDefault(require("super-stringify"));
|
|
11
14
|
const settings_1 = require("../settings");
|
|
12
15
|
/**
|
|
13
16
|
* Platform Accessory
|
|
@@ -19,23 +22,19 @@ class MeterPlus {
|
|
|
19
22
|
this.platform = platform;
|
|
20
23
|
this.accessory = accessory;
|
|
21
24
|
this.device = device;
|
|
25
|
+
//MQTT stuff
|
|
26
|
+
this.mqttClient = null;
|
|
27
|
+
// Connection
|
|
28
|
+
this.BLE = (this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI');
|
|
29
|
+
this.OpenAPI = (this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI');
|
|
22
30
|
// default placeholders
|
|
23
31
|
this.logs(device);
|
|
24
32
|
this.scan(device);
|
|
25
33
|
this.refreshRate(device);
|
|
26
34
|
this.config(device);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
else {
|
|
31
|
-
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
32
|
-
}
|
|
33
|
-
if (this.CurrentTemperature === undefined) {
|
|
34
|
-
this.CurrentTemperature = 0;
|
|
35
|
-
}
|
|
36
|
-
else {
|
|
37
|
-
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
38
|
-
}
|
|
35
|
+
this.context();
|
|
36
|
+
this.setupHistoryService(device);
|
|
37
|
+
this.setupMqtt(device);
|
|
39
38
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
40
39
|
this.doMeterUpdate = new rxjs_1.Subject();
|
|
41
40
|
this.meterUpdateInProgress = false;
|
|
@@ -52,12 +51,12 @@ class MeterPlus {
|
|
|
52
51
|
.updateValue(this.FirmwareRevision(accessory, device));
|
|
53
52
|
// Temperature Sensor Service
|
|
54
53
|
if (device.meter?.hide_temperature) {
|
|
55
|
-
this.debugLog(
|
|
54
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
56
55
|
this.temperatureservice = this.accessory.getService(this.platform.Service.TemperatureSensor);
|
|
57
56
|
accessory.removeService(this.temperatureservice);
|
|
58
57
|
}
|
|
59
58
|
else if (!this.temperatureservice) {
|
|
60
|
-
this.debugLog(
|
|
59
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Temperature Sensor Service`);
|
|
61
60
|
(this.temperatureservice =
|
|
62
61
|
this.accessory.getService(this.platform.Service.TemperatureSensor) || this.accessory.addService(this.platform.Service.TemperatureSensor)),
|
|
63
62
|
`${accessory.displayName} Temperature Sensor`;
|
|
@@ -76,16 +75,16 @@ class MeterPlus {
|
|
|
76
75
|
});
|
|
77
76
|
}
|
|
78
77
|
else {
|
|
79
|
-
this.debugLog(
|
|
78
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
|
|
80
79
|
}
|
|
81
80
|
// Humidity Sensor Service
|
|
82
81
|
if (device.meter?.hide_humidity) {
|
|
83
|
-
this.debugLog(
|
|
82
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
|
|
84
83
|
this.humidityservice = this.accessory.getService(this.platform.Service.HumiditySensor);
|
|
85
84
|
accessory.removeService(this.humidityservice);
|
|
86
85
|
}
|
|
87
86
|
else if (!this.humidityservice) {
|
|
88
|
-
this.debugLog(
|
|
87
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Humidity Sensor Service`);
|
|
89
88
|
(this.humidityservice =
|
|
90
89
|
this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor)),
|
|
91
90
|
`${accessory.displayName} Humidity Sensor`;
|
|
@@ -100,23 +99,23 @@ class MeterPlus {
|
|
|
100
99
|
});
|
|
101
100
|
}
|
|
102
101
|
else {
|
|
103
|
-
this.debugLog(
|
|
102
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
|
|
104
103
|
}
|
|
105
104
|
// Battery Service
|
|
106
|
-
if (!
|
|
107
|
-
this.debugLog(
|
|
105
|
+
if (!this.BLE) {
|
|
106
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Battery Service`);
|
|
108
107
|
this.batteryService = this.accessory.getService(this.platform.Service.Battery);
|
|
109
108
|
accessory.removeService(this.batteryService);
|
|
110
109
|
}
|
|
111
|
-
else if (
|
|
112
|
-
this.debugLog(
|
|
110
|
+
else if (this.BLE && !this.batteryService) {
|
|
111
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Battery Service`);
|
|
113
112
|
(this.batteryService = this.accessory.getService(this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery)),
|
|
114
113
|
`${accessory.displayName} Battery`;
|
|
115
114
|
this.batteryService.setCharacteristic(this.platform.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
116
115
|
this.batteryService.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE);
|
|
117
116
|
}
|
|
118
117
|
else {
|
|
119
|
-
this.debugLog(
|
|
118
|
+
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Battery Service Not Added`);
|
|
120
119
|
}
|
|
121
120
|
// Retrieve initial values and updateHomekit
|
|
122
121
|
this.updateHomeKitCharacteristics();
|
|
@@ -131,15 +130,19 @@ class MeterPlus {
|
|
|
131
130
|
* Parse the device status from the SwitchBot api
|
|
132
131
|
*/
|
|
133
132
|
async parseStatus() {
|
|
134
|
-
if (this.
|
|
133
|
+
if (this.BLE) {
|
|
134
|
+
await this.BLEparseStatus();
|
|
135
|
+
}
|
|
136
|
+
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
135
137
|
await this.openAPIparseStatus();
|
|
136
138
|
}
|
|
137
139
|
else {
|
|
138
|
-
|
|
140
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
141
|
+
+ ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
141
144
|
async BLEparseStatus() {
|
|
142
|
-
this.debugLog(
|
|
145
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
143
146
|
// Battery
|
|
144
147
|
this.BatteryLevel = Number(this.battery);
|
|
145
148
|
if (this.BatteryLevel < 15) {
|
|
@@ -152,53 +155,52 @@ class MeterPlus {
|
|
|
152
155
|
// Humidity
|
|
153
156
|
if (!this.device.meter?.hide_humidity) {
|
|
154
157
|
this.CurrentRelativeHumidity = this.humidity;
|
|
155
|
-
this.debugLog(
|
|
158
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
156
159
|
}
|
|
157
160
|
// Current Temperature
|
|
158
161
|
if (!this.device.meter?.hide_temperature) {
|
|
159
162
|
this.temperature < 0 ? 0 : this.temperature > 100 ? 100 : this.temperature;
|
|
160
163
|
this.CurrentTemperature = this.temperature;
|
|
161
|
-
this.debugLog(
|
|
164
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
162
165
|
}
|
|
163
166
|
}
|
|
164
167
|
async openAPIparseStatus() {
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
169
|
+
// Current Relative Humidity
|
|
170
|
+
if (!this.device.meter?.hide_humidity) {
|
|
171
|
+
this.CurrentRelativeHumidity = this.Humidity;
|
|
172
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
167
173
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
this.CurrentRelativeHumidity = this.Humidity;
|
|
173
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} Humidity: ${this.CurrentRelativeHumidity}%`);
|
|
174
|
-
}
|
|
175
|
-
// Current Temperature
|
|
176
|
-
if (!this.device.meter?.hide_temperature) {
|
|
177
|
-
this.CurrentTemperature = this.Temperature;
|
|
178
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
179
|
-
}
|
|
174
|
+
// Current Temperature
|
|
175
|
+
if (!this.device.meter?.hide_temperature) {
|
|
176
|
+
this.CurrentTemperature = this.Temperature;
|
|
177
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Temperature: ${this.CurrentTemperature}°c`);
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
/**
|
|
183
181
|
* Asks the SwitchBot API for the latest device information
|
|
184
182
|
*/
|
|
185
183
|
async refreshStatus() {
|
|
186
|
-
if (this.
|
|
187
|
-
this.
|
|
184
|
+
if (this.BLE) {
|
|
185
|
+
await this.BLERefreshStatus();
|
|
186
|
+
}
|
|
187
|
+
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
188
|
+
await this.openAPIRefreshStatus();
|
|
188
189
|
}
|
|
189
190
|
else {
|
|
190
|
-
this.
|
|
191
|
+
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:`
|
|
192
|
+
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
|
-
async
|
|
194
|
-
this.debugLog(
|
|
195
|
+
async BLERefreshStatus() {
|
|
196
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLERefreshStatus`);
|
|
195
197
|
const switchbot = await this.platform.connectBLE();
|
|
196
198
|
// Convert to BLE Address
|
|
197
199
|
this.device.bleMac = this.device
|
|
198
200
|
.deviceId.match(/.{1,2}/g)
|
|
199
201
|
.join(':')
|
|
200
202
|
.toLowerCase();
|
|
201
|
-
this.debugLog(
|
|
203
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLE Address: ${this.device.bleMac}`);
|
|
202
204
|
this.getCustomBLEAddress(switchbot);
|
|
203
205
|
// Start to monitor advertisement packets
|
|
204
206
|
if (switchbot !== false) {
|
|
@@ -211,27 +213,26 @@ class MeterPlus {
|
|
|
211
213
|
// Set an event hander
|
|
212
214
|
switchbot.onadvertisement = (ad) => {
|
|
213
215
|
this.address = ad.address;
|
|
214
|
-
|
|
215
|
-
this.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.
|
|
216
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Config BLE Address: ${this.device.bleMac},`
|
|
217
|
+
+ ` BLE Address Found: ${this.address}`);
|
|
218
|
+
if (ad.serviceData.humidity > 0) {
|
|
219
|
+
// reject unreliable data
|
|
220
|
+
this.humidity = ad.serviceData.humidity;
|
|
219
221
|
}
|
|
220
222
|
this.serviceData = ad.serviceData;
|
|
221
223
|
this.temperature = ad.serviceData.temperature.c;
|
|
222
|
-
this.humidity = ad.serviceData.humidity;
|
|
223
224
|
this.battery = ad.serviceData.battery;
|
|
224
|
-
this.debugLog(
|
|
225
|
-
this.debugLog(
|
|
226
|
-
`temperature: ${
|
|
225
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${(0, super_stringify_1.default)(ad.serviceData)}`);
|
|
226
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} model: ${ad.serviceData.model}, modelName: ${ad.serviceData.modelName}, ` +
|
|
227
|
+
`temperature: ${(0, super_stringify_1.default)(ad.serviceData.temperature?.c)}, humidity: ${ad.serviceData.humidity}, ` +
|
|
227
228
|
`battery: ${ad.serviceData.battery}`);
|
|
228
229
|
if (this.serviceData) {
|
|
229
230
|
this.connected = true;
|
|
230
|
-
this.debugLog(
|
|
231
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
231
232
|
}
|
|
232
233
|
else {
|
|
233
234
|
this.connected = false;
|
|
234
|
-
this.debugLog(
|
|
235
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} connected: ${this.connected}`);
|
|
235
236
|
}
|
|
236
237
|
};
|
|
237
238
|
// Wait 10 seconds
|
|
@@ -245,147 +246,273 @@ class MeterPlus {
|
|
|
245
246
|
this.updateHomeKitCharacteristics();
|
|
246
247
|
}
|
|
247
248
|
else {
|
|
248
|
-
await this.
|
|
249
|
+
await this.BLERefreshConnection(switchbot);
|
|
249
250
|
}
|
|
250
251
|
})
|
|
251
252
|
.catch(async (e) => {
|
|
252
|
-
this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection`);
|
|
253
|
-
if (this.deviceLogging.includes('debug')) {
|
|
254
|
-
this.errorLog(`Meter Plus: ${this.accessory.displayName} failed refreshStatus with BLE Connection,` + ` Error Message: ${JSON.stringify(e.message)}`);
|
|
255
|
-
}
|
|
256
|
-
if (this.platform.config.credentials?.token) {
|
|
257
|
-
this.warnLog(`Meter Plus: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
258
|
-
this.SwitchToOpenAPI = true;
|
|
259
|
-
this.openAPIRefreshStatus();
|
|
260
|
-
}
|
|
261
253
|
this.apiError(e);
|
|
254
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed BLERefreshStatus with ${this.device.connectionType}`
|
|
255
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
256
|
+
await this.BLERefreshConnection(switchbot);
|
|
262
257
|
});
|
|
263
258
|
}
|
|
264
259
|
else {
|
|
265
|
-
await this.
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
async getCustomBLEAddress(switchbot) {
|
|
269
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
270
|
-
(async () => {
|
|
271
|
-
// Start to monitor advertisement packets
|
|
272
|
-
await switchbot.startScan({
|
|
273
|
-
model: 'i',
|
|
274
|
-
});
|
|
275
|
-
// Set an event handler
|
|
276
|
-
switchbot.onadvertisement = (ad) => {
|
|
277
|
-
this.warnLog(`Meter Plus: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
278
|
-
};
|
|
279
|
-
await switchbot.wait(10000);
|
|
280
|
-
// Stop to monitor
|
|
281
|
-
switchbot.stopScan();
|
|
282
|
-
})();
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
async BLEconnection(switchbot) {
|
|
286
|
-
this.errorLog(`Meter Plus: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
287
|
-
if (this.platform.config.credentials?.token) {
|
|
288
|
-
this.warnLog(`Meter Plus: ${this.accessory.displayName} Using OpenAPI Connection`);
|
|
289
|
-
this.SwitchToOpenAPI = true;
|
|
290
|
-
await this.openAPIRefreshStatus();
|
|
260
|
+
await this.BLERefreshConnection(switchbot);
|
|
291
261
|
}
|
|
292
262
|
}
|
|
293
263
|
async openAPIRefreshStatus() {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} d: ${d}`);
|
|
322
|
-
});
|
|
323
|
-
res.on('end', () => {
|
|
324
|
-
try {
|
|
325
|
-
this.deviceStatus = JSON.parse(rawData);
|
|
326
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} openAPIRefreshStatus: ${JSON.stringify(this.deviceStatus)}`);
|
|
327
|
-
this.Humidity = this.deviceStatus.body.humidity;
|
|
328
|
-
this.Temperature = this.deviceStatus.body.temperature;
|
|
329
|
-
this.parseStatus();
|
|
330
|
-
this.updateHomeKitCharacteristics();
|
|
331
|
-
}
|
|
332
|
-
catch (e) {
|
|
333
|
-
this.errorLog(`Meter Plus: ${this.accessory.displayName} error message: ${e.message}`);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
264
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
265
|
+
try {
|
|
266
|
+
const t = Date.now();
|
|
267
|
+
const nonce = 'requestID';
|
|
268
|
+
const data = this.platform.config.credentials?.token + t + nonce;
|
|
269
|
+
const signTerm = crypto_1.default.createHmac('sha256', this.platform.config.credentials?.secret).update(Buffer.from(data, 'utf-8')).digest();
|
|
270
|
+
const sign = signTerm.toString('base64');
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} sign: ${sign}`);
|
|
272
|
+
const options = {
|
|
273
|
+
hostname: settings_1.HostDomain,
|
|
274
|
+
port: 443,
|
|
275
|
+
path: `${settings_1.DevicePath}/${this.device.deviceId}/status`,
|
|
276
|
+
method: 'GET',
|
|
277
|
+
headers: {
|
|
278
|
+
Authorization: this.platform.config.credentials?.token,
|
|
279
|
+
sign: sign,
|
|
280
|
+
nonce: nonce,
|
|
281
|
+
t: t,
|
|
282
|
+
'Content-Type': 'application/json',
|
|
283
|
+
},
|
|
284
|
+
};
|
|
285
|
+
const req = https_1.default.request(options, (res) => {
|
|
286
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus statusCode: ${res.statusCode}`);
|
|
287
|
+
let rawData = '';
|
|
288
|
+
res.on('data', (d) => {
|
|
289
|
+
rawData += d;
|
|
290
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} d: ${d}`);
|
|
336
291
|
});
|
|
337
|
-
|
|
338
|
-
|
|
292
|
+
res.on('end', () => {
|
|
293
|
+
try {
|
|
294
|
+
this.deviceStatus = JSON.parse(rawData);
|
|
295
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus: ${(0, super_stringify_1.default)(this.deviceStatus)}`);
|
|
296
|
+
this.Humidity = this.deviceStatus.body.humidity;
|
|
297
|
+
this.Temperature = this.deviceStatus.body.temperature;
|
|
298
|
+
this.parseStatus();
|
|
299
|
+
this.updateHomeKitCharacteristics();
|
|
300
|
+
}
|
|
301
|
+
catch (e) {
|
|
302
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
303
|
+
}
|
|
339
304
|
});
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
305
|
+
});
|
|
306
|
+
req.on('error', (e) => {
|
|
307
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} error message: ${e.message}`);
|
|
308
|
+
});
|
|
309
|
+
req.end();
|
|
310
|
+
}
|
|
311
|
+
catch (e) {
|
|
312
|
+
this.apiError(e);
|
|
313
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} failed openAPIRefreshStatus with ${this.device.connectionType}`
|
|
314
|
+
+ ` Connection, Error Message: ${(0, super_stringify_1.default)(e.message)}`);
|
|
350
315
|
}
|
|
351
316
|
}
|
|
352
317
|
/**
|
|
353
318
|
* Updates the status for each of the HomeKit Characteristics
|
|
354
319
|
*/
|
|
355
320
|
async updateHomeKitCharacteristics() {
|
|
321
|
+
const mqttmessage = [];
|
|
322
|
+
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
356
323
|
if (!this.device.meter?.hide_humidity) {
|
|
357
324
|
if (this.CurrentRelativeHumidity === undefined) {
|
|
358
|
-
this.debugLog(
|
|
325
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
359
326
|
}
|
|
360
327
|
else {
|
|
328
|
+
this.accessory.context.CurrentRelativeHumidity = this.CurrentRelativeHumidity;
|
|
361
329
|
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.CurrentRelativeHumidity);
|
|
362
|
-
this.debugLog(
|
|
330
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
331
|
+
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.CurrentRelativeHumidity}`);
|
|
332
|
+
mqttmessage.push(`"humidity": ${this.CurrentRelativeHumidity}`);
|
|
333
|
+
entry['humidity'] = this.CurrentRelativeHumidity;
|
|
363
334
|
}
|
|
364
335
|
}
|
|
365
336
|
if (!this.device.meter?.hide_temperature) {
|
|
366
337
|
if (this.CurrentTemperature === undefined) {
|
|
367
|
-
this.debugLog(
|
|
338
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} CurrentTemperature: ${this.CurrentTemperature}`);
|
|
368
339
|
}
|
|
369
340
|
else {
|
|
341
|
+
mqttmessage.push(`"temperature": ${this.CurrentTemperature}`);
|
|
342
|
+
entry['temp'] = this.CurrentTemperature;
|
|
343
|
+
this.accessory.context.CurrentTemperature = this.CurrentTemperature;
|
|
370
344
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.CurrentTemperature);
|
|
371
|
-
this.debugLog(
|
|
345
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic CurrentTemperature: ${this.CurrentTemperature}`);
|
|
372
346
|
}
|
|
373
347
|
}
|
|
374
|
-
if (this.
|
|
348
|
+
if (this.BLE) {
|
|
375
349
|
if (this.BatteryLevel === undefined) {
|
|
376
|
-
this.debugLog(
|
|
350
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
377
351
|
}
|
|
378
352
|
else {
|
|
353
|
+
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
354
|
+
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
379
355
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.BatteryLevel);
|
|
380
|
-
this.debugLog(
|
|
356
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
381
357
|
}
|
|
382
358
|
if (this.StatusLowBattery === undefined) {
|
|
383
|
-
this.debugLog(
|
|
359
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
384
360
|
}
|
|
385
361
|
else {
|
|
362
|
+
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
363
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
386
364
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.StatusLowBattery);
|
|
387
|
-
this.debugLog(
|
|
365
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
369
|
+
if (this.CurrentRelativeHumidity > 0) {
|
|
370
|
+
// reject unreliable data
|
|
371
|
+
this.historyService?.addEntry(entry);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
/*
|
|
375
|
+
* Publish MQTT message for topics of
|
|
376
|
+
* 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
|
|
377
|
+
*/
|
|
378
|
+
mqttPublish(message) {
|
|
379
|
+
const mac = this.device.deviceId
|
|
380
|
+
?.toLowerCase()
|
|
381
|
+
.match(/[\s\S]{1,2}/g)
|
|
382
|
+
?.join(':');
|
|
383
|
+
const options = this.device.mqttPubOptions || {};
|
|
384
|
+
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
385
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${(0, super_stringify_1.default)(options)}`);
|
|
386
|
+
}
|
|
387
|
+
/*
|
|
388
|
+
* Setup MQTT hadler if URL is specifed.
|
|
389
|
+
*/
|
|
390
|
+
async setupMqtt(device) {
|
|
391
|
+
if (device.mqttURL) {
|
|
392
|
+
try {
|
|
393
|
+
this.mqttClient = await (0, async_mqtt_1.connectAsync)(device.mqttURL, device.mqttOptions || {});
|
|
394
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
395
|
+
this.mqttClient.on('error', (e) => {
|
|
396
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
catch (e) {
|
|
400
|
+
this.mqttClient = null;
|
|
401
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
/*
|
|
406
|
+
* Setup EVE history graph feature if enabled.
|
|
407
|
+
*/
|
|
408
|
+
async setupHistoryService(device) {
|
|
409
|
+
const mac = this.device
|
|
410
|
+
.deviceId.match(/.{1,2}/g)
|
|
411
|
+
.join(':')
|
|
412
|
+
.toLowerCase();
|
|
413
|
+
this.historyService = device.history
|
|
414
|
+
? new this.platform.fakegatoAPI('room', this.accessory, {
|
|
415
|
+
log: this.platform.log,
|
|
416
|
+
storage: 'fs',
|
|
417
|
+
filename: `${(0, os_1.hostname)().split('.')[0]}_${mac}_persist.json`,
|
|
418
|
+
})
|
|
419
|
+
: null;
|
|
420
|
+
}
|
|
421
|
+
async getCustomBLEAddress(switchbot) {
|
|
422
|
+
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
423
|
+
(async () => {
|
|
424
|
+
// Start to monitor advertisement packets
|
|
425
|
+
await switchbot.startScan({
|
|
426
|
+
model: 'i',
|
|
427
|
+
});
|
|
428
|
+
// Set an event handler
|
|
429
|
+
switchbot.onadvertisement = (ad) => {
|
|
430
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${(0, super_stringify_1.default)(ad, null, ' ')}`);
|
|
431
|
+
};
|
|
432
|
+
await switchbot.wait(10000);
|
|
433
|
+
// Stop to monitor
|
|
434
|
+
switchbot.stopScan();
|
|
435
|
+
})();
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
async BLERefreshConnection(switchbot) {
|
|
439
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
440
|
+
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
441
|
+
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} Using OpenAPI Connection to Refresh Status`);
|
|
442
|
+
await this.openAPIRefreshStatus();
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
model(device) {
|
|
446
|
+
let model;
|
|
447
|
+
if (device.deviceType === 'Meter Plus (JP)') {
|
|
448
|
+
model = 'W2201500';
|
|
449
|
+
}
|
|
450
|
+
else {
|
|
451
|
+
model = 'W2301500';
|
|
452
|
+
}
|
|
453
|
+
return model;
|
|
454
|
+
}
|
|
455
|
+
async scan(device) {
|
|
456
|
+
if (device.scanDuration) {
|
|
457
|
+
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
458
|
+
if (this.BLE) {
|
|
459
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
else {
|
|
463
|
+
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
464
|
+
if (this.BLE) {
|
|
465
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
async statusCode({ res }) {
|
|
470
|
+
switch (res.statusCode) {
|
|
471
|
+
case 151:
|
|
472
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this device type.`);
|
|
473
|
+
break;
|
|
474
|
+
case 152:
|
|
475
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found.`);
|
|
476
|
+
break;
|
|
477
|
+
case 160:
|
|
478
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported.`);
|
|
479
|
+
break;
|
|
480
|
+
case 161:
|
|
481
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline.`);
|
|
482
|
+
this.offlineOff();
|
|
483
|
+
break;
|
|
484
|
+
case 171:
|
|
485
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} is offline. Hub: ${this.device.hubDeviceId}`);
|
|
486
|
+
this.offlineOff();
|
|
487
|
+
break;
|
|
488
|
+
case 190:
|
|
489
|
+
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
490
|
+
` Or command: ${(0, super_stringify_1.default)(res)} format is invalid`);
|
|
491
|
+
break;
|
|
492
|
+
case 100:
|
|
493
|
+
if (this.platform.debugMode) {
|
|
494
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent.`);
|
|
495
|
+
}
|
|
496
|
+
break;
|
|
497
|
+
default:
|
|
498
|
+
if (this.platform.debugMode) {
|
|
499
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode.`);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
async offlineOff() {
|
|
504
|
+
if (this.device.offline) {
|
|
505
|
+
if (!this.device.meter?.hide_humidity) {
|
|
506
|
+
this.humidityservice?.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.accessory.context.CurrentRelativeHumidity);
|
|
507
|
+
}
|
|
508
|
+
if (!this.device.meter?.hide_temperature) {
|
|
509
|
+
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.accessory.context.CurrentTemperature);
|
|
510
|
+
}
|
|
511
|
+
if (this.BLE) {
|
|
512
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, this.accessory.context.BatteryLevel);
|
|
513
|
+
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.accessory.context.StatusLowBattery);
|
|
388
514
|
}
|
|
515
|
+
await this.updateHomeKitCharacteristics();
|
|
389
516
|
}
|
|
390
517
|
}
|
|
391
518
|
async apiError(e) {
|
|
@@ -395,29 +522,74 @@ class MeterPlus {
|
|
|
395
522
|
if (!this.device.meter?.hide_temperature) {
|
|
396
523
|
this.temperatureservice?.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, e);
|
|
397
524
|
}
|
|
398
|
-
if (this.
|
|
525
|
+
if (this.BLE) {
|
|
399
526
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.BatteryLevel, e);
|
|
400
527
|
this.batteryService?.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, e);
|
|
401
528
|
}
|
|
402
|
-
//throw new this.platform.api.hap.HapStatusError(HAPStatus.SERVICE_COMMUNICATION_FAILURE);
|
|
403
529
|
}
|
|
404
|
-
|
|
405
|
-
let
|
|
406
|
-
|
|
407
|
-
|
|
530
|
+
FirmwareRevision(accessory, device) {
|
|
531
|
+
let FirmwareRevision;
|
|
532
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
533
|
+
+ ` accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
534
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
535
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
536
|
+
if (accessory.context.FirmwareRevision) {
|
|
537
|
+
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
538
|
+
}
|
|
539
|
+
else if (device.firmware) {
|
|
540
|
+
FirmwareRevision = device.firmware;
|
|
408
541
|
}
|
|
409
542
|
else {
|
|
410
|
-
|
|
543
|
+
FirmwareRevision = this.platform.version;
|
|
544
|
+
}
|
|
545
|
+
return FirmwareRevision;
|
|
546
|
+
}
|
|
547
|
+
context() {
|
|
548
|
+
if (this.CurrentRelativeHumidity === undefined) {
|
|
549
|
+
this.CurrentRelativeHumidity = 0;
|
|
550
|
+
}
|
|
551
|
+
else {
|
|
552
|
+
this.CurrentRelativeHumidity = this.accessory.context.CurrentRelativeHumidity;
|
|
553
|
+
}
|
|
554
|
+
if (this.CurrentTemperature === undefined) {
|
|
555
|
+
this.CurrentTemperature = 0;
|
|
556
|
+
}
|
|
557
|
+
else {
|
|
558
|
+
this.CurrentTemperature = this.accessory.context.CurrentTemperature;
|
|
559
|
+
}
|
|
560
|
+
if (this.BLE) {
|
|
561
|
+
if (this.BatteryLevel === undefined) {
|
|
562
|
+
this.BatteryLevel = 100;
|
|
563
|
+
}
|
|
564
|
+
else {
|
|
565
|
+
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
566
|
+
}
|
|
567
|
+
if (this.StatusLowBattery === undefined) {
|
|
568
|
+
this.StatusLowBattery = this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
569
|
+
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
async refreshRate(device) {
|
|
577
|
+
if (device.refreshRate) {
|
|
578
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
579
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
580
|
+
}
|
|
581
|
+
else if (this.platform.config.options.refreshRate) {
|
|
582
|
+
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
583
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
411
584
|
}
|
|
412
|
-
return model;
|
|
413
585
|
}
|
|
414
586
|
async config(device) {
|
|
415
587
|
let config = {};
|
|
416
588
|
if (device.meter) {
|
|
417
589
|
config = device.meter;
|
|
418
590
|
}
|
|
419
|
-
if (device.
|
|
420
|
-
config['
|
|
591
|
+
if (device.connectionType !== undefined) {
|
|
592
|
+
config['connectionType'] = device.connectionType;
|
|
421
593
|
}
|
|
422
594
|
if (device.logging !== undefined) {
|
|
423
595
|
config['logging'] = device.logging;
|
|
@@ -429,66 +601,26 @@ class MeterPlus {
|
|
|
429
601
|
config['scanDuration'] = device.scanDuration;
|
|
430
602
|
}
|
|
431
603
|
if (Object.entries(config).length !== 0) {
|
|
432
|
-
this.infoLog(
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
async refreshRate(device) {
|
|
436
|
-
if (device.refreshRate) {
|
|
437
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
438
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
439
|
-
}
|
|
440
|
-
else if (this.platform.config.options.refreshRate) {
|
|
441
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
442
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
async scan(device) {
|
|
446
|
-
if (device.scanDuration) {
|
|
447
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
448
|
-
if (device.ble) {
|
|
449
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
else {
|
|
453
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
454
|
-
if (this.device.ble) {
|
|
455
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
456
|
-
}
|
|
604
|
+
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${(0, super_stringify_1.default)(config)}`);
|
|
457
605
|
}
|
|
458
606
|
}
|
|
459
607
|
async logs(device) {
|
|
460
608
|
if (this.platform.debugMode) {
|
|
461
609
|
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
462
|
-
this.debugLog(
|
|
610
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
463
611
|
}
|
|
464
612
|
else if (device.logging) {
|
|
465
613
|
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
466
|
-
this.debugLog(
|
|
614
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
467
615
|
}
|
|
468
616
|
else if (this.platform.config.options?.logging) {
|
|
469
617
|
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
470
|
-
this.debugLog(
|
|
618
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
471
619
|
}
|
|
472
620
|
else {
|
|
473
621
|
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
474
|
-
this.debugLog(
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
FirmwareRevision(accessory, device) {
|
|
478
|
-
let FirmwareRevision;
|
|
479
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} accessory.context.FirmwareRevision: ${accessory.context.FirmwareRevision}`);
|
|
480
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} device.firmware: ${device.firmware}`);
|
|
481
|
-
this.debugLog(`Meter Plus: ${this.accessory.displayName} this.platform.version: ${this.platform.version}`);
|
|
482
|
-
if (accessory.context.FirmwareRevision) {
|
|
483
|
-
FirmwareRevision = accessory.context.FirmwareRevision;
|
|
484
|
-
}
|
|
485
|
-
else if (device.firmware) {
|
|
486
|
-
FirmwareRevision = device.firmware;
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
FirmwareRevision = this.platform.version;
|
|
622
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
490
623
|
}
|
|
491
|
-
return FirmwareRevision;
|
|
492
624
|
}
|
|
493
625
|
/**
|
|
494
626
|
* Logging for Device
|
|
@@ -503,11 +635,25 @@ class MeterPlus {
|
|
|
503
635
|
this.platform.log.warn(String(...log));
|
|
504
636
|
}
|
|
505
637
|
}
|
|
638
|
+
debugWarnLog(...log) {
|
|
639
|
+
if (this.enablingDeviceLogging()) {
|
|
640
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
641
|
+
this.platform.log.warn('[DEBUG]', String(...log));
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
}
|
|
506
645
|
errorLog(...log) {
|
|
507
646
|
if (this.enablingDeviceLogging()) {
|
|
508
647
|
this.platform.log.error(String(...log));
|
|
509
648
|
}
|
|
510
649
|
}
|
|
650
|
+
debugErrorLog(...log) {
|
|
651
|
+
if (this.enablingDeviceLogging()) {
|
|
652
|
+
if (this.deviceLogging?.includes('debug')) {
|
|
653
|
+
this.platform.log.error('[DEBUG]', String(...log));
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
}
|
|
511
657
|
debugLog(...log) {
|
|
512
658
|
if (this.enablingDeviceLogging()) {
|
|
513
659
|
if (this.deviceLogging === 'debug') {
|