@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.61
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/.vscode/settings.json +4 -1
- package/CHANGELOG.md +4 -1
- package/config.schema.json +120 -17
- package/dist/device/blindtilt.d.ts +23 -96
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +408 -779
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +26 -72
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +696 -822
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +14 -68
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +237 -606
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +14 -75
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +280 -658
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +15 -66
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +242 -544
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +19 -88
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +402 -805
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +59 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +684 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/fan.d.ts +51 -0
- package/dist/device/fan.d.ts.map +1 -0
- package/dist/device/fan.js +535 -0
- package/dist/device/fan.js.map +1 -0
- package/dist/device/hub.d.ts +16 -60
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +246 -613
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +11 -66
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +232 -593
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +11 -64
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +185 -600
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +11 -69
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +277 -586
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +16 -63
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +241 -560
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +14 -64
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +181 -593
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +14 -65
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +170 -593
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +13 -69
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +178 -531
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +9 -57
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +92 -458
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +12 -63
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +197 -521
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +10 -65
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +139 -495
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +22 -16
- package/dist/homebridge-ui/server.js +1 -1
- package/dist/homebridge-ui/server.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +9 -49
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +309 -419
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +8 -39
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +72 -304
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +7 -36
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +34 -278
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +10 -43
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +100 -338
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +40 -0
- package/dist/irdevice/irdevice.d.ts.map +1 -0
- package/dist/irdevice/irdevice.js +330 -0
- package/dist/irdevice/irdevice.js.map +1 -0
- package/dist/irdevice/light.d.ts +12 -45
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +87 -357
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +19 -48
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +352 -546
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +8 -40
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +82 -321
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +7 -36
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +41 -284
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +7 -36
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +42 -287
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +19 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +310 -169
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +62 -19
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +16 -552
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +77 -0
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +638 -1
- package/dist/utils.js.map +1 -1
- package/eslint.config.js +96 -0
- package/package.json +19 -15
- package/src/custom.d.ts +2 -1
- package/src/device/blindtilt.ts +442 -814
- package/src/device/bot.ts +754 -915
- package/src/device/ceilinglight.ts +255 -633
- package/src/device/colorbulb.ts +295 -685
- package/src/device/contact.ts +277 -571
- package/src/device/curtain.ts +431 -835
- package/src/device/device.ts +709 -0
- package/src/device/fan.ts +591 -0
- package/src/device/hub.ts +286 -644
- package/src/device/humidifier.ts +266 -646
- package/src/device/iosensor.ts +220 -625
- package/src/device/lightstrip.ts +305 -620
- package/src/device/lock.ts +280 -600
- package/src/device/meter.ts +216 -617
- package/src/device/meterplus.ts +205 -619
- package/src/device/motion.ts +206 -556
- package/src/device/plug.ts +107 -490
- package/src/device/robotvacuumcleaner.ts +223 -550
- package/src/device/waterdetector.ts +160 -519
- package/src/homebridge-ui/public/index.html +22 -16
- package/src/homebridge-ui/server.ts +1 -1
- package/src/index.ts +4 -3
- package/src/irdevice/airconditioner.ts +333 -447
- package/src/irdevice/airpurifier.ts +92 -322
- package/src/irdevice/camera.ts +45 -294
- package/src/irdevice/fan.ts +115 -353
- package/src/irdevice/irdevice.ts +346 -0
- package/src/irdevice/light.ts +110 -385
- package/src/irdevice/other.ts +399 -616
- package/src/irdevice/tv.ts +103 -340
- package/src/irdevice/vacuumcleaner.ts +52 -306
- package/src/irdevice/waterheater.ts +53 -311
- package/src/platform.ts +355 -216
- package/src/settings.ts +116 -611
- package/src/utils.ts +642 -1
- package/src/device/waterdetector.json +0 -11
|
@@ -1,135 +1,79 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/* Copyright(C) 2021-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* waterdetector.ts: @switchbot/homebridge-switchbot.
|
|
4
|
+
*/
|
|
5
|
+
import { deviceBase } from './device.js';
|
|
5
6
|
import { interval, Subject } from 'rxjs';
|
|
6
|
-
import { skipWhile } from 'rxjs/operators';
|
|
7
7
|
import { Devices } from '../settings.js';
|
|
8
|
+
import { skipWhile } from 'rxjs/operators';
|
|
8
9
|
/**
|
|
9
10
|
* Platform Accessory
|
|
10
11
|
* An instance of this class is created for each accessory your platform registers
|
|
11
12
|
* Each accessory may expose multiple services of different service types.
|
|
12
13
|
*/
|
|
13
|
-
export class WaterDetector {
|
|
14
|
+
export class WaterDetector extends deviceBase {
|
|
14
15
|
platform;
|
|
15
|
-
accessory;
|
|
16
|
-
device;
|
|
17
|
-
api;
|
|
18
|
-
log;
|
|
19
|
-
config;
|
|
20
|
-
hap;
|
|
21
16
|
// Services
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
humidityservice;
|
|
25
|
-
temperatureservice;
|
|
26
|
-
// Characteristic Values
|
|
27
|
-
StatusActive;
|
|
28
|
-
LeakDetected;
|
|
29
|
-
BatteryLevel;
|
|
30
|
-
ChargingState;
|
|
31
|
-
StatusLowBattery;
|
|
32
|
-
FirmwareRevision;
|
|
33
|
-
// OpenAPI Status
|
|
34
|
-
OpenAPI_BatteryLevel;
|
|
35
|
-
OpenAPI_FirmwareRevision;
|
|
36
|
-
OpenAPI_LeakDetected;
|
|
37
|
-
// BLE Status
|
|
38
|
-
BLE_BatteryLevel;
|
|
39
|
-
BLE_LeakDetected; //serviceData['status'];
|
|
40
|
-
// BLE Others
|
|
41
|
-
BLE_IsConnected;
|
|
42
|
-
//MQTT stuff
|
|
43
|
-
mqttClient = null;
|
|
44
|
-
// EVE history service handler
|
|
45
|
-
historyService;
|
|
46
|
-
// Config
|
|
47
|
-
scanDuration;
|
|
48
|
-
deviceLogging;
|
|
49
|
-
deviceRefreshRate;
|
|
17
|
+
Battery;
|
|
18
|
+
LeakSensor;
|
|
50
19
|
// Updates
|
|
51
20
|
WaterDetectorUpdateInProgress;
|
|
52
21
|
doWaterDetectorUpdate;
|
|
53
|
-
// Connection
|
|
54
|
-
OpenAPI;
|
|
55
|
-
BLE;
|
|
56
22
|
constructor(platform, accessory, device) {
|
|
23
|
+
super(platform, accessory, device);
|
|
57
24
|
this.platform = platform;
|
|
58
|
-
this.accessory = accessory;
|
|
59
|
-
this.device = device;
|
|
60
|
-
this.api = this.platform.api;
|
|
61
|
-
this.log = this.platform.log;
|
|
62
|
-
this.config = this.platform.config;
|
|
63
|
-
this.hap = this.api.hap;
|
|
64
|
-
// Connection
|
|
65
|
-
this.BLE = this.device.connectionType === 'BLE' || this.device.connectionType === 'BLE/OpenAPI';
|
|
66
|
-
this.OpenAPI = this.device.connectionType === 'OpenAPI' || this.device.connectionType === 'BLE/OpenAPI';
|
|
67
25
|
// default placeholders
|
|
68
|
-
this.deviceLogs(device);
|
|
69
|
-
this.scan(device);
|
|
70
|
-
this.refreshRate(device);
|
|
71
|
-
this.deviceContext();
|
|
72
26
|
this.setupHistoryService(device);
|
|
73
|
-
this.setupMqtt(device);
|
|
74
|
-
this.deviceConfig(device);
|
|
75
27
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
76
28
|
this.doWaterDetectorUpdate = new Subject();
|
|
77
29
|
this.WaterDetectorUpdateInProgress = false;
|
|
78
|
-
//
|
|
79
|
-
this.
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
.
|
|
83
|
-
.
|
|
84
|
-
.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
30
|
+
// Initialize Battery Service
|
|
31
|
+
this.Battery = {
|
|
32
|
+
Name: accessory.context.BatteryName ?? `${accessory.displayName} Battery`,
|
|
33
|
+
Service: accessory.getService(this.hap.Service.Battery) ?? accessory.addService(this.hap.Service.Battery),
|
|
34
|
+
BatteryLevel: accessory.context.BatteryLevel ?? 100,
|
|
35
|
+
StatusLowBattery: accessory.context.StatusLowBattery ?? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL,
|
|
36
|
+
ChargingState: accessory.context.ChargingState ?? this.hap.Characteristic.ChargingState.NOT_CHARGEABLE,
|
|
37
|
+
};
|
|
38
|
+
// Initialize Battery Characteristic
|
|
39
|
+
this.Battery.Service
|
|
40
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.Battery.Name)
|
|
41
|
+
.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE)
|
|
42
|
+
.getCharacteristic(this.hap.Characteristic.BatteryLevel)
|
|
43
|
+
.onGet(() => {
|
|
44
|
+
return this.Battery.StatusLowBattery;
|
|
45
|
+
});
|
|
46
|
+
this.Battery.Service
|
|
47
|
+
.getCharacteristic(this.hap.Characteristic.StatusLowBattery)
|
|
48
|
+
.onGet(() => {
|
|
49
|
+
return this.Battery.StatusLowBattery;
|
|
50
|
+
});
|
|
51
|
+
accessory.context.BatteryName = this.Battery.Name;
|
|
52
|
+
// Initialize Leak Sensor Service
|
|
88
53
|
if (device.waterdetector?.hide_leak) {
|
|
89
54
|
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Leak Sensor Service`);
|
|
90
|
-
this.
|
|
91
|
-
accessory.removeService(this.
|
|
92
|
-
}
|
|
93
|
-
else if (!this.leakService) {
|
|
94
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Add Leak Sensor Service`);
|
|
95
|
-
const leakService = `${accessory.displayName} Leak Sensor`;
|
|
96
|
-
(this.leakService = this.accessory.getService(this.hap.Service.LeakSensor)
|
|
97
|
-
|| this.accessory.addService(this.hap.Service.LeakSensor)), leakService;
|
|
98
|
-
this.leakService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Leak Sensor`);
|
|
99
|
-
if (!this.leakService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
100
|
-
this.leakService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Leak Sensor`);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Leak Sensor Service Not Added`);
|
|
105
|
-
}
|
|
106
|
-
// Temperature Sensor Service
|
|
107
|
-
if (device.waterdetector?.hide_temperature) {
|
|
108
|
-
this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Temperature Sensor Service`);
|
|
109
|
-
this.temperatureservice = this.accessory.getService(this.hap.Service.TemperatureSensor);
|
|
110
|
-
accessory.removeService(this.temperatureservice);
|
|
55
|
+
this.LeakSensor.Service = this.accessory.getService(this.hap.Service.LeakSensor);
|
|
56
|
+
accessory.removeService(this.LeakSensor.Service);
|
|
111
57
|
}
|
|
112
58
|
else {
|
|
113
|
-
this.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
this.batteryService.setCharacteristic(this.hap.Characteristic.Name, `${accessory.displayName} Battery`);
|
|
129
|
-
if (!this.batteryService.testCharacteristic(this.hap.Characteristic.ConfiguredName)) {
|
|
130
|
-
this.batteryService.addCharacteristic(this.hap.Characteristic.ConfiguredName, `${accessory.displayName} Battery`);
|
|
59
|
+
this.LeakSensor = {
|
|
60
|
+
Name: accessory.context.LeakSensorName ?? `${accessory.displayName} Leak Sensor`,
|
|
61
|
+
Service: accessory.getService(this.hap.Service.LeakSensor) ?? this.accessory.addService(this.hap.Service.LeakSensor),
|
|
62
|
+
StatusActive: accessory.context.StatusActive ?? false,
|
|
63
|
+
LeakDetected: accessory.context.LeakDetected ?? this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED,
|
|
64
|
+
};
|
|
65
|
+
// Initialize LeakSensor Characteristic
|
|
66
|
+
this.LeakSensor.Service
|
|
67
|
+
.setCharacteristic(this.hap.Characteristic.Name, this.LeakSensor.Name)
|
|
68
|
+
.setCharacteristic(this.hap.Characteristic.StatusActive, true)
|
|
69
|
+
.getCharacteristic(this.hap.Characteristic.LeakDetected)
|
|
70
|
+
.onGet(() => {
|
|
71
|
+
return this.LeakSensor.LeakDetected;
|
|
72
|
+
});
|
|
73
|
+
accessory.context.LeakSensorName = this.LeakSensor.Name;
|
|
131
74
|
}
|
|
132
|
-
|
|
75
|
+
// Retrieve initial values and updateHomekit
|
|
76
|
+
this.refreshStatus();
|
|
133
77
|
// Retrieve initial values and updateHomekit
|
|
134
78
|
this.updateHomeKitCharacteristics();
|
|
135
79
|
// Start an update interval
|
|
@@ -139,18 +83,20 @@ export class WaterDetector {
|
|
|
139
83
|
await this.refreshStatus();
|
|
140
84
|
});
|
|
141
85
|
//regisiter webhook event handler
|
|
142
|
-
if (this.device.
|
|
143
|
-
this.
|
|
86
|
+
if (device.webhook && !this.device.waterdetector?.hide_leak) {
|
|
87
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
|
|
144
88
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context) => {
|
|
145
89
|
try {
|
|
146
90
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} received Webhook: ${JSON.stringify(context)}`);
|
|
147
|
-
const {
|
|
148
|
-
const { LeakDetected } = this;
|
|
91
|
+
const { detectionState, battery } = context;
|
|
92
|
+
const { LeakDetected } = this.LeakSensor;
|
|
93
|
+
const { BatteryLevel } = this.Battery;
|
|
149
94
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ` +
|
|
150
|
-
'(
|
|
151
|
-
`Webhook:(${
|
|
152
|
-
`current:(${LeakDetected})`);
|
|
153
|
-
this.LeakDetected =
|
|
95
|
+
'(detectionState, battery) = ' +
|
|
96
|
+
`Webhook:(${detectionState}, ${battery}), ` +
|
|
97
|
+
`current:(${LeakDetected}, ${BatteryLevel})`);
|
|
98
|
+
this.LeakSensor.LeakDetected = detectionState;
|
|
99
|
+
this.Battery.BatteryLevel = battery;
|
|
154
100
|
this.updateHomeKitCharacteristics();
|
|
155
101
|
}
|
|
156
102
|
catch (e) {
|
|
@@ -160,65 +106,56 @@ export class WaterDetector {
|
|
|
160
106
|
};
|
|
161
107
|
}
|
|
162
108
|
}
|
|
163
|
-
|
|
164
|
-
* Parse the device status from the SwitchBot api
|
|
165
|
-
*/
|
|
166
|
-
async parseStatus() {
|
|
167
|
-
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
168
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} parseStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
169
|
-
}
|
|
170
|
-
else if (this.BLE) {
|
|
171
|
-
await this.BLEparseStatus();
|
|
172
|
-
}
|
|
173
|
-
else if (this.OpenAPI && this.platform.config.credentials?.token) {
|
|
174
|
-
await this.openAPIparseStatus();
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
await this.offlineOff();
|
|
178
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Connection Type:` + ` ${this.device.connectionType}, parseStatus will not happen.`);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
async BLEparseStatus() {
|
|
109
|
+
async BLEparseStatus(serviceData) {
|
|
182
110
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BLEparseStatus`);
|
|
183
111
|
// Battery
|
|
184
|
-
this.BatteryLevel = Number(
|
|
185
|
-
if (this.BatteryLevel < 15) {
|
|
186
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
112
|
+
this.Battery.BatteryLevel = Number(serviceData.battery);
|
|
113
|
+
if (this.Battery.BatteryLevel < 15) {
|
|
114
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
187
115
|
}
|
|
188
116
|
else {
|
|
189
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
117
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
190
118
|
}
|
|
191
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
119
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
192
120
|
// LeakDetected
|
|
193
|
-
this.
|
|
194
|
-
|
|
121
|
+
if (this.device.waterdetector?.hide_leak) {
|
|
122
|
+
this.LeakSensor.LeakDetected = serviceData.status;
|
|
123
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
124
|
+
}
|
|
195
125
|
}
|
|
196
|
-
async openAPIparseStatus() {
|
|
126
|
+
async openAPIparseStatus(deviceStatus) {
|
|
197
127
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIparseStatus`);
|
|
198
128
|
// StatusLowBattery
|
|
199
|
-
this.BatteryLevel = Number(
|
|
200
|
-
if (this.BatteryLevel < 10) {
|
|
201
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
129
|
+
this.Battery.BatteryLevel = Number(deviceStatus.body.battery);
|
|
130
|
+
if (this.Battery.BatteryLevel < 10) {
|
|
131
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW;
|
|
202
132
|
}
|
|
203
133
|
else {
|
|
204
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
134
|
+
this.Battery.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
205
135
|
}
|
|
206
|
-
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}, StatusLowBattery: ${this.StatusLowBattery}`);
|
|
136
|
+
this.debugLog(`${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}, StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
207
137
|
// BatteryLevel
|
|
208
|
-
if (Number.isNaN(this.BatteryLevel)) {
|
|
209
|
-
this.BatteryLevel = 100;
|
|
138
|
+
if (Number.isNaN(this.Battery.BatteryLevel)) {
|
|
139
|
+
this.Battery.BatteryLevel = 100;
|
|
210
140
|
}
|
|
211
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
141
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
212
142
|
// LeakDetected
|
|
213
|
-
this.
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
143
|
+
if (!this.device.waterdetector?.hide_leak) {
|
|
144
|
+
this.LeakSensor.LeakDetected = deviceStatus.body.status;
|
|
145
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
146
|
+
}
|
|
147
|
+
// Firmware Version
|
|
148
|
+
const version = deviceStatus.body.version?.toString();
|
|
149
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Firmware Version: ${version?.replace(/^V|-.*$/g, '')}`);
|
|
150
|
+
if (deviceStatus.body.version) {
|
|
151
|
+
this.accessory.context.version = version?.replace(/^V|-.*$/g, '');
|
|
152
|
+
this.accessory
|
|
153
|
+
.getService(this.hap.Service.AccessoryInformation)
|
|
154
|
+
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, this.accessory.context.version)
|
|
155
|
+
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
156
|
+
.updateValue(this.accessory.context.version);
|
|
157
|
+
}
|
|
218
158
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Asks the SwitchBot API for the latest device information
|
|
221
|
-
*/
|
|
222
159
|
async refreshStatus() {
|
|
223
160
|
if (!this.device.enableCloudService && this.OpenAPI) {
|
|
224
161
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} refreshStatus enableCloudService: ${this.device.enableCloudService}`);
|
|
@@ -248,49 +185,42 @@ export class WaterDetector {
|
|
|
248
185
|
// Start to monitor advertisement packets
|
|
249
186
|
(async () => {
|
|
250
187
|
// Start to monitor advertisement packets
|
|
251
|
-
await switchbot.startScan({
|
|
252
|
-
model: 'l',
|
|
253
|
-
id: this.device.bleMac,
|
|
254
|
-
});
|
|
188
|
+
await switchbot.startScan({ model: this.device.bleModel, id: this.device.bleMac });
|
|
255
189
|
// Set an event handler
|
|
256
190
|
switchbot.onadvertisement = (ad) => {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
191
|
+
if (this.device.bleMac === ad.address && ad.model === this.device.bleModel) {
|
|
192
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
|
|
193
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.model}`);
|
|
260
194
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
261
|
-
this.BLE_LeakDetected = ad.serviceData.status;
|
|
262
|
-
this.BLE_BatteryLevel = ad.serviceData.battery;
|
|
263
195
|
}
|
|
264
196
|
else {
|
|
265
197
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} serviceData: ${JSON.stringify(ad.serviceData)}`);
|
|
266
198
|
}
|
|
267
199
|
};
|
|
268
|
-
// Wait
|
|
200
|
+
// Wait 10 seconds
|
|
269
201
|
await switchbot.wait(this.scanDuration * 1000);
|
|
270
202
|
// Stop to monitor
|
|
271
203
|
await switchbot.stopScan();
|
|
272
204
|
// Update HomeKit
|
|
273
|
-
await this.BLEparseStatus();
|
|
205
|
+
await this.BLEparseStatus(switchbot.onadvertisement.serviceData);
|
|
274
206
|
await this.updateHomeKitCharacteristics();
|
|
275
207
|
})();
|
|
208
|
+
if (switchbot === undefined) {
|
|
209
|
+
await this.BLERefreshConnection(switchbot);
|
|
210
|
+
}
|
|
276
211
|
}
|
|
277
212
|
async openAPIRefreshStatus() {
|
|
278
213
|
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} openAPIRefreshStatus`);
|
|
279
214
|
try {
|
|
280
|
-
const { body, statusCode } = await
|
|
281
|
-
headers: this.platform.generateHeaders(),
|
|
282
|
-
});
|
|
215
|
+
const { body, statusCode } = await this.platform.retryRequest(this.deviceMaxRetries, this.deviceDelayBetweenRetries, `${Devices}/${this.device.deviceId}/status`, { headers: this.platform.generateHeaders() });
|
|
283
216
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} statusCode: ${statusCode}`);
|
|
284
217
|
const deviceStatus = await body.json();
|
|
285
218
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
286
219
|
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} deviceStatus statusCode: ${deviceStatus.statusCode}`);
|
|
287
220
|
if ((statusCode === 200 || statusCode === 100) && (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)) {
|
|
288
|
-
this.
|
|
221
|
+
this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
|
|
289
222
|
+ `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
|
|
290
|
-
this.
|
|
291
|
-
this.OpenAPI_BatteryLevel = deviceStatus.body.battery;
|
|
292
|
-
this.OpenAPI_FirmwareRevision = deviceStatus.body.version;
|
|
293
|
-
this.openAPIparseStatus();
|
|
223
|
+
this.openAPIparseStatus(deviceStatus);
|
|
294
224
|
this.updateHomeKitCharacteristics();
|
|
295
225
|
}
|
|
296
226
|
else {
|
|
@@ -311,128 +241,56 @@ export class WaterDetector {
|
|
|
311
241
|
const mqttmessage = [];
|
|
312
242
|
const entry = { time: Math.round(new Date().valueOf() / 1000) };
|
|
313
243
|
if (!this.device.waterdetector?.hide_leak) {
|
|
314
|
-
if (this.LeakDetected === undefined) {
|
|
315
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakDetected}`);
|
|
244
|
+
if (this.LeakSensor.LeakDetected === undefined) {
|
|
245
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
316
246
|
}
|
|
317
247
|
else {
|
|
318
248
|
if (this.device.mqttURL) {
|
|
319
|
-
mqttmessage.push(`"LeakDetected": ${this.LeakDetected}`);
|
|
249
|
+
mqttmessage.push(`"LeakDetected": ${this.LeakSensor.LeakDetected}`);
|
|
320
250
|
}
|
|
321
251
|
if (this.device.history) {
|
|
322
|
-
entry['leak'] = this.LeakDetected;
|
|
252
|
+
entry['leak'] = this.LeakSensor.LeakDetected;
|
|
323
253
|
}
|
|
324
|
-
this.accessory.context.LeakDetected = this.LeakDetected;
|
|
325
|
-
this.
|
|
326
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LeakDetected: ${this.LeakDetected}`);
|
|
254
|
+
this.accessory.context.LeakDetected = this.LeakSensor.LeakDetected;
|
|
255
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.LeakSensor.LeakDetected);
|
|
256
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
327
257
|
}
|
|
328
258
|
}
|
|
329
|
-
if (this.BatteryLevel === undefined) {
|
|
330
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.BatteryLevel}`);
|
|
259
|
+
if (this.Battery.BatteryLevel === undefined) {
|
|
260
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
331
261
|
}
|
|
332
262
|
else {
|
|
333
263
|
if (this.device.mqttURL) {
|
|
334
|
-
mqttmessage.push(`"battery": ${this.BatteryLevel}`);
|
|
264
|
+
mqttmessage.push(`"battery": ${this.Battery.BatteryLevel}`);
|
|
335
265
|
}
|
|
336
|
-
this.accessory.context.BatteryLevel = this.BatteryLevel;
|
|
337
|
-
this.
|
|
338
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.BatteryLevel}`);
|
|
266
|
+
this.accessory.context.BatteryLevel = this.Battery.BatteryLevel;
|
|
267
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.Battery.BatteryLevel);
|
|
268
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
339
269
|
}
|
|
340
|
-
if (this.StatusLowBattery === undefined) {
|
|
341
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.StatusLowBattery}`);
|
|
270
|
+
if (this.Battery.StatusLowBattery === undefined) {
|
|
271
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
342
272
|
}
|
|
343
273
|
else {
|
|
344
274
|
if (this.device.mqttURL) {
|
|
345
|
-
mqttmessage.push(`"lowBattery": ${this.StatusLowBattery}`);
|
|
275
|
+
mqttmessage.push(`"lowBattery": ${this.Battery.StatusLowBattery}`);
|
|
346
276
|
}
|
|
347
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
348
|
-
this.
|
|
349
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic
|
|
277
|
+
this.accessory.context.StatusLowBattery = this.Battery.StatusLowBattery;
|
|
278
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.Battery.StatusLowBattery);
|
|
279
|
+
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic`
|
|
280
|
+
+ ` StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
350
281
|
}
|
|
351
282
|
if (this.device.mqttURL) {
|
|
352
283
|
this.mqttPublish(`{${mqttmessage.join(',')}}`);
|
|
353
284
|
}
|
|
354
|
-
if (
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
this.
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
/*
|
|
362
|
-
* Publish MQTT message for topics of
|
|
363
|
-
* 'homebridge-switchbot/meter/xx:xx:xx:xx:xx:xx'
|
|
364
|
-
*/
|
|
365
|
-
mqttPublish(message) {
|
|
366
|
-
const mac = this.device.deviceId
|
|
367
|
-
?.toLowerCase()
|
|
368
|
-
.match(/[\s\S]{1,2}/g)
|
|
369
|
-
?.join(':');
|
|
370
|
-
const options = this.device.mqttPubOptions || {};
|
|
371
|
-
this.mqttClient?.publish(`homebridge-switchbot/meter/${mac}`, `${message}`, options);
|
|
372
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT message: ${message} options:${JSON.stringify(options)}`);
|
|
373
|
-
}
|
|
374
|
-
/*
|
|
375
|
-
* Setup MQTT hadler if URL is specified.
|
|
376
|
-
*/
|
|
377
|
-
async setupMqtt(device) {
|
|
378
|
-
if (device.mqttURL) {
|
|
379
|
-
try {
|
|
380
|
-
const { connectAsync } = asyncmqtt;
|
|
381
|
-
this.mqttClient = await connectAsync(device.mqttURL, device.mqttOptions || {});
|
|
382
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} MQTT connection has been established successfully.`);
|
|
383
|
-
this.mqttClient.on('error', (e) => {
|
|
384
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to publish MQTT messages. ${e}`);
|
|
385
|
-
});
|
|
386
|
-
}
|
|
387
|
-
catch (e) {
|
|
388
|
-
this.mqttClient = null;
|
|
389
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Failed to establish MQTT connection. ${e}`);
|
|
285
|
+
if (!this.device.waterdetector?.hide_leak) {
|
|
286
|
+
if (Number(this.LeakSensor.LeakDetected) > 0) {
|
|
287
|
+
// reject unreliable data
|
|
288
|
+
if (this.device.history) {
|
|
289
|
+
this.historyService?.addEntry(entry);
|
|
290
|
+
}
|
|
390
291
|
}
|
|
391
292
|
}
|
|
392
293
|
}
|
|
393
|
-
/*
|
|
394
|
-
* Setup EVE history graph feature if enabled.
|
|
395
|
-
*/
|
|
396
|
-
async setupHistoryService(device) {
|
|
397
|
-
const mac = this.device
|
|
398
|
-
.deviceId.match(/.{1,2}/g)
|
|
399
|
-
.join(':')
|
|
400
|
-
.toLowerCase();
|
|
401
|
-
this.historyService = device.history
|
|
402
|
-
? new this.platform.fakegatoAPI('room', this.accessory, {
|
|
403
|
-
log: this.platform.log,
|
|
404
|
-
storage: 'fs',
|
|
405
|
-
filename: `${hostname().split('.')[0]}_${mac}_persist.json`,
|
|
406
|
-
})
|
|
407
|
-
: null;
|
|
408
|
-
}
|
|
409
|
-
async stopScanning(switchbot) {
|
|
410
|
-
switchbot.stopScan();
|
|
411
|
-
if (this.BLE_IsConnected) {
|
|
412
|
-
await this.BLEparseStatus();
|
|
413
|
-
await this.updateHomeKitCharacteristics();
|
|
414
|
-
}
|
|
415
|
-
else {
|
|
416
|
-
await this.BLERefreshConnection(switchbot);
|
|
417
|
-
}
|
|
418
|
-
}
|
|
419
|
-
async getCustomBLEAddress(switchbot) {
|
|
420
|
-
if (this.device.customBLEaddress && this.deviceLogging.includes('debug')) {
|
|
421
|
-
(async () => {
|
|
422
|
-
// Start to monitor advertisement packets
|
|
423
|
-
await switchbot.startScan({
|
|
424
|
-
model: 'i',
|
|
425
|
-
});
|
|
426
|
-
// Set an event handler
|
|
427
|
-
switchbot.onadvertisement = (ad) => {
|
|
428
|
-
this.warnLog(`${this.device.deviceType}: ${this.accessory.displayName} ad: ${JSON.stringify(ad, null, ' ')}`);
|
|
429
|
-
};
|
|
430
|
-
await sleep(10000);
|
|
431
|
-
// Stop to monitor
|
|
432
|
-
switchbot.stopScan();
|
|
433
|
-
})();
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
294
|
async BLERefreshConnection(switchbot) {
|
|
437
295
|
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} wasn't able to establish BLE Connection, node-switchbot:`
|
|
438
296
|
+ ` ${JSON.stringify(switchbot)}`);
|
|
@@ -441,231 +299,17 @@ export class WaterDetector {
|
|
|
441
299
|
await this.openAPIRefreshStatus();
|
|
442
300
|
}
|
|
443
301
|
}
|
|
444
|
-
async scan(device) {
|
|
445
|
-
if (device.scanDuration) {
|
|
446
|
-
this.scanDuration = this.accessory.context.scanDuration = device.scanDuration;
|
|
447
|
-
if (this.BLE) {
|
|
448
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config scanDuration: ${this.scanDuration}`);
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
else {
|
|
452
|
-
this.scanDuration = this.accessory.context.scanDuration = 1;
|
|
453
|
-
if (this.BLE) {
|
|
454
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Default scanDuration: ${this.scanDuration}`);
|
|
455
|
-
}
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
async statusCode(statusCode) {
|
|
459
|
-
switch (statusCode) {
|
|
460
|
-
case 151:
|
|
461
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command not supported by this deviceType, statusCode: ${statusCode}`);
|
|
462
|
-
break;
|
|
463
|
-
case 152:
|
|
464
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device not found, statusCode: ${statusCode}`);
|
|
465
|
-
break;
|
|
466
|
-
case 160:
|
|
467
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Command is not supported, statusCode: ${statusCode}`);
|
|
468
|
-
break;
|
|
469
|
-
case 161:
|
|
470
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device is offline, statusCode: ${statusCode}`);
|
|
471
|
-
this.offlineOff();
|
|
472
|
-
break;
|
|
473
|
-
case 171:
|
|
474
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Hub Device is offline, statusCode: ${statusCode}. ` +
|
|
475
|
-
`Hub: ${this.device.hubDeviceId}`);
|
|
476
|
-
this.offlineOff();
|
|
477
|
-
break;
|
|
478
|
-
case 190:
|
|
479
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Device internal error due to device states not synchronized with server,` +
|
|
480
|
-
` Or command format is invalid, statusCode: ${statusCode}`);
|
|
481
|
-
break;
|
|
482
|
-
case 100:
|
|
483
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Command successfully sent, statusCode: ${statusCode}`);
|
|
484
|
-
break;
|
|
485
|
-
case 200:
|
|
486
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Request successful, statusCode: ${statusCode}`);
|
|
487
|
-
break;
|
|
488
|
-
case 400:
|
|
489
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Bad Request, The client has issued an invalid request. `
|
|
490
|
-
+ `This is commonly used to specify validation errors in a request payload, statusCode: ${statusCode}`);
|
|
491
|
-
break;
|
|
492
|
-
case 401:
|
|
493
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unauthorized, Authorization for the API is required, `
|
|
494
|
-
+ `but the request has not been authenticated, statusCode: ${statusCode}`);
|
|
495
|
-
break;
|
|
496
|
-
case 403:
|
|
497
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Forbidden, The request has been authenticated but does not `
|
|
498
|
-
+ `have appropriate permissions, or a requested resource is not found, statusCode: ${statusCode}`);
|
|
499
|
-
break;
|
|
500
|
-
case 404:
|
|
501
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Found, Specifies the requested path does not exist, `
|
|
502
|
-
+ `statusCode: ${statusCode}`);
|
|
503
|
-
break;
|
|
504
|
-
case 406:
|
|
505
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Not Acceptable, The client has requested a MIME type via `
|
|
506
|
-
+ `the Accept header for a value not supported by the server, statusCode: ${statusCode}`);
|
|
507
|
-
break;
|
|
508
|
-
case 415:
|
|
509
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unsupported Media Type, The client has defined a contentType `
|
|
510
|
-
+ `header that is not supported by the server, statusCode: ${statusCode}`);
|
|
511
|
-
break;
|
|
512
|
-
case 422:
|
|
513
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Unprocessable Entity, The client has made a valid request, `
|
|
514
|
-
+ `but the server cannot process it. This is often used for APIs for which certain limits have been exceeded, statusCode: ${statusCode}`);
|
|
515
|
-
break;
|
|
516
|
-
case 429:
|
|
517
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Too Many Requests, The client has exceeded the number of `
|
|
518
|
-
+ `requests allowed for a given time window, statusCode: ${statusCode}`);
|
|
519
|
-
break;
|
|
520
|
-
case 500:
|
|
521
|
-
this.errorLog(`${this.device.deviceType}: ${this.accessory.displayName} Internal Server Error, An unexpected error on the SmartThings `
|
|
522
|
-
+ `servers has occurred. These errors should be rare, statusCode: ${statusCode}`);
|
|
523
|
-
break;
|
|
524
|
-
default:
|
|
525
|
-
this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} Unknown statusCode: ` +
|
|
526
|
-
`${statusCode}, Submit Bugs Here: ' + 'https://tinyurl.com/SwitchBotBug`);
|
|
527
|
-
}
|
|
528
|
-
}
|
|
529
302
|
async offlineOff() {
|
|
530
|
-
if (this.device.offline) {
|
|
531
|
-
|
|
532
|
-
await this.updateHomeKitCharacteristics();
|
|
303
|
+
if (this.device.offline && !this.device.waterdetector?.hide_leak) {
|
|
304
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.hap.Characteristic.LeakDetected.LEAK_NOT_DETECTED);
|
|
533
305
|
}
|
|
534
306
|
}
|
|
535
307
|
async apiError(e) {
|
|
536
308
|
if (!this.device.waterdetector?.hide_leak) {
|
|
537
|
-
this.
|
|
538
|
-
}
|
|
539
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
540
|
-
this.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
541
|
-
}
|
|
542
|
-
async deviceContext() {
|
|
543
|
-
if (this.LeakDetected === undefined) {
|
|
544
|
-
this.LeakDetected = 0;
|
|
545
|
-
}
|
|
546
|
-
else {
|
|
547
|
-
this.LeakDetected = this.accessory.context.LeakDetected;
|
|
548
|
-
}
|
|
549
|
-
if (this.BatteryLevel === undefined) {
|
|
550
|
-
this.BatteryLevel = 100;
|
|
551
|
-
}
|
|
552
|
-
else {
|
|
553
|
-
this.BatteryLevel = this.accessory.context.BatteryLevel;
|
|
554
|
-
}
|
|
555
|
-
if (this.StatusLowBattery === undefined) {
|
|
556
|
-
this.StatusLowBattery = this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
557
|
-
this.accessory.context.StatusLowBattery = this.StatusLowBattery;
|
|
558
|
-
}
|
|
559
|
-
else {
|
|
560
|
-
this.StatusLowBattery = this.accessory.context.StatusLowBattery;
|
|
561
|
-
}
|
|
562
|
-
if (this.FirmwareRevision === undefined) {
|
|
563
|
-
this.FirmwareRevision = this.platform.version;
|
|
564
|
-
this.accessory.context.FirmwareRevision = this.FirmwareRevision;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
async refreshRate(device) {
|
|
568
|
-
if (device.refreshRate) {
|
|
569
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = device.refreshRate;
|
|
570
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config refreshRate: ${this.deviceRefreshRate}`);
|
|
571
|
-
}
|
|
572
|
-
else if (this.platform.config.options.refreshRate) {
|
|
573
|
-
this.deviceRefreshRate = this.accessory.context.refreshRate = this.platform.config.options.refreshRate;
|
|
574
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config refreshRate: ${this.deviceRefreshRate}`);
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
async deviceConfig(device) {
|
|
578
|
-
let config = {};
|
|
579
|
-
if (device.waterdetector) {
|
|
580
|
-
config = device.waterdetector;
|
|
581
|
-
}
|
|
582
|
-
if (device.connectionType !== undefined) {
|
|
583
|
-
config['connectionType'] = device.connectionType;
|
|
584
|
-
}
|
|
585
|
-
if (device.external !== undefined) {
|
|
586
|
-
config['external'] = device.external;
|
|
587
|
-
}
|
|
588
|
-
if (device.mqttURL !== undefined) {
|
|
589
|
-
config['mqttURL'] = device.mqttURL;
|
|
590
|
-
}
|
|
591
|
-
if (device.logging !== undefined) {
|
|
592
|
-
config['logging'] = device.logging;
|
|
309
|
+
this.LeakSensor.Service.updateCharacteristic(this.hap.Characteristic.LeakDetected, e);
|
|
593
310
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
}
|
|
597
|
-
if (device.scanDuration !== undefined) {
|
|
598
|
-
config['scanDuration'] = device.scanDuration;
|
|
599
|
-
}
|
|
600
|
-
if (device.webhook !== undefined) {
|
|
601
|
-
config['webhook'] = device.webhook;
|
|
602
|
-
}
|
|
603
|
-
if (Object.entries(config).length !== 0) {
|
|
604
|
-
this.debugWarnLog(`${this.device.deviceType}: ${this.accessory.displayName} Config: ${JSON.stringify(config)}`);
|
|
605
|
-
}
|
|
606
|
-
}
|
|
607
|
-
async deviceLogs(device) {
|
|
608
|
-
if (this.platform.debugMode) {
|
|
609
|
-
this.deviceLogging = this.accessory.context.logging = 'debugMode';
|
|
610
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Debug Mode Logging: ${this.deviceLogging}`);
|
|
611
|
-
}
|
|
612
|
-
else if (device.logging) {
|
|
613
|
-
this.deviceLogging = this.accessory.context.logging = device.logging;
|
|
614
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Device Config Logging: ${this.deviceLogging}`);
|
|
615
|
-
}
|
|
616
|
-
else if (this.platform.config.options?.logging) {
|
|
617
|
-
this.deviceLogging = this.accessory.context.logging = this.platform.config.options?.logging;
|
|
618
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Using Platform Config Logging: ${this.deviceLogging}`);
|
|
619
|
-
}
|
|
620
|
-
else {
|
|
621
|
-
this.deviceLogging = this.accessory.context.logging = 'standard';
|
|
622
|
-
this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} Logging Not Set, Using: ${this.deviceLogging}`);
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
/**
|
|
626
|
-
* Logging for Device
|
|
627
|
-
*/
|
|
628
|
-
infoLog(...log) {
|
|
629
|
-
if (this.enablingDeviceLogging()) {
|
|
630
|
-
this.platform.log.info(String(...log));
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
warnLog(...log) {
|
|
634
|
-
if (this.enablingDeviceLogging()) {
|
|
635
|
-
this.platform.log.warn(String(...log));
|
|
636
|
-
}
|
|
637
|
-
}
|
|
638
|
-
debugWarnLog(...log) {
|
|
639
|
-
if (this.enablingDeviceLogging()) {
|
|
640
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
641
|
-
this.platform.log.warn('[DEBUG]', String(...log));
|
|
642
|
-
}
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
errorLog(...log) {
|
|
646
|
-
if (this.enablingDeviceLogging()) {
|
|
647
|
-
this.platform.log.error(String(...log));
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
debugErrorLog(...log) {
|
|
651
|
-
if (this.enablingDeviceLogging()) {
|
|
652
|
-
if (this.deviceLogging?.includes('debug')) {
|
|
653
|
-
this.platform.log.error('[DEBUG]', String(...log));
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
debugLog(...log) {
|
|
658
|
-
if (this.enablingDeviceLogging()) {
|
|
659
|
-
if (this.deviceLogging === 'debug') {
|
|
660
|
-
this.platform.log.info('[DEBUG]', String(...log));
|
|
661
|
-
}
|
|
662
|
-
else {
|
|
663
|
-
this.platform.log.debug(String(...log));
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
enablingDeviceLogging() {
|
|
668
|
-
return this.deviceLogging.includes('debug') || this.deviceLogging === 'standard';
|
|
311
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.BatteryLevel, e);
|
|
312
|
+
this.Battery.Service.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, e);
|
|
669
313
|
}
|
|
670
314
|
}
|
|
671
315
|
//# sourceMappingURL=waterdetector.js.map
|