@switchbot/homebridge-switchbot 3.7.1-beta.8 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -2
- package/README.md +14 -0
- package/assets/security-privacy-bluetooth.png +0 -0
- package/config.schema.json +78 -3
- package/dist/device/blindtilt.d.ts +18 -8
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +108 -70
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +9 -9
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +143 -170
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +13 -13
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +38 -73
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +12 -12
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +41 -79
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +5 -5
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +20 -42
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +15 -5
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +127 -81
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +18 -18
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -36
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +8 -8
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +43 -75
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +5 -5
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -39
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +5 -5
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +38 -78
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +5 -5
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +21 -40
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -6
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +34 -73
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +9 -9
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +37 -52
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +5 -5
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +21 -39
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +5 -5
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +21 -38
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +5 -5
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +14 -32
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +12 -12
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +16 -25
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +11 -11
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +42 -56
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +5 -5
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +47 -44
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/server.js +2 -2
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +8 -8
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +61 -105
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +10 -10
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +22 -42
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +9 -9
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +15 -25
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +8 -8
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +21 -40
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +11 -11
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +14 -22
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +9 -9
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +24 -47
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +9 -9
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +40 -83
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +9 -9
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +29 -54
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +5 -5
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -21
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +5 -5
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -22
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +24 -23
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +471 -715
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +6 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +9 -9
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts +6 -6
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/deviceresponse.d.ts +4 -4
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +2 -2
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/devicewebhookstatus.d.ts +5 -5
- package/dist/types/devicewebhookstatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts +4 -4
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +2 -2
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/utils.d.ts +4 -4
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +9 -13
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +48 -93
- package/package.json +62 -55
- package/src/device/blindtilt.ts +509 -460
- package/src/device/bot.ts +696 -718
- package/src/device/ceilinglight.ts +331 -364
- package/src/device/colorbulb.ts +412 -448
- package/src/device/contact.ts +200 -221
- package/src/device/curtain.ts +506 -444
- package/src/device/device.ts +206 -208
- package/src/device/fan.ts +307 -340
- package/src/device/hub.ts +184 -209
- package/src/device/humidifier.ts +297 -342
- package/src/device/iosensor.ts +182 -204
- package/src/device/lightstrip.ts +362 -399
- package/src/device/lock.ts +262 -276
- package/src/device/meter.ts +183 -205
- package/src/device/meterplus.ts +183 -204
- package/src/device/motion.ts +169 -185
- package/src/device/plug.ts +174 -177
- package/src/device/robotvacuumcleaner.ts +256 -269
- package/src/device/waterdetector.ts +185 -185
- package/src/homebridge-ui/server.ts +16 -15
- package/src/index.ts +5 -6
- package/src/irdevice/airconditioner.ts +277 -326
- package/src/irdevice/airpurifier.ts +124 -143
- package/src/irdevice/camera.ts +58 -64
- package/src/irdevice/fan.ts +106 -123
- package/src/irdevice/irdevice.ts +116 -119
- package/src/irdevice/light.ts +119 -143
- package/src/irdevice/other.ts +417 -461
- package/src/irdevice/tv.ts +155 -177
- package/src/irdevice/vacuumcleaner.ts +54 -60
- package/src/irdevice/waterheater.ts +56 -63
- package/src/platform.ts +1467 -1683
- package/src/settings.ts +173 -170
- package/src/types/bledevicestatus.ts +252 -256
- package/src/types/devicelist.ts +79 -79
- package/src/types/deviceresponse.ts +12 -13
- package/src/types/devicestatus.ts +124 -124
- package/src/types/devicewebhookstatus.ts +126 -131
- package/src/types/irdevicelist.ts +10 -10
- package/src/types/pushbody.ts +5 -5
- package/src/utils.ts +64 -65
- package/tsconfig.json +10 -9
- package/.github/npm-version-script.cjs +0 -81
|
@@ -2,21 +2,23 @@
|
|
|
2
2
|
*
|
|
3
3
|
* waterdetector.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
|
|
7
|
+
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
|
+
import type { devicesConfig } from '../settings.js'
|
|
9
|
+
import type { waterLeakDetectorServiceData } from '../types/bledevicestatus.js'
|
|
10
|
+
import type { device } from '../types/devicelist.js'
|
|
11
|
+
import type { waterLeakDetectorStatus } from '../types/devicestatus.js'
|
|
12
|
+
import type { waterLeakDetectorWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
|
+
|
|
7
14
|
/*
|
|
8
15
|
* For Testing Locally:
|
|
9
16
|
* import { SwitchBotBLEModel, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
|
|
10
17
|
*/
|
|
11
|
-
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
18
|
+
import { SwitchBotBLEModel, SwitchBotBLEModelName } from 'node-switchbot'
|
|
19
|
+
import { interval, skipWhile, Subject } from 'rxjs'
|
|
12
20
|
|
|
13
|
-
import
|
|
14
|
-
import type { device } from '../types/devicelist.js';
|
|
15
|
-
import type { SwitchBotPlatform } from '../platform.js';
|
|
16
|
-
import type { waterLeakDetectorServiceData } from '../types/bledevicestatus.js';
|
|
17
|
-
import type { Service, PlatformAccessory, CharacteristicValue } from 'homebridge';
|
|
18
|
-
import type { waterLeakDetectorStatus } from '../types/devicestatus.js';
|
|
19
|
-
import type { waterLeakDetectorWebhookContext } from '../types/devicewebhookstatus.js';
|
|
21
|
+
import { deviceBase } from './device.js'
|
|
20
22
|
|
|
21
23
|
/**
|
|
22
24
|
* Platform Accessory
|
|
@@ -27,225 +29,227 @@ export class WaterDetector extends deviceBase {
|
|
|
27
29
|
// Services
|
|
28
30
|
private Battery: {
|
|
29
31
|
Name: CharacteristicValue
|
|
30
|
-
Service: Service
|
|
31
|
-
BatteryLevel: CharacteristicValue
|
|
32
|
-
StatusLowBattery: CharacteristicValue
|
|
33
|
-
ChargingState: CharacteristicValue
|
|
34
|
-
}
|
|
32
|
+
Service: Service
|
|
33
|
+
BatteryLevel: CharacteristicValue
|
|
34
|
+
StatusLowBattery: CharacteristicValue
|
|
35
|
+
ChargingState: CharacteristicValue
|
|
36
|
+
}
|
|
35
37
|
|
|
36
38
|
private LeakSensor?: {
|
|
37
|
-
Name: CharacteristicValue
|
|
38
|
-
Service: Service
|
|
39
|
-
StatusActive: CharacteristicValue
|
|
40
|
-
LeakDetected: CharacteristicValue
|
|
41
|
-
}
|
|
39
|
+
Name: CharacteristicValue
|
|
40
|
+
Service: Service
|
|
41
|
+
StatusActive: CharacteristicValue
|
|
42
|
+
LeakDetected: CharacteristicValue
|
|
43
|
+
}
|
|
42
44
|
|
|
43
45
|
// OpenAPI
|
|
44
|
-
deviceStatus!: waterLeakDetectorStatus
|
|
46
|
+
deviceStatus!: waterLeakDetectorStatus
|
|
45
47
|
|
|
46
|
-
//Webhook
|
|
47
|
-
webhookContext!: waterLeakDetectorWebhookContext
|
|
48
|
+
// Webhook
|
|
49
|
+
webhookContext!: waterLeakDetectorWebhookContext
|
|
48
50
|
|
|
49
51
|
// BLE
|
|
50
|
-
serviceData!: waterLeakDetectorServiceData
|
|
52
|
+
serviceData!: waterLeakDetectorServiceData
|
|
51
53
|
|
|
52
54
|
// Updates
|
|
53
|
-
WaterDetectorUpdateInProgress!: boolean
|
|
54
|
-
doWaterDetectorUpdate: Subject<void
|
|
55
|
+
WaterDetectorUpdateInProgress!: boolean
|
|
56
|
+
doWaterDetectorUpdate: Subject<void>
|
|
55
57
|
|
|
56
58
|
constructor(
|
|
57
59
|
readonly platform: SwitchBotPlatform,
|
|
58
60
|
accessory: PlatformAccessory,
|
|
59
61
|
device: device & devicesConfig,
|
|
60
62
|
) {
|
|
61
|
-
super(platform, accessory, device)
|
|
63
|
+
super(platform, accessory, device)
|
|
62
64
|
// Set category
|
|
63
|
-
accessory.category = this.hap.Categories.SENSOR
|
|
65
|
+
accessory.category = this.hap.Categories.SENSOR
|
|
64
66
|
|
|
65
67
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
66
|
-
this.doWaterDetectorUpdate = new Subject()
|
|
67
|
-
this.WaterDetectorUpdateInProgress = false
|
|
68
|
+
this.doWaterDetectorUpdate = new Subject()
|
|
69
|
+
this.WaterDetectorUpdateInProgress = false
|
|
68
70
|
|
|
69
71
|
// Initialize Battery Service
|
|
70
|
-
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
72
|
+
accessory.context.Battery = accessory.context.Battery ?? {}
|
|
71
73
|
this.Battery = {
|
|
72
74
|
Name: `${accessory.displayName} Battery`,
|
|
73
75
|
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery) as Service,
|
|
74
76
|
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
75
77
|
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
76
78
|
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGEABLE,
|
|
77
|
-
}
|
|
78
|
-
accessory.context.Battery = this.Battery as object
|
|
79
|
+
}
|
|
80
|
+
accessory.context.Battery = this.Battery as object
|
|
79
81
|
|
|
80
82
|
// Initialize Battery Characteristic
|
|
81
|
-
this.Battery.Service
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
this.Battery.Service
|
|
90
|
-
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
91
|
-
.onGet(() => {
|
|
92
|
-
return this.Battery.StatusLowBattery;
|
|
93
|
-
});
|
|
83
|
+
this.Battery.Service.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name).setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE).getCharacteristic(this.hap.Characteristic.BatteryLevel).onGet(() => {
|
|
84
|
+
return this.Battery.StatusLowBattery
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
this.Battery.Service.getCharacteristic(this.hap.Characteristic.StatusLowBattery).onGet(() => {
|
|
88
|
+
return this.Battery.StatusLowBattery
|
|
89
|
+
})
|
|
94
90
|
|
|
95
91
|
// Initialize Leak Sensor Service
|
|
96
92
|
if (device.waterdetector?.hide_leak) {
|
|
97
93
|
if (this.LeakSensor) {
|
|
98
|
-
this.debugLog('Removing Leak Sensor Service')
|
|
99
|
-
this.LeakSensor.Service = this.accessory.getService(this.hap.Service.LeakSensor) as Service
|
|
100
|
-
accessory.removeService(this.LeakSensor.Service)
|
|
94
|
+
this.debugLog('Removing Leak Sensor Service')
|
|
95
|
+
this.LeakSensor.Service = this.accessory.getService(this.hap.Service.LeakSensor) as Service
|
|
96
|
+
accessory.removeService(this.LeakSensor.Service)
|
|
101
97
|
} else {
|
|
102
|
-
this.debugLog('Leak Sensor Service Not Found')
|
|
98
|
+
this.debugLog('Leak Sensor Service Not Found')
|
|
103
99
|
}
|
|
104
100
|
} else {
|
|
105
|
-
accessory.context.LeakSensor = accessory.context.LeakSensor ?? {}
|
|
101
|
+
accessory.context.LeakSensor = accessory.context.LeakSensor ?? {}
|
|
106
102
|
this.LeakSensor = {
|
|
107
103
|
Name: `${accessory.displayName} Leak Sensor`,
|
|
108
104
|
Service: accessory.getService(this.hap.Service.LeakSensor) ?? this.accessory.addService(this.hap.Service.LeakSensor) as Service,
|
|
109
105
|
StatusActive: accessory.context.StatusActive ?? false,
|
|
110
106
|
LeakDetected: accessory.context.LeakDetected ?? this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED,
|
|
111
|
-
}
|
|
112
|
-
accessory.context.LeakSensor = this.LeakSensor as object
|
|
107
|
+
}
|
|
108
|
+
accessory.context.LeakSensor = this.LeakSensor as object
|
|
113
109
|
|
|
114
110
|
// Initialize LeakSensor Characteristic
|
|
115
|
-
this.LeakSensor!.Service
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
.getCharacteristic(this.hap.Characteristic.LeakDetected)
|
|
119
|
-
.onGet(() => {
|
|
120
|
-
return this.LeakSensor!.LeakDetected;
|
|
121
|
-
});
|
|
111
|
+
this.LeakSensor!.Service.setCharacteristic(this.hap.Characteristic.Name, this.LeakSensor.Name).setCharacteristic(this.hap.Characteristic.StatusActive, true).getCharacteristic(this.hap.Characteristic.LeakDetected).onGet(() => {
|
|
112
|
+
return this.LeakSensor!.LeakDetected
|
|
113
|
+
})
|
|
122
114
|
}
|
|
123
115
|
|
|
124
116
|
// Retrieve initial values and updateHomekit
|
|
125
117
|
try {
|
|
126
|
-
this.debugLog('Retrieve initial values and update Homekit')
|
|
127
|
-
this.refreshStatus()
|
|
118
|
+
this.debugLog('Retrieve initial values and update Homekit')
|
|
119
|
+
this.refreshStatus()
|
|
128
120
|
} catch (e: any) {
|
|
129
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
121
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
130
122
|
}
|
|
131
123
|
|
|
132
|
-
//regisiter webhook event handler if enabled
|
|
124
|
+
// regisiter webhook event handler if enabled
|
|
133
125
|
try {
|
|
134
|
-
this.debugLog('Registering Webhook Event Handler')
|
|
135
|
-
this.registerWebhook()
|
|
126
|
+
this.debugLog('Registering Webhook Event Handler')
|
|
127
|
+
this.registerWebhook()
|
|
136
128
|
} catch (e: any) {
|
|
137
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
129
|
+
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
138
130
|
}
|
|
139
131
|
|
|
140
|
-
//regisiter platform BLE event handler if enabled
|
|
132
|
+
// regisiter platform BLE event handler if enabled
|
|
141
133
|
try {
|
|
142
|
-
this.debugLog('Registering Platform BLE Event Handler')
|
|
143
|
-
this.registerPlatformBLE()
|
|
134
|
+
this.debugLog('Registering Platform BLE Event Handler')
|
|
135
|
+
this.registerPlatformBLE()
|
|
144
136
|
} catch (e: any) {
|
|
145
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
137
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
146
138
|
}
|
|
147
139
|
|
|
148
140
|
// Start an update interval
|
|
149
141
|
interval(this.deviceRefreshRate * 1000)
|
|
150
142
|
.pipe(skipWhile(() => this.WaterDetectorUpdateInProgress))
|
|
151
143
|
.subscribe(async () => {
|
|
152
|
-
await this.debugLog(`update interval: ${this.deviceRefreshRate * 1000} seconds`)
|
|
153
|
-
await this.refreshStatus()
|
|
154
|
-
})
|
|
144
|
+
await this.debugLog(`update interval: ${this.deviceRefreshRate * 1000} seconds`)
|
|
145
|
+
await this.refreshStatus()
|
|
146
|
+
})
|
|
155
147
|
}
|
|
156
148
|
|
|
157
149
|
async BLEparseStatus(): Promise<void> {
|
|
158
|
-
await this.debugLog('BLEparseStatus')
|
|
159
|
-
await this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery})
|
|
160
|
-
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
161
|
-
|
|
162
|
-
//LeakSensor
|
|
163
|
-
if (this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
150
|
+
await this.debugLog('BLEparseStatus')
|
|
151
|
+
await this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
|
|
164
152
|
|
|
153
|
+
// LeakSensor
|
|
154
|
+
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
165
155
|
// StatusActive
|
|
166
|
-
this.LeakSensor.StatusActive = this.serviceData.state
|
|
167
|
-
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
156
|
+
this.LeakSensor.StatusActive = this.serviceData.state
|
|
157
|
+
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
168
158
|
|
|
169
159
|
// LeakDetected
|
|
170
|
-
this.
|
|
171
|
-
|
|
160
|
+
if (this.device.waterdetector?.dry) {
|
|
161
|
+
this.LeakSensor.LeakDetected = this.serviceData.status === 0 ? 1 : 0
|
|
162
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
163
|
+
} else {
|
|
164
|
+
this.LeakSensor.LeakDetected = this.serviceData.status
|
|
165
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
166
|
+
}
|
|
172
167
|
}
|
|
173
168
|
// BatteryLevel
|
|
174
|
-
this.Battery.BatteryLevel = this.serviceData.battery
|
|
175
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
169
|
+
this.Battery.BatteryLevel = this.serviceData.battery
|
|
170
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
176
171
|
// StatusLowBattery
|
|
177
172
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
178
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
179
|
-
|
|
173
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
174
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
175
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
async openAPIparseStatus(): Promise<void> {
|
|
183
|
-
await this.debugLog('openAPIparseStatus')
|
|
184
|
-
await this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery})
|
|
185
|
-
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
179
|
+
await this.debugLog('openAPIparseStatus')
|
|
180
|
+
await this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
|
|
186
181
|
|
|
187
|
-
//LeakSensor
|
|
182
|
+
// LeakSensor
|
|
188
183
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
189
|
-
|
|
190
184
|
// StatusActive
|
|
191
|
-
this.LeakSensor.StatusActive = this.deviceStatus.battery
|
|
192
|
-
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
185
|
+
this.LeakSensor.StatusActive = this.deviceStatus.battery !== 0
|
|
186
|
+
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
193
187
|
|
|
194
188
|
// LeakDetected
|
|
195
|
-
this.
|
|
196
|
-
|
|
189
|
+
if (this.device.waterdetector?.dry) {
|
|
190
|
+
this.LeakSensor.LeakDetected = this.deviceStatus.status === 0 ? 1 : 0
|
|
191
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
192
|
+
} else {
|
|
193
|
+
this.LeakSensor.LeakDetected = this.deviceStatus.status
|
|
194
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
195
|
+
}
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
// BatteryLevel
|
|
200
|
-
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
201
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
199
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery
|
|
200
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
202
201
|
|
|
203
202
|
// StatusLowBattery
|
|
204
203
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
205
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
206
|
-
|
|
204
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
205
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
206
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
207
207
|
|
|
208
208
|
// FirmwareVersion
|
|
209
209
|
if (this.deviceStatus.version) {
|
|
210
|
-
const version = this.deviceStatus.version.toString()
|
|
211
|
-
await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`)
|
|
212
|
-
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
210
|
+
const version = this.deviceStatus.version.toString()
|
|
211
|
+
await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`)
|
|
212
|
+
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0'
|
|
213
213
|
this.accessory
|
|
214
214
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
215
215
|
.setCharacteristic(this.hap.Characteristic.HardwareRevision, deviceVersion)
|
|
216
216
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
217
217
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
218
|
-
.updateValue(deviceVersion)
|
|
219
|
-
this.accessory.context.version = deviceVersion
|
|
220
|
-
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
218
|
+
.updateValue(deviceVersion)
|
|
219
|
+
this.accessory.context.version = deviceVersion
|
|
220
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`)
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
224
|
async parseStatusWebhook(): Promise<void> {
|
|
225
|
-
await this.debugLog('parseStatusWebhook')
|
|
226
|
-
await this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery})
|
|
227
|
-
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
225
|
+
await this.debugLog('parseStatusWebhook')
|
|
226
|
+
await this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}), current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`)
|
|
228
227
|
|
|
229
|
-
//LeakSensor
|
|
228
|
+
// LeakSensor
|
|
230
229
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
231
|
-
|
|
232
230
|
// StatusActive
|
|
233
|
-
this.LeakSensor.StatusActive = this.webhookContext.detectionState
|
|
234
|
-
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
231
|
+
this.LeakSensor.StatusActive = !!this.webhookContext.detectionState
|
|
232
|
+
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`)
|
|
235
233
|
|
|
236
234
|
// LeakDetected
|
|
237
|
-
this.
|
|
238
|
-
|
|
235
|
+
if (this.device.waterdetector?.dry) {
|
|
236
|
+
this.LeakSensor.LeakDetected = this.webhookContext.detectionState === 0 ? 1 : 0
|
|
237
|
+
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
238
|
+
} else {
|
|
239
|
+
this.LeakSensor.LeakDetected = this.webhookContext.detectionState
|
|
240
|
+
await this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`)
|
|
241
|
+
}
|
|
239
242
|
}
|
|
240
243
|
|
|
241
244
|
// BatteryLevel
|
|
242
|
-
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
243
|
-
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
245
|
+
this.Battery.BatteryLevel = this.webhookContext.battery
|
|
246
|
+
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`)
|
|
244
247
|
|
|
245
248
|
// StatusLowBattery
|
|
246
249
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
247
|
-
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
248
|
-
|
|
250
|
+
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW
|
|
251
|
+
: this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL
|
|
252
|
+
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`)
|
|
249
253
|
}
|
|
250
254
|
|
|
251
255
|
/**
|
|
@@ -253,97 +257,97 @@ export class WaterDetector extends deviceBase {
|
|
|
253
257
|
*/
|
|
254
258
|
async refreshStatus(): Promise<void> {
|
|
255
259
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
256
|
-
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
260
|
+
await this.errorLog(`refreshStatus enableCloudService: ${this.device.enableCloudService}`)
|
|
257
261
|
} else if (this.BLE) {
|
|
258
|
-
await this.BLERefreshStatus()
|
|
262
|
+
await this.BLERefreshStatus()
|
|
259
263
|
} else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
260
|
-
await this.openAPIRefreshStatus()
|
|
264
|
+
await this.openAPIRefreshStatus()
|
|
261
265
|
} else {
|
|
262
|
-
await this.offlineOff()
|
|
263
|
-
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
266
|
+
await this.offlineOff()
|
|
267
|
+
await this.debugWarnLog(`Connection Type: ${this.device.connectionType}, refreshStatus will not happen.`)
|
|
264
268
|
}
|
|
265
269
|
}
|
|
266
270
|
|
|
267
271
|
async BLERefreshStatus(): Promise<void> {
|
|
268
|
-
await this.debugLog('BLERefreshStatus')
|
|
269
|
-
const switchbot = await this.switchbotBLE()
|
|
272
|
+
await this.debugLog('BLERefreshStatus')
|
|
273
|
+
const switchbot = await this.switchbotBLE()
|
|
270
274
|
if (switchbot === undefined) {
|
|
271
|
-
await this.BLERefreshConnection(switchbot)
|
|
275
|
+
await this.BLERefreshConnection(switchbot)
|
|
272
276
|
} else {
|
|
273
277
|
// Start to monitor advertisement packets
|
|
274
278
|
(async () => {
|
|
275
279
|
// Start to monitor advertisement packets
|
|
276
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData
|
|
280
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData
|
|
277
281
|
// Update HomeKit
|
|
278
282
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
279
|
-
this.serviceData = serviceData
|
|
280
|
-
await this.BLEparseStatus()
|
|
281
|
-
await this.updateHomeKitCharacteristics()
|
|
283
|
+
this.serviceData = serviceData
|
|
284
|
+
await this.BLEparseStatus()
|
|
285
|
+
await this.updateHomeKitCharacteristics()
|
|
282
286
|
} else {
|
|
283
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
284
|
-
await this.BLERefreshConnection(switchbot)
|
|
287
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
288
|
+
await this.BLERefreshConnection(switchbot)
|
|
285
289
|
}
|
|
286
|
-
})()
|
|
290
|
+
})()
|
|
287
291
|
}
|
|
288
292
|
}
|
|
289
293
|
|
|
290
294
|
async registerPlatformBLE(): Promise<void> {
|
|
291
|
-
await this.debugLog('registerPlatformBLE')
|
|
295
|
+
await this.debugLog('registerPlatformBLE')
|
|
292
296
|
if (this.config.options?.BLE) {
|
|
293
|
-
await this.debugLog('is listening to Platform BLE.')
|
|
294
|
-
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
295
|
-
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
297
|
+
await this.debugLog('is listening to Platform BLE.')
|
|
298
|
+
this.device.bleMac = this.device.deviceId!.match(/.{1,2}/g)!.join(':').toLowerCase()
|
|
299
|
+
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
296
300
|
this.platform.bleEventHandler[this.device.bleMac] = async (context: waterLeakDetectorServiceData) => {
|
|
297
301
|
try {
|
|
298
|
-
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
299
|
-
this.serviceData = context
|
|
300
|
-
await this.BLEparseStatus()
|
|
301
|
-
await this.updateHomeKitCharacteristics()
|
|
302
|
+
await this.debugLog(`received BLE: ${JSON.stringify(context)}`)
|
|
303
|
+
this.serviceData = context
|
|
304
|
+
await this.BLEparseStatus()
|
|
305
|
+
await this.updateHomeKitCharacteristics()
|
|
302
306
|
} catch (e: any) {
|
|
303
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
307
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
304
308
|
}
|
|
305
|
-
}
|
|
309
|
+
}
|
|
306
310
|
} else {
|
|
307
|
-
await this.debugLog('is not listening to Platform BLE')
|
|
311
|
+
await this.debugLog('is not listening to Platform BLE')
|
|
308
312
|
}
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
async openAPIRefreshStatus(): Promise<void> {
|
|
312
|
-
await this.debugLog('openAPIRefreshStatus')
|
|
316
|
+
await this.debugLog('openAPIRefreshStatus')
|
|
313
317
|
try {
|
|
314
|
-
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
315
|
-
const deviceStatus: any = await body.json()
|
|
316
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
318
|
+
const { body, statusCode } = await this.deviceRefreshStatus()
|
|
319
|
+
const deviceStatus: any = await body.json()
|
|
320
|
+
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
317
321
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
318
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
319
|
-
this.deviceStatus = deviceStatus.body
|
|
320
|
-
await this.openAPIparseStatus()
|
|
321
|
-
await this.updateHomeKitCharacteristics()
|
|
322
|
+
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
323
|
+
this.deviceStatus = deviceStatus.body
|
|
324
|
+
await this.openAPIparseStatus()
|
|
325
|
+
await this.updateHomeKitCharacteristics()
|
|
322
326
|
} else {
|
|
323
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
324
|
-
await this.debugWarnLog(statusCode, deviceStatus)
|
|
327
|
+
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
328
|
+
await this.debugWarnLog(statusCode, deviceStatus)
|
|
325
329
|
}
|
|
326
330
|
} catch (e: any) {
|
|
327
|
-
await this.apiError(e)
|
|
328
|
-
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
331
|
+
await this.apiError(e)
|
|
332
|
+
await this.errorLog(`failed openAPIRefreshStatus with ${this.device.connectionType} Connection, Error Message: ${JSON.stringify(e.message)}`)
|
|
329
333
|
}
|
|
330
334
|
}
|
|
331
335
|
|
|
332
336
|
async registerWebhook() {
|
|
333
337
|
if (this.device.webhook) {
|
|
334
|
-
await this.debugLog('is listening webhook.')
|
|
338
|
+
await this.debugLog('is listening webhook.')
|
|
335
339
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
|
|
336
340
|
try {
|
|
337
|
-
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
338
|
-
this.webhookContext = context
|
|
339
|
-
await this.parseStatusWebhook()
|
|
340
|
-
await this.updateHomeKitCharacteristics()
|
|
341
|
+
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`)
|
|
342
|
+
this.webhookContext = context
|
|
343
|
+
await this.parseStatusWebhook()
|
|
344
|
+
await this.updateHomeKitCharacteristics()
|
|
341
345
|
} catch (e: any) {
|
|
342
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
346
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
343
347
|
}
|
|
344
|
-
}
|
|
348
|
+
}
|
|
345
349
|
} else {
|
|
346
|
-
await this.debugLog('is not listening webhook.')
|
|
350
|
+
await this.debugLog('is not listening webhook.')
|
|
347
351
|
}
|
|
348
352
|
}
|
|
349
353
|
|
|
@@ -353,43 +357,39 @@ export class WaterDetector extends deviceBase {
|
|
|
353
357
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
354
358
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
355
359
|
// StatusActive
|
|
356
|
-
await this.updateCharacteristic(this.LeakSensor.Service, this.hap.Characteristic.StatusActive,
|
|
357
|
-
this.LeakSensor.StatusActive, 'StatusActive');
|
|
360
|
+
await this.updateCharacteristic(this.LeakSensor.Service, this.hap.Characteristic.StatusActive, this.LeakSensor.StatusActive, 'StatusActive')
|
|
358
361
|
// LeakDetected
|
|
359
|
-
await this.updateCharacteristic(this.LeakSensor.Service, this.hap.Characteristic.LeakDetected,
|
|
360
|
-
this.LeakSensor.LeakDetected, 'LeakDetected');
|
|
362
|
+
await this.updateCharacteristic(this.LeakSensor.Service, this.hap.Characteristic.LeakDetected, this.LeakSensor.LeakDetected, 'LeakDetected')
|
|
361
363
|
}
|
|
362
364
|
// BatteryLevel
|
|
363
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel,
|
|
364
|
-
this.Battery.BatteryLevel, 'BatteryLevel');
|
|
365
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel, 'BatteryLevel')
|
|
365
366
|
// StatusLowBattery
|
|
366
|
-
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery,
|
|
367
|
-
this.Battery.StatusLowBattery, 'StatusLowBattery');
|
|
367
|
+
await this.updateCharacteristic(this.Battery.Service, this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery, 'StatusLowBattery')
|
|
368
368
|
}
|
|
369
369
|
|
|
370
370
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
371
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
371
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`)
|
|
372
372
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
373
|
-
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
374
|
-
await this.openAPIRefreshStatus()
|
|
373
|
+
await this.warnLog('Using OpenAPI Connection to Refresh Status')
|
|
374
|
+
await this.openAPIRefreshStatus()
|
|
375
375
|
}
|
|
376
376
|
}
|
|
377
377
|
|
|
378
378
|
async offlineOff(): Promise<void> {
|
|
379
379
|
if (this.device.offline) {
|
|
380
380
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
381
|
-
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, false)
|
|
382
|
-
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED)
|
|
381
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, false)
|
|
382
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED)
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
-
async apiError(e: any): Promise
|
|
388
|
-
if(!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
389
|
-
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
|
|
390
|
-
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, e)
|
|
387
|
+
async apiError(e: any): Promise<void> {
|
|
388
|
+
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
389
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.StatusActive, e)
|
|
390
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, e)
|
|
391
391
|
}
|
|
392
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
393
|
-
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
392
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e)
|
|
393
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e)
|
|
394
394
|
}
|
|
395
395
|
}
|
|
@@ -1,47 +1,48 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import fs from 'node:fs'
|
|
2
|
+
|
|
3
|
+
import { HomebridgePluginUiServer } from '@homebridge/plugin-ui-utils'
|
|
3
4
|
|
|
4
5
|
class PluginUiServer extends HomebridgePluginUiServer {
|
|
5
6
|
constructor() {
|
|
6
|
-
super()
|
|
7
|
+
super()
|
|
7
8
|
/*
|
|
8
9
|
A native method getCachedAccessories() was introduced in config-ui-x v4.37.0
|
|
9
10
|
The following is for users who have a lower version of config-ui-x
|
|
10
11
|
*/
|
|
11
12
|
this.onRequest('getCachedAccessories', () => {
|
|
12
13
|
try {
|
|
13
|
-
const plugin = 'homebridge-switchbot'
|
|
14
|
-
const devicesToReturn = []
|
|
14
|
+
const plugin = 'homebridge-switchbot'
|
|
15
|
+
const devicesToReturn = []
|
|
15
16
|
|
|
16
17
|
// The path and file of the cached accessories
|
|
17
|
-
const accFile = this.homebridgeStoragePath
|
|
18
|
+
const accFile = `${this.homebridgeStoragePath}/accessories/cachedAccessories`
|
|
18
19
|
|
|
19
20
|
// Check the file exists
|
|
20
21
|
if (fs.existsSync(accFile)) {
|
|
21
22
|
// read the cached accessories file
|
|
22
|
-
const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8'))
|
|
23
|
+
const cachedAccessories: any[] = JSON.parse(fs.readFileSync(accFile, 'utf8'))
|
|
23
24
|
|
|
24
25
|
cachedAccessories.forEach((accessory: any) => {
|
|
25
26
|
// Check the accessory is from this plugin
|
|
26
27
|
if (accessory.plugin === plugin) {
|
|
27
28
|
// Add the cached accessory to the array
|
|
28
|
-
devicesToReturn.push(accessory.accessory as never)
|
|
29
|
+
devicesToReturn.push(accessory.accessory as never)
|
|
29
30
|
}
|
|
30
|
-
})
|
|
31
|
+
})
|
|
31
32
|
}
|
|
32
33
|
// Return the array
|
|
33
|
-
return devicesToReturn
|
|
34
|
+
return devicesToReturn
|
|
34
35
|
} catch {
|
|
35
36
|
// Just return an empty accessory list in case of any errors
|
|
36
|
-
return []
|
|
37
|
+
return []
|
|
37
38
|
}
|
|
38
|
-
})
|
|
39
|
-
this.ready()
|
|
39
|
+
})
|
|
40
|
+
this.ready()
|
|
40
41
|
}
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
function startPluginUiServer(): PluginUiServer {
|
|
44
|
-
return new PluginUiServer()
|
|
45
|
+
return new PluginUiServer()
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
startPluginUiServer()
|
|
48
|
+
startPluginUiServer()
|