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