@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.
Files changed (177) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +120 -17
  4. package/dist/device/blindtilt.d.ts +23 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +408 -779
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +26 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +696 -822
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +14 -68
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +237 -606
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +14 -75
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +280 -658
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +15 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +242 -544
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +19 -88
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +402 -805
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +59 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +684 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +51 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +535 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +16 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +246 -613
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +232 -593
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +11 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +185 -600
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +11 -69
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +277 -586
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +16 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +241 -560
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +14 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +181 -593
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +14 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +170 -593
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +13 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +178 -531
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +9 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +92 -458
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +12 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +197 -521
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +10 -65
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +139 -495
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +9 -49
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +309 -419
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +72 -304
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +34 -278
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +10 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +100 -338
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +40 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +330 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +87 -357
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +352 -546
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +82 -321
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +41 -284
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +42 -287
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +19 -6
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +310 -169
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +62 -19
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +77 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +638 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +19 -15
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +442 -814
  143. package/src/device/bot.ts +754 -915
  144. package/src/device/ceilinglight.ts +255 -633
  145. package/src/device/colorbulb.ts +295 -685
  146. package/src/device/contact.ts +277 -571
  147. package/src/device/curtain.ts +431 -835
  148. package/src/device/device.ts +709 -0
  149. package/src/device/fan.ts +591 -0
  150. package/src/device/hub.ts +286 -644
  151. package/src/device/humidifier.ts +266 -646
  152. package/src/device/iosensor.ts +220 -625
  153. package/src/device/lightstrip.ts +305 -620
  154. package/src/device/lock.ts +280 -600
  155. package/src/device/meter.ts +216 -617
  156. package/src/device/meterplus.ts +205 -619
  157. package/src/device/motion.ts +206 -556
  158. package/src/device/plug.ts +107 -490
  159. package/src/device/robotvacuumcleaner.ts +223 -550
  160. package/src/device/waterdetector.ts +160 -519
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +333 -447
  165. package/src/irdevice/airpurifier.ts +92 -322
  166. package/src/irdevice/camera.ts +45 -294
  167. package/src/irdevice/fan.ts +115 -353
  168. package/src/irdevice/irdevice.ts +346 -0
  169. package/src/irdevice/light.ts +110 -385
  170. package/src/irdevice/other.ts +399 -616
  171. package/src/irdevice/tv.ts +103 -340
  172. package/src/irdevice/vacuumcleaner.ts +52 -306
  173. package/src/irdevice/waterheater.ts +53 -311
  174. package/src/platform.ts +355 -216
  175. package/src/settings.ts +116 -611
  176. package/src/utils.ts +642 -1
  177. package/src/device/waterdetector.json +0 -11
@@ -1,135 +1,79 @@
1
- import { hostname } from 'os';
2
- import { request } from 'undici';
3
- import { sleep } from '../utils.js';
4
- import asyncmqtt from 'async-mqtt';
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
- leakService;
23
- batteryService;
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
- // Retrieve initial values and updateHomekit
79
- this.refreshStatus();
80
- // set accessory information
81
- accessory
82
- .getService(this.hap.Service.AccessoryInformation)
83
- .setCharacteristic(this.hap.Characteristic.Manufacturer, 'SwitchBot')
84
- .setCharacteristic(this.hap.Characteristic.Model, 'WoWaterDetector')
85
- .setCharacteristic(this.hap.Characteristic.SerialNumber, device.deviceId)
86
- .setCharacteristic(this.hap.Characteristic.FirmwareRevision, accessory.context.FirmwareRevision);
87
- // Leak Sensor Service
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.leakService = this.accessory.getService(this.hap.Service.LeakSensor);
91
- accessory.removeService(this.leakService);
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.debugLog(`${this.device.deviceType}: ${accessory.displayName} Temperature Sensor Service Not Added`);
114
- }
115
- // Humidity Sensor Service
116
- if (device.waterdetector?.hide_humidity) {
117
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Removing Humidity Sensor Service`);
118
- this.humidityservice = this.accessory.getService(this.hap.Service.HumiditySensor);
119
- accessory.removeService(this.humidityservice);
120
- }
121
- else {
122
- this.debugLog(`${this.device.deviceType}: ${accessory.displayName} Humidity Sensor Service Not Added`);
123
- }
124
- // Battery Service
125
- const batteryService = `${accessory.displayName} Battery`;
126
- (this.batteryService = this.accessory.getService(this.hap.Service.Battery)
127
- || accessory.addService(this.hap.Service.Battery)), batteryService;
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
- this.batteryService.setCharacteristic(this.hap.Characteristic.ChargingState, this.hap.Characteristic.ChargingState.NOT_CHARGEABLE);
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.webhook) {
143
- this.infoLog(`${this.device.deviceType}: ${this.accessory.displayName} is listening webhook.`);
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 { status } = context;
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
- '(status) = ' +
151
- `Webhook:(${status}), ` +
152
- `current:(${LeakDetected})`);
153
- this.LeakDetected = status;
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(this.BLE_BatteryLevel);
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.LeakDetected = this.BLE_LeakDetected;
194
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakDetected}%`);
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(this.OpenAPI_BatteryLevel);
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.LeakDetected = this.OpenAPI_LeakDetected;
214
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} LeakDetected: ${this.LeakDetected}%`);
215
- // FirmwareRevision
216
- this.FirmwareRevision = this.OpenAPI_FirmwareRevision;
217
- this.accessory.context.FirmwareRevision = this.FirmwareRevision;
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
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} ${JSON.stringify(ad, null, ' ')}`);
258
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} address: ${ad.address}, model: ${ad.serviceData.model}`);
259
- if (this.device.bleMac === ad.address && ad.serviceData.model === 'l') {
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 1 seconds
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 request(`${Devices}/${this.device.deviceId}/status`, {
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.debugErrorLog(`${this.device.deviceType}: ${this.accessory.displayName} `
221
+ this.debugSuccessLog(`${this.device.deviceType}: ${this.accessory.displayName} `
289
222
  + `statusCode: ${statusCode} & deviceStatus StatusCode: ${deviceStatus.statusCode}`);
290
- this.OpenAPI_LeakDetected = deviceStatus.body.status;
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.leakService?.updateCharacteristic(this.hap.Characteristic.LeakDetected, this.LeakDetected);
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.batteryService?.updateCharacteristic(this.hap.Characteristic.BatteryLevel, this.BatteryLevel);
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.batteryService?.updateCharacteristic(this.hap.Characteristic.StatusLowBattery, this.StatusLowBattery);
349
- this.debugLog(`${this.device.deviceType}: ${this.accessory.displayName} updateCharacteristic StatusLowBattery: ${this.StatusLowBattery}`);
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 (Number(this.LeakDetected) > 0) {
355
- // reject unreliable data
356
- if (this.device.history) {
357
- this.historyService?.addEntry(entry);
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
- await this.deviceContext();
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.leakService?.updateCharacteristic(this.hap.Characteristic.LeakDetected, e);
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
- if (device.refreshRate !== undefined) {
595
- config['refreshRate'] = device.refreshRate;
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