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