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