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