@switchbot/homebridge-switchbot 3.5.1-beta.2 → 3.5.1-beta.4
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/dist/device/blindtilt.d.ts +15 -6
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +203 -255
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +196 -218
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +9 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +202 -247
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +10 -5
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +329 -378
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +9 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +99 -142
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -7
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +203 -264
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +28 -32
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +186 -225
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +9 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +198 -227
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +9 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +106 -231
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +12 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +192 -232
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +9 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +91 -157
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +10 -5
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +287 -367
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +10 -5
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +171 -216
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +9 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +93 -158
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +9 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +94 -155
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +9 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +84 -142
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +99 -124
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +9 -6
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +170 -253
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +12 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +102 -128
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +2 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +2 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +2 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +2 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +2 -1
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +1 -1
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +2 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +2 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +2 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +2 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +2 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +5 -7
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +51 -34
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +49 -191
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +19 -0
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +279 -0
- package/dist/types/bledevicestatus.d.ts.map +1 -0
- package/dist/types/bledevicestatus.js +2 -0
- package/dist/types/bledevicestatus.js.map +1 -0
- package/dist/types/devicelist.d.ts +89 -0
- package/dist/types/devicelist.d.ts.map +1 -0
- package/dist/types/devicelist.js +6 -0
- package/dist/types/devicelist.js.map +1 -0
- package/dist/types/deviceresponse.d.ts +13 -0
- package/dist/types/deviceresponse.d.ts.map +1 -0
- package/dist/types/deviceresponse.js +2 -0
- package/dist/types/deviceresponse.js.map +1 -0
- package/dist/types/devicestatus.d.ts +149 -0
- package/dist/types/devicestatus.d.ts.map +1 -0
- package/dist/types/devicestatus.js +3 -0
- package/dist/types/devicestatus.js.map +1 -0
- package/dist/types/devicewebhookstatus.d.ts +156 -0
- package/dist/types/devicewebhookstatus.d.ts.map +1 -0
- package/dist/types/devicewebhookstatus.js +2 -0
- package/dist/types/devicewebhookstatus.js.map +1 -0
- package/dist/types/irdevicelist.d.ts +10 -0
- package/dist/types/irdevicelist.d.ts.map +1 -0
- package/dist/types/irdevicelist.js +2 -0
- package/dist/types/irdevicelist.js.map +1 -0
- package/dist/types/pushbody.d.ts +6 -0
- package/dist/types/pushbody.d.ts.map +1 -0
- package/dist/types/pushbody.js +2 -0
- package/dist/types/pushbody.js.map +1 -0
- package/dist/utils.d.ts +25 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +28 -0
- package/dist/utils.js.map +1 -1
- package/package.json +10 -10
- package/src/device/blindtilt.ts +224 -264
- package/src/device/bot.ts +208 -221
- package/src/device/ceilinglight.ts +210 -257
- package/src/device/colorbulb.ts +334 -397
- package/src/device/contact.ts +111 -146
- package/src/device/curtain.ts +220 -283
- package/src/device/device.ts +194 -245
- package/src/device/fan.ts +214 -230
- package/src/device/hub.ts +126 -246
- package/src/device/humidifier.ts +216 -243
- package/src/device/iosensor.ts +114 -166
- package/src/device/lightstrip.ts +302 -377
- package/src/device/lock.ts +187 -221
- package/src/device/meter.ts +116 -177
- package/src/device/meterplus.ts +117 -174
- package/src/device/motion.ts +99 -144
- package/src/device/plug.ts +110 -128
- package/src/device/robotvacuumcleaner.ts +189 -252
- package/src/device/waterdetector.ts +120 -138
- package/src/irdevice/airconditioner.ts +2 -1
- package/src/irdevice/airpurifier.ts +2 -1
- package/src/irdevice/camera.ts +2 -1
- package/src/irdevice/fan.ts +2 -1
- package/src/irdevice/irdevice.ts +3 -2
- package/src/irdevice/light.ts +2 -1
- package/src/irdevice/other.ts +2 -1
- package/src/irdevice/tv.ts +2 -1
- package/src/irdevice/vacuumcleaner.ts +2 -1
- package/src/irdevice/waterheater.ts +2 -1
- package/src/platform.ts +52 -34
- package/src/settings.ts +30 -239
- package/src/types/bledevicestatus.ts +305 -0
- package/src/types/devicelist.ts +124 -0
- package/src/types/deviceresponse.ts +15 -0
- package/src/types/devicestatus.ts +178 -0
- package/src/types/devicewebhookstatus.ts +196 -0
- package/src/types/irdevicelist.ts +15 -0
- package/src/types/pushbody.ts +9 -0
- package/src/utils.ts +33 -0
package/src/device/meter.ts
CHANGED
|
@@ -6,10 +6,15 @@ import { Units } from 'homebridge';
|
|
|
6
6
|
import { deviceBase } from './device.js';
|
|
7
7
|
import { convertUnits } from '../utils.js';
|
|
8
8
|
import { Subject, interval, skipWhile } from 'rxjs';
|
|
9
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
9
10
|
|
|
11
|
+
import type { devicesConfig } from '../settings.js';
|
|
12
|
+
import type { device } from '../types/devicelist.js';
|
|
10
13
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
14
|
+
import type { meterServiceData } from '../types/bledevicestatus.js';
|
|
15
|
+
import type { meterStatus } from '../types/devicestatus.js';
|
|
16
|
+
import type { meterWebhookContext } from '../types/devicewebhookstatus.js';
|
|
11
17
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
12
|
-
import type { device, devicesConfig, serviceData, deviceStatus } from '../settings.js';
|
|
13
18
|
|
|
14
19
|
export class Meter extends deviceBase {
|
|
15
20
|
// Services
|
|
@@ -136,76 +141,63 @@ export class Meter extends deviceBase {
|
|
|
136
141
|
// Retrieve initial values and update Homekit
|
|
137
142
|
this.updateHomeKitCharacteristics();
|
|
138
143
|
|
|
144
|
+
//regisiter webhook event handler
|
|
145
|
+
this.registerWebhook();
|
|
146
|
+
|
|
139
147
|
// Start an update interval
|
|
140
148
|
interval(this.deviceRefreshRate * 1000)
|
|
141
149
|
.pipe(skipWhile(() => this.meterUpdateInProgress))
|
|
142
150
|
.subscribe(async () => {
|
|
143
151
|
await this.refreshStatus();
|
|
144
152
|
});
|
|
145
|
-
|
|
146
|
-
//regisiter webhook event handler
|
|
147
|
-
this.registerWebhook(accessory, device);
|
|
148
153
|
}
|
|
149
154
|
|
|
150
|
-
async BLEparseStatus(serviceData:
|
|
151
|
-
this.debugLog(
|
|
152
|
-
|
|
153
|
-
// BatteryLevel
|
|
154
|
-
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
155
|
-
if (this.Battery.BatteryLevel < 15) {
|
|
156
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
157
|
-
} else {
|
|
158
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
159
|
-
}
|
|
160
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
161
|
-
|
|
155
|
+
async BLEparseStatus(serviceData: meterServiceData): Promise<void> {
|
|
156
|
+
await this.debugLog('BLEparseStatus');
|
|
162
157
|
// CurrentRelativeHumidity
|
|
163
|
-
if (!this.device.
|
|
164
|
-
this.HumiditySensor
|
|
165
|
-
this.debugLog(
|
|
158
|
+
if (!this.device.iosensor?.hide_humidity && this.HumiditySensor?.Service) {
|
|
159
|
+
this.HumiditySensor.CurrentRelativeHumidity = serviceData.humidity;
|
|
160
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
166
161
|
}
|
|
167
|
-
|
|
168
162
|
// Current Temperature
|
|
169
|
-
if (!this.device.meter?.hide_temperature) {
|
|
170
|
-
const
|
|
171
|
-
this.TemperatureSensor
|
|
172
|
-
this.debugLog(
|
|
163
|
+
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
164
|
+
const CELSIUS = serviceData.temperature.c < 0 ? 0 : serviceData.temperature.c > 100 ? 100 : serviceData.temperature.c;
|
|
165
|
+
this.TemperatureSensor.CurrentTemperature = CELSIUS;
|
|
166
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
173
167
|
}
|
|
168
|
+
// BatteryLevel
|
|
169
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
170
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
171
|
+
// StatusLowBattery
|
|
172
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
173
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
174
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
async openAPIparseStatus(deviceStatus:
|
|
177
|
-
this.debugLog(
|
|
178
|
-
|
|
179
|
-
// Battery
|
|
180
|
-
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
181
|
-
if (this.Battery.BatteryLevel < 10) {
|
|
182
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
183
|
-
} else {
|
|
184
|
-
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
185
|
-
}
|
|
186
|
-
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
187
|
-
this.Battery.BatteryLevel = 100;
|
|
188
|
-
}
|
|
189
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel},`
|
|
190
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
191
|
-
|
|
177
|
+
async openAPIparseStatus(deviceStatus: meterStatus): Promise<void> {
|
|
178
|
+
await this.debugLog('openAPIparseStatus');
|
|
192
179
|
// CurrentRelativeHumidity
|
|
193
|
-
if (!this.device.meter?.hide_humidity) {
|
|
194
|
-
this.HumiditySensor
|
|
195
|
-
this.debugLog(
|
|
180
|
+
if (!this.device.meter?.hide_humidity && this.HumiditySensor?.Service) {
|
|
181
|
+
this.HumiditySensor.CurrentRelativeHumidity = deviceStatus.humidity;
|
|
182
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}%`);
|
|
196
183
|
}
|
|
197
|
-
|
|
198
184
|
// CurrentTemperature
|
|
199
|
-
if (!this.device.meter?.hide_temperature) {
|
|
200
|
-
this.TemperatureSensor
|
|
201
|
-
this.debugLog(
|
|
185
|
+
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
186
|
+
this.TemperatureSensor.CurrentTemperature = deviceStatus.temperature;
|
|
187
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}°c`);
|
|
202
188
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
189
|
+
// BatteryLevel
|
|
190
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
191
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
192
|
+
// StatusLowBattery
|
|
193
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
194
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
195
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
196
|
+
// FirmwareVersion
|
|
197
|
+
const version = deviceStatus.version.toString();
|
|
198
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
199
|
+
if (deviceStatus.version) {
|
|
200
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
209
201
|
this.accessory
|
|
210
202
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
211
203
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -213,7 +205,29 @@ export class Meter extends deviceBase {
|
|
|
213
205
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
214
206
|
.updateValue(deviceVersion);
|
|
215
207
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
216
|
-
this.debugSuccessLog(
|
|
208
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async parseStatusWebhook(context: meterWebhookContext): Promise<void> {
|
|
213
|
+
await this.debugLog('parseStatusWebhook');
|
|
214
|
+
await this.debugLog(`(scale, temperature, humidity) = Webhook:(${context.scale}, ${convertUnits(context.temperature, context.scale,
|
|
215
|
+
this.device.meter?.convertUnitTo)}, ${context.humidity}), current:(${this.TemperatureSensor?.CurrentTemperature},`
|
|
216
|
+
+ ` ${this.HumiditySensor?.CurrentRelativeHumidity})`);
|
|
217
|
+
// Check if the scale is not CELSIUS
|
|
218
|
+
if (context.scale !== 'CELSIUS' && this.device.hub?.convertUnitTo === undefined) {
|
|
219
|
+
await this.warnLog(`received a non-CELSIUS Webhook scale: ${context.scale}, Use the *convertUnitsTo* config under Hub settings,`
|
|
220
|
+
+ ' if displaying incorrectly in HomeKit.');
|
|
221
|
+
}
|
|
222
|
+
// CurrentRelativeHumidity
|
|
223
|
+
if (!this.device.meter?.hide_humidity && this.HumiditySensor?.Service) {
|
|
224
|
+
this.HumiditySensor.CurrentRelativeHumidity = context.humidity;
|
|
225
|
+
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor.CurrentRelativeHumidity}`);
|
|
226
|
+
}
|
|
227
|
+
// CurrentTemperature
|
|
228
|
+
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
229
|
+
this.TemperatureSensor.CurrentTemperature = convertUnits(context.temperature, context.scale, this.device.hub?.convertUnitTo);
|
|
230
|
+
await this.debugLog(`CurrentTemperature: ${this.TemperatureSensor.CurrentTemperature}`);
|
|
217
231
|
}
|
|
218
232
|
}
|
|
219
233
|
|
|
@@ -222,20 +236,19 @@ export class Meter extends deviceBase {
|
|
|
222
236
|
*/
|
|
223
237
|
async refreshStatus(): Promise<void> {
|
|
224
238
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
225
|
-
this.errorLog(
|
|
239
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
226
240
|
} else if (this.BLE) {
|
|
227
241
|
await this.BLERefreshStatus();
|
|
228
242
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
229
243
|
await this.openAPIRefreshStatus();
|
|
230
244
|
} else {
|
|
231
245
|
await this.offlineOff();
|
|
232
|
-
this.debugWarnLog(
|
|
233
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
246
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
234
247
|
}
|
|
235
248
|
}
|
|
236
249
|
|
|
237
250
|
async BLERefreshStatus(): Promise<void> {
|
|
238
|
-
this.debugLog(
|
|
251
|
+
await this.debugLog('BLERefreshStatus');
|
|
239
252
|
const switchbot = await this.switchbotBLE();
|
|
240
253
|
|
|
241
254
|
if (switchbot === undefined) {
|
|
@@ -244,13 +257,13 @@ export class Meter extends deviceBase {
|
|
|
244
257
|
// Start to monitor advertisement packets
|
|
245
258
|
(async () => {
|
|
246
259
|
// Start to monitor advertisement packets
|
|
247
|
-
const serviceData
|
|
260
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as meterServiceData;
|
|
248
261
|
// Update HomeKit
|
|
249
|
-
if (serviceData.model
|
|
262
|
+
if (serviceData.model === SwitchBotBLEModel.Meter && serviceData.modelName === SwitchBotBLEModelName.Meter) {
|
|
250
263
|
await this.BLEparseStatus(serviceData);
|
|
251
264
|
await this.updateHomeKitCharacteristics();
|
|
252
265
|
} else {
|
|
253
|
-
this.errorLog(
|
|
266
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
254
267
|
await this.BLERefreshConnection(switchbot);
|
|
255
268
|
}
|
|
256
269
|
})();
|
|
@@ -258,54 +271,39 @@ export class Meter extends deviceBase {
|
|
|
258
271
|
}
|
|
259
272
|
|
|
260
273
|
async openAPIRefreshStatus(): Promise<void> {
|
|
261
|
-
this.debugLog(
|
|
274
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
262
275
|
try {
|
|
263
276
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
264
277
|
const deviceStatus: any = await body.json();
|
|
265
|
-
await this.
|
|
266
|
-
if (
|
|
267
|
-
await this.
|
|
268
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
278
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
279
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
280
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
281
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
269
282
|
await this.updateHomeKitCharacteristics();
|
|
270
283
|
} else {
|
|
271
|
-
await this.
|
|
284
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
285
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
272
286
|
}
|
|
273
287
|
} catch (e: any) {
|
|
274
288
|
await this.apiError(e);
|
|
275
|
-
await this.
|
|
289
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
276
290
|
}
|
|
277
291
|
}
|
|
278
292
|
|
|
279
|
-
async registerWebhook(
|
|
280
|
-
if (device.webhook) {
|
|
281
|
-
this.debugLog(
|
|
282
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
293
|
+
async registerWebhook() {
|
|
294
|
+
if (this.device.webhook) {
|
|
295
|
+
await this.debugLog('is listening webhook.');
|
|
296
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: meterWebhookContext) => {
|
|
283
297
|
try {
|
|
284
|
-
this.debugLog(
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
const { CurrentRelativeHumidity } = this.HumiditySensor ?? { CurrentRelativeHumidity: undefined };
|
|
288
|
-
if (context.scale !== 'CELCIUS' && device.meter?.convertUnitTo === undefined) {
|
|
289
|
-
this.warnLog(`${device.deviceType}: ${accessory.displayName} received Webhook scale: `
|
|
290
|
-
+ `${context.scale}, instead of CELCIUS. Use the *convertUnitsTo* config under Meter settings, if displaying incorrectly in HomeKit.`);
|
|
291
|
-
}
|
|
292
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} ` +
|
|
293
|
-
'(scale, temperature, humidity) = '
|
|
294
|
-
+ `Webhook:(${context.scale}, ${convertUnits(temperature, context.scale, device.meter?.convertUnitTo)}, ${humidity}), `
|
|
295
|
-
+ `current:(${CurrentTemperature}, ${CurrentRelativeHumidity})`);
|
|
296
|
-
if (!device.meter?.hide_humidity) {
|
|
297
|
-
this.HumiditySensor!.CurrentRelativeHumidity = humidity;
|
|
298
|
-
}
|
|
299
|
-
if (!device.meter?.hide_temperature) {
|
|
300
|
-
this.TemperatureSensor!.CurrentTemperature = convertUnits(temperature, context.scale, device.meter?.convertUnitTo);
|
|
301
|
-
}
|
|
302
|
-
this.updateHomeKitCharacteristics();
|
|
298
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
299
|
+
await this.parseStatusWebhook(context);
|
|
300
|
+
await this.updateHomeKitCharacteristics();
|
|
303
301
|
} catch (e: any) {
|
|
304
|
-
this.errorLog(
|
|
302
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
305
303
|
}
|
|
306
304
|
};
|
|
307
305
|
} else {
|
|
308
|
-
this.debugLog(
|
|
306
|
+
await this.debugLog('is not listening webhook.');
|
|
309
307
|
}
|
|
310
308
|
}
|
|
311
309
|
|
|
@@ -313,113 +311,54 @@ export class Meter extends deviceBase {
|
|
|
313
311
|
* Updates the status for each of the HomeKit Characteristics
|
|
314
312
|
*/
|
|
315
313
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
316
|
-
const mqttmessage: string[] = [];
|
|
317
|
-
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
318
|
-
|
|
319
314
|
// CurrentRelativeHumidity
|
|
320
|
-
if (!this.device.meter?.hide_humidity) {
|
|
321
|
-
|
|
322
|
-
this.
|
|
323
|
-
+ ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
324
|
-
} else {
|
|
325
|
-
this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity;
|
|
326
|
-
this.HumiditySensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
|
|
327
|
-
this.HumiditySensor!.CurrentRelativeHumidity);
|
|
328
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName}`
|
|
329
|
-
+ ` updateCharacteristic CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
330
|
-
if (this.device.mqttURL) {
|
|
331
|
-
mqttmessage.push(`"humidity": ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
332
|
-
}
|
|
333
|
-
if (this.device.history) {
|
|
334
|
-
entry['humidity'] = this.HumiditySensor!.CurrentRelativeHumidity;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
315
|
+
if (!this.device.meter?.hide_humidity && this.HumiditySensor?.Service) {
|
|
316
|
+
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
|
|
317
|
+
this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
|
|
337
318
|
}
|
|
338
|
-
|
|
339
319
|
// CurrentTemperature
|
|
340
|
-
if (!this.device.meter?.hide_temperature) {
|
|
341
|
-
|
|
342
|
-
this.
|
|
343
|
-
} else {
|
|
344
|
-
this.accessory.context.CurrentTemperature = this.TemperatureSensor!.CurrentTemperature;
|
|
345
|
-
this.TemperatureSensor!.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.TemperatureSensor!.CurrentTemperature);
|
|
346
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
347
|
-
+ ` CurrentTemperature: ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
348
|
-
if (this.device.mqttURL) {
|
|
349
|
-
mqttmessage.push(`"temperature": ${this.TemperatureSensor!.CurrentTemperature}`);
|
|
350
|
-
}
|
|
351
|
-
if (this.device.history) {
|
|
352
|
-
entry['temp'] = this.TemperatureSensor!.CurrentTemperature;
|
|
353
|
-
}
|
|
354
|
-
}
|
|
320
|
+
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
321
|
+
await this.updateCharacteristic(this.TemperatureSensor.Service, this.hap.Characteristic.CurrentTemperature,
|
|
322
|
+
this.TemperatureSensor.CurrentTemperature, 'CurrentTemperature');
|
|
355
323
|
}
|
|
356
|
-
|
|
357
324
|
// BatteryLevel
|
|
358
|
-
|
|
359
|
-
this.
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
this.Battery
|
|
363
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
364
|
-
if (this.device.mqttURL) {
|
|
365
|
-
mqttmessage.push(`"battery": ${this.Battery.BatteryLevel}`);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
369
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
370
|
-
} else {
|
|
371
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
372
|
-
this.Battery!.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
373
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
374
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
375
|
-
if (this.device.mqttURL) {
|
|
376
|
-
mqttmessage.push(`"lowBattery": ${this.Battery.StatusLowBattery}`);
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// MQTT Publish
|
|
381
|
-
if (this.device.mqttURL) {
|
|
382
|
-
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// History Service
|
|
386
|
-
if (!this.device.meter?.hide_humidity && (Number(this.HumiditySensor!.CurrentRelativeHumidity) > 0)) {
|
|
387
|
-
// reject unreliable data
|
|
388
|
-
if (this.device.history) {
|
|
389
|
-
this.historyService?.addEntry(entry);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
325
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
326
|
+
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
327
|
+
// StatusLowBattery
|
|
328
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
329
|
+
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
392
330
|
}
|
|
393
331
|
|
|
394
332
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
395
|
-
this.errorLog(
|
|
396
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
333
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
397
334
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
398
|
-
this.warnLog(
|
|
335
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
399
336
|
await this.openAPIRefreshStatus();
|
|
400
337
|
}
|
|
401
338
|
}
|
|
402
339
|
|
|
403
340
|
async offlineOff(): Promise<void> {
|
|
404
341
|
if (this.device.offline) {
|
|
405
|
-
if (!this.device.meter?.hide_humidity) {
|
|
406
|
-
this.HumiditySensor
|
|
342
|
+
if (!this.device.meter?.hide_humidity && this.HumiditySensor?.Service) {
|
|
343
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, 50);
|
|
407
344
|
}
|
|
408
|
-
if (!this.device.meter?.hide_temperature) {
|
|
409
|
-
this.TemperatureSensor
|
|
345
|
+
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
346
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, 30);
|
|
410
347
|
}
|
|
411
348
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, 100);
|
|
349
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery,
|
|
350
|
+
this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL);
|
|
412
351
|
}
|
|
413
352
|
}
|
|
414
353
|
|
|
415
354
|
async apiError(e: any): Promise<void> {
|
|
416
|
-
if (!this.device.meter?.hide_humidity) {
|
|
417
|
-
this.HumiditySensor
|
|
355
|
+
if (!this.device.meter?.hide_humidity && this.HumiditySensor?.Service) {
|
|
356
|
+
this.HumiditySensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity, e);
|
|
418
357
|
}
|
|
419
|
-
if (!this.device.meter?.hide_temperature) {
|
|
420
|
-
this.TemperatureSensor
|
|
358
|
+
if (!this.device.meter?.hide_temperature && this.TemperatureSensor?.Service) {
|
|
359
|
+
this.TemperatureSensor.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
421
360
|
}
|
|
422
|
-
this.Battery
|
|
423
|
-
this.Battery
|
|
361
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
362
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
424
363
|
}
|
|
425
364
|
}
|