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