@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
|
@@ -3,12 +3,16 @@
|
|
|
3
3
|
* waterdetector.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import { deviceBase } from './device.js';
|
|
6
|
-
import { interval,
|
|
7
|
-
import {
|
|
6
|
+
import { Subject, interval, skipWhile } from 'rxjs';
|
|
7
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot';
|
|
8
8
|
|
|
9
|
+
import type { devicesConfig } from '../settings.js';
|
|
10
|
+
import type { device } from '../types/devicelist.js';
|
|
9
11
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
12
|
+
import type { waterLeakDetectorServiceData } from '../types/bledevicestatus.js';
|
|
10
13
|
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
11
|
-
import type {
|
|
14
|
+
import type { waterLeakDetectorStatus } from '../types/devicestatus.js';
|
|
15
|
+
import type { waterLeakDetectorWebhookContext } from '../types/devicewebhookstatus.js';
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* Platform Accessory
|
|
@@ -42,7 +46,6 @@ export class WaterDetector extends deviceBase {
|
|
|
42
46
|
device: device & devicesConfig,
|
|
43
47
|
) {
|
|
44
48
|
super(platform, accessory, device);
|
|
45
|
-
|
|
46
49
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
47
50
|
this.doWaterDetectorUpdate = new Subject();
|
|
48
51
|
this.WaterDetectorUpdateInProgress = false;
|
|
@@ -108,63 +111,58 @@ export class WaterDetector extends deviceBase {
|
|
|
108
111
|
// Retrieve initial values and updateHomekit
|
|
109
112
|
this.updateHomeKitCharacteristics();
|
|
110
113
|
|
|
114
|
+
//regisiter webhook event handler
|
|
115
|
+
this.registerWebhook();
|
|
116
|
+
|
|
111
117
|
// Start an update interval
|
|
112
118
|
interval(this.deviceRefreshRate * 1000)
|
|
113
119
|
.pipe(skipWhile(() => this.WaterDetectorUpdateInProgress))
|
|
114
120
|
.subscribe(async () => {
|
|
115
121
|
await this.refreshStatus();
|
|
116
122
|
});
|
|
117
|
-
|
|
118
|
-
//regisiter webhook event handler
|
|
119
|
-
this.registerWebhook(accessory, device);
|
|
120
123
|
}
|
|
121
124
|
|
|
122
|
-
async BLEparseStatus(serviceData:
|
|
123
|
-
this.debugLog(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
this.
|
|
128
|
-
|
|
129
|
-
this.
|
|
130
|
-
|
|
131
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
132
|
-
|
|
133
|
-
// LeakDetected
|
|
134
|
-
if (this.device.waterdetector?.hide_leak) {
|
|
135
|
-
this.LeakSensor!.LeakDetected = serviceData.status!;
|
|
136
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor!.LeakDetected}`);
|
|
125
|
+
async BLEparseStatus(serviceData: waterLeakDetectorServiceData): Promise<void> {
|
|
126
|
+
await this.debugLog('BLEparseStatus');
|
|
127
|
+
if (this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
128
|
+
// StatusActive
|
|
129
|
+
this.LeakSensor.StatusActive = serviceData.state;
|
|
130
|
+
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
131
|
+
// LeakDetected
|
|
132
|
+
this.LeakSensor.LeakDetected = serviceData.status;
|
|
133
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
137
134
|
}
|
|
135
|
+
// BatteryLevel
|
|
136
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
137
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
138
|
+
// StatusLowBattery
|
|
139
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
140
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
141
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
138
142
|
}
|
|
139
143
|
|
|
140
|
-
async openAPIparseStatus(deviceStatus:
|
|
141
|
-
this.debugLog(
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
this.
|
|
146
|
-
|
|
147
|
-
this.
|
|
144
|
+
async openAPIparseStatus(deviceStatus: waterLeakDetectorStatus): Promise<void> {
|
|
145
|
+
await this.debugLog('openAPIparseStatus');
|
|
146
|
+
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
147
|
+
// StatusActive
|
|
148
|
+
this.LeakSensor.StatusActive = deviceStatus.status ? true : false;
|
|
149
|
+
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
150
|
+
// LeakDetected
|
|
151
|
+
this.LeakSensor.LeakDetected = deviceStatus.status;
|
|
152
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
148
153
|
}
|
|
149
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
150
|
-
|
|
151
154
|
// BatteryLevel
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
// Firmware Version
|
|
164
|
-
const version = deviceStatus.body.version?.toString();
|
|
165
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
166
|
-
if (deviceStatus.body.version) {
|
|
167
|
-
const deviceVersion = version?.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
155
|
+
this.Battery.BatteryLevel = Number(deviceStatus.battery);
|
|
156
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
157
|
+
// StatusLowBattery
|
|
158
|
+
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
159
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
160
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
161
|
+
// FirmwareVersion
|
|
162
|
+
const version = deviceStatus.version.toString();
|
|
163
|
+
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
164
|
+
if (deviceStatus.version) {
|
|
165
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
168
166
|
this.accessory
|
|
169
167
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
170
168
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
@@ -172,41 +170,64 @@ export class WaterDetector extends deviceBase {
|
|
|
172
170
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
173
171
|
.updateValue(deviceVersion);
|
|
174
172
|
this.accessory.context.deviceVersion = deviceVersion;
|
|
175
|
-
this.debugSuccessLog(
|
|
173
|
+
await this.debugSuccessLog(`deviceVersion: ${this.accessory.context.deviceVersion}`);
|
|
176
174
|
}
|
|
177
175
|
}
|
|
178
176
|
|
|
177
|
+
async parseStatusWebhook(context: waterLeakDetectorWebhookContext): Promise<void> {
|
|
178
|
+
await this.debugLog('parseStatusWebhook');
|
|
179
|
+
await this.debugLog(`(detectionState, battery) = Webhook: (${context.detectionState}, ${context.battery}),`
|
|
180
|
+
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
181
|
+
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
182
|
+
// StatusActive
|
|
183
|
+
this.LeakSensor.StatusActive = context.detectionState ? true : false;
|
|
184
|
+
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
185
|
+
// LeakDetected
|
|
186
|
+
this.LeakSensor.LeakDetected = context.detectionState;
|
|
187
|
+
await this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
188
|
+
}
|
|
189
|
+
// BatteryLevel
|
|
190
|
+
this.Battery.BatteryLevel = Number(context.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
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Asks the SwitchBot API for the latest device information
|
|
200
|
+
*/
|
|
179
201
|
async refreshStatus(): Promise<void> {
|
|
180
202
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
181
|
-
this.errorLog(
|
|
203
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
182
204
|
} else if (this.BLE) {
|
|
183
205
|
await this.BLERefreshStatus();
|
|
184
206
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
185
207
|
await this.openAPIRefreshStatus();
|
|
186
208
|
} else {
|
|
187
209
|
await this.offlineOff();
|
|
188
|
-
this.debugWarnLog(
|
|
189
|
-
+ ` ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
210
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`);
|
|
190
211
|
}
|
|
191
212
|
}
|
|
192
213
|
|
|
193
214
|
async BLERefreshStatus(): Promise<void> {
|
|
194
|
-
this.debugLog(
|
|
215
|
+
await this.debugLog('BLERefreshStatus');
|
|
195
216
|
const switchbot = await this.switchbotBLE();
|
|
196
217
|
|
|
197
218
|
if (switchbot === undefined) {
|
|
198
219
|
await this.BLERefreshConnection(switchbot);
|
|
199
220
|
} else {
|
|
200
|
-
// Start to monitor advertisement packets
|
|
201
|
-
(async () => {
|
|
202
221
|
// Start to monitor advertisement packets
|
|
203
|
-
|
|
222
|
+
(async () => {
|
|
223
|
+
// Start to monitor advertisement packets
|
|
224
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as waterLeakDetectorServiceData;
|
|
204
225
|
// Update HomeKit
|
|
205
|
-
if (serviceData.model
|
|
226
|
+
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
206
227
|
await this.BLEparseStatus(serviceData);
|
|
207
228
|
await this.updateHomeKitCharacteristics();
|
|
208
229
|
} else {
|
|
209
|
-
this.errorLog(
|
|
230
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
210
231
|
await this.BLERefreshConnection(switchbot);
|
|
211
232
|
}
|
|
212
233
|
})();
|
|
@@ -214,46 +235,39 @@ export class WaterDetector extends deviceBase {
|
|
|
214
235
|
}
|
|
215
236
|
|
|
216
237
|
async openAPIRefreshStatus(): Promise<void> {
|
|
217
|
-
this.debugLog(
|
|
238
|
+
await this.debugLog('openAPIRefreshStatus');
|
|
218
239
|
try {
|
|
219
240
|
const { body, statusCode } = await this.deviceRefreshStatus();
|
|
220
241
|
const deviceStatus: any = await body.json();
|
|
221
|
-
await this.
|
|
222
|
-
if (
|
|
223
|
-
await this.
|
|
224
|
-
await this.openAPIparseStatus(deviceStatus);
|
|
242
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
243
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
244
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
245
|
+
await this.openAPIparseStatus(deviceStatus.body);
|
|
225
246
|
await this.updateHomeKitCharacteristics();
|
|
226
247
|
} else {
|
|
227
|
-
await this.
|
|
248
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
249
|
+
await this.debugWarnLog(statusCode, deviceStatus);
|
|
228
250
|
}
|
|
229
251
|
} catch (e: any) {
|
|
230
252
|
await this.apiError(e);
|
|
231
|
-
await this.
|
|
253
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`);
|
|
232
254
|
}
|
|
233
255
|
}
|
|
234
256
|
|
|
235
|
-
async registerWebhook(
|
|
236
|
-
if (device.webhook) {
|
|
237
|
-
this.debugLog(
|
|
238
|
-
this.platform.webhookEventHandler[device.deviceId] = async (context) => {
|
|
257
|
+
async registerWebhook() {
|
|
258
|
+
if (this.device.webhook) {
|
|
259
|
+
await this.debugLog('is listening webhook.');
|
|
260
|
+
this.platform.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
|
|
239
261
|
try {
|
|
240
|
-
this.debugLog(
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const { BatteryLevel } = this.Battery ? this.Battery : { BatteryLevel: undefined };
|
|
244
|
-
this.debugLog(`${device.deviceType}: ${accessory.displayName} (detectionState, battery) = Webhook: (${detectionState}, ${battery}), `
|
|
245
|
-
+ `current: (${LeakDetected}, ${BatteryLevel})`);
|
|
246
|
-
if (!device.waterdetector?.hide_leak) {
|
|
247
|
-
this.LeakSensor!.LeakDetected = detectionState;
|
|
248
|
-
}
|
|
249
|
-
this.Battery.BatteryLevel = battery;
|
|
250
|
-
this.updateHomeKitCharacteristics();
|
|
262
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
263
|
+
await this.parseStatusWebhook(context);
|
|
264
|
+
await this.updateHomeKitCharacteristics();
|
|
251
265
|
} catch (e: any) {
|
|
252
|
-
this.errorLog(
|
|
266
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
253
267
|
}
|
|
254
268
|
};
|
|
255
269
|
} else {
|
|
256
|
-
this.debugLog(
|
|
270
|
+
await this.debugLog('is not listening webhook.');
|
|
257
271
|
}
|
|
258
272
|
}
|
|
259
273
|
|
|
@@ -261,75 +275,43 @@ export class WaterDetector extends deviceBase {
|
|
|
261
275
|
* Updates the status for each of the HomeKit Characteristics
|
|
262
276
|
*/
|
|
263
277
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
mqttmessage.push(`"LeakDetected": ${this.LeakSensor!.LeakDetected}`);
|
|
272
|
-
}
|
|
273
|
-
if (this.device.history) {
|
|
274
|
-
entry['leak'] = this.LeakSensor!.LeakDetected;
|
|
275
|
-
}
|
|
276
|
-
this.accessory.context.LeakDetected = this.LeakSensor!.LeakDetected;
|
|
277
|
-
this.LeakSensor!.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.LeakSensor!.LeakDetected);
|
|
278
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LeakDetected: ${this.LeakSensor!.LeakDetected}`);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
if (this.Battery.BatteryLevel === undefined) {
|
|
282
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
283
|
-
} else {
|
|
284
|
-
if (this.device.mqttURL) {
|
|
285
|
-
mqttmessage.push(`"battery": ${this.Battery.BatteryLevel}`);
|
|
286
|
-
}
|
|
287
|
-
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
288
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
289
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
290
|
-
}
|
|
291
|
-
if (this.Battery.StatusLowBattery === undefined) {
|
|
292
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
293
|
-
} else {
|
|
294
|
-
if (this.device.mqttURL) {
|
|
295
|
-
mqttmessage.push(`"lowBattery": ${this.Battery.StatusLowBattery}`);
|
|
296
|
-
}
|
|
297
|
-
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
298
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
299
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
300
|
-
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
301
|
-
}
|
|
302
|
-
if (this.device.mqttURL) {
|
|
303
|
-
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
304
|
-
}
|
|
305
|
-
if (!this.device.waterdetector?.hide_leak) {
|
|
306
|
-
if (Number(this.LeakSensor!.LeakDetected) > 0) {
|
|
307
|
-
// reject unreliable data
|
|
308
|
-
if (this.device.history) {
|
|
309
|
-
this.historyService?.addEntry(entry);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
278
|
+
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
279
|
+
// StatusActive
|
|
280
|
+
await this.updateCharacteristic(this.LeakSensor.Service, this.hap.Characteristic.StatusActive,
|
|
281
|
+
this.LeakSensor.StatusActive, 'StatusActive');
|
|
282
|
+
// LeakDetected
|
|
283
|
+
await this.updateCharacteristic(this.LeakSensor.Service, this.hap.Characteristic.LeakDetected,
|
|
284
|
+
this.LeakSensor.LeakDetected, 'LeakDetected');
|
|
312
285
|
}
|
|
286
|
+
// BatteryLevel
|
|
287
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
288
|
+
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
289
|
+
// StatusLowBattery
|
|
290
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
291
|
+
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
313
292
|
}
|
|
314
293
|
|
|
315
294
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
316
|
-
this.errorLog(
|
|
317
|
-
+ ` ${JSON.stringify(switchbot)}`);
|
|
295
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchbot)}`);
|
|
318
296
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
319
|
-
this.warnLog(
|
|
297
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
320
298
|
await this.openAPIRefreshStatus();
|
|
321
299
|
}
|
|
322
300
|
}
|
|
323
301
|
|
|
324
302
|
async offlineOff(): Promise<void> {
|
|
325
|
-
if (this.device.offline
|
|
326
|
-
|
|
303
|
+
if (this.device.offline) {
|
|
304
|
+
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
305
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, false);
|
|
306
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED);
|
|
307
|
+
}
|
|
327
308
|
}
|
|
328
309
|
}
|
|
329
310
|
|
|
330
|
-
async apiError(e: any): Promise<void> {
|
|
331
|
-
if
|
|
332
|
-
this.LeakSensor
|
|
311
|
+
async apiError(e: any): Promise < void> {
|
|
312
|
+
if(!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
313
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e);
|
|
314
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, e);
|
|
333
315
|
}
|
|
334
316
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
335
317
|
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
package/src/irdevice/camera.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
package/src/irdevice/fan.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
package/src/irdevice/irdevice.ts
CHANGED
|
@@ -7,7 +7,8 @@ import { Devices } from '../settings.js';
|
|
|
7
7
|
|
|
8
8
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
9
9
|
import type { API, HAP, Logging, PlatformAccessory } from 'homebridge';
|
|
10
|
-
import type { SwitchBotPlatformConfig, irDevicesConfig
|
|
10
|
+
import type { SwitchBotPlatformConfig, irDevicesConfig } from '../settings.js';
|
|
11
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
11
12
|
|
|
12
13
|
export abstract class irdeviceBase {
|
|
13
14
|
public readonly api: API;
|
|
@@ -179,7 +180,7 @@ export abstract class irdeviceBase {
|
|
|
179
180
|
const validVersion = match?.join('.');
|
|
180
181
|
deviceVersion = validVersion ?? '0.0.0';
|
|
181
182
|
} else {
|
|
182
|
-
deviceVersion = version
|
|
183
|
+
deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
183
184
|
}
|
|
184
185
|
accessory
|
|
185
186
|
.getService(this.hap.Service.AccessoryInformation)!
|
package/src/irdevice/light.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
package/src/irdevice/other.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
package/src/irdevice/tv.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { irdeviceBase } from './irdevice.js';
|
|
6
6
|
|
|
7
7
|
import type { SwitchBotPlatform } from '../platform.js';
|
|
8
|
-
import type { irDevicesConfig
|
|
8
|
+
import type { irDevicesConfig } from '../settings.js';
|
|
9
|
+
import type { irdevice } from '../types/irdevicelist.js';
|
|
9
10
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge';
|
|
10
11
|
|
|
11
12
|
/**
|