@switchbot/homebridge-switchbot 3.5.1-beta.9 → 3.5.2-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/config.schema.json +19 -3
- package/dist/device/blindtilt.d.ts +6 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +61 -47
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +6 -3
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +60 -26
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +6 -3
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +48 -30
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +6 -3
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +54 -37
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +6 -3
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +46 -32
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +6 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +42 -28
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +7 -4
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +61 -152
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +6 -3
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +54 -33
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +6 -3
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +50 -31
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +6 -3
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +48 -29
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +6 -3
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +45 -28
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +6 -3
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +47 -29
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +6 -3
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +39 -26
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +6 -3
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +44 -28
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +6 -3
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +43 -28
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +6 -3
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +38 -25
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +6 -3
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +31 -18
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +6 -3
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +38 -23
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +6 -3
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +44 -27
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/homebridge-ui/public/index.html +2 -2
- package/dist/irdevice/airconditioner.d.ts +1 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +67 -177
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +0 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +24 -53
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +12 -17
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +22 -38
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +22 -10
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +94 -100
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +20 -38
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +79 -77
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +38 -53
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +11 -16
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +11 -16
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +4 -6
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +564 -665
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +10 -8
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/types/bledevicestatus.d.ts +2 -1
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/package.json +14 -14
- package/src/device/blindtilt.ts +65 -49
- package/src/device/bot.ts +80 -27
- package/src/device/ceilinglight.ts +58 -32
- package/src/device/colorbulb.ts +58 -44
- package/src/device/contact.ts +50 -32
- package/src/device/curtain.ts +52 -29
- package/src/device/device.ts +63 -135
- package/src/device/fan.ts +68 -34
- package/src/device/hub.ts +63 -34
- package/src/device/humidifier.ts +61 -34
- package/src/device/iosensor.ts +52 -31
- package/src/device/lightstrip.ts +53 -30
- package/src/device/lock.ts +56 -27
- package/src/device/meter.ts +61 -30
- package/src/device/meterplus.ts +57 -30
- package/src/device/motion.ts +51 -27
- package/src/device/plug.ts +39 -19
- package/src/device/robotvacuumcleaner.ts +54 -25
- package/src/device/waterdetector.ts +63 -29
- package/src/homebridge-ui/public/index.html +2 -2
- package/src/irdevice/airconditioner.ts +76 -165
- package/src/irdevice/airpurifier.ts +29 -49
- package/src/irdevice/camera.ts +13 -16
- package/src/irdevice/fan.ts +25 -35
- package/src/irdevice/irdevice.ts +97 -96
- package/src/irdevice/light.ts +21 -35
- package/src/irdevice/other.ts +79 -77
- package/src/irdevice/tv.ts +40 -51
- package/src/irdevice/vacuumcleaner.ts +12 -15
- package/src/irdevice/waterheater.ts +12 -15
- package/src/platform.ts +566 -696
- package/src/settings.ts +11 -8
- package/src/types/bledevicestatus.ts +4 -2
- package/src/types/devicestatus.ts +1 -1
|
@@ -36,6 +36,15 @@ export class WaterDetector extends deviceBase {
|
|
|
36
36
|
LeakDetected: CharacteristicValue;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
// OpenAPI
|
|
40
|
+
deviceStatus!: waterLeakDetectorStatus;
|
|
41
|
+
|
|
42
|
+
//Webhook
|
|
43
|
+
webhookContext!: waterLeakDetectorWebhookContext;
|
|
44
|
+
|
|
45
|
+
// BLE
|
|
46
|
+
serviceData!: waterLeakDetectorServiceData;
|
|
47
|
+
|
|
39
48
|
// Updates
|
|
40
49
|
WaterDetectorUpdateInProgress!: boolean;
|
|
41
50
|
doWaterDetectorUpdate: Subject<void>;
|
|
@@ -46,6 +55,9 @@ export class WaterDetector extends deviceBase {
|
|
|
46
55
|
device: device & devicesConfig,
|
|
47
56
|
) {
|
|
48
57
|
super(platform, accessory, device);
|
|
58
|
+
// Set category
|
|
59
|
+
accessory.category = this.hap.Categories.SENSOR;
|
|
60
|
+
|
|
49
61
|
// this is subject we use to track when we need to POST changes to the SwitchBot API
|
|
50
62
|
this.doWaterDetectorUpdate = new Subject();
|
|
51
63
|
this.WaterDetectorUpdateInProgress = false;
|
|
@@ -79,11 +91,11 @@ export class WaterDetector extends deviceBase {
|
|
|
79
91
|
// Initialize Leak Sensor Service
|
|
80
92
|
if (device.waterdetector?.hide_leak) {
|
|
81
93
|
if (this.LeakSensor) {
|
|
82
|
-
this.debugLog(
|
|
94
|
+
this.debugLog('Removing Leak Sensor Service');
|
|
83
95
|
this.LeakSensor.Service = this.accessory.getService(this.hap.Service.LeakSensor) as Service;
|
|
84
96
|
accessory.removeService(this.LeakSensor.Service);
|
|
85
97
|
} else {
|
|
86
|
-
this.debugLog(
|
|
98
|
+
this.debugLog('Leak Sensor Service Not Found');
|
|
87
99
|
}
|
|
88
100
|
} else {
|
|
89
101
|
accessory.context.LeakSensor = accessory.context.LeakSensor ?? {};
|
|
@@ -106,13 +118,11 @@ export class WaterDetector extends deviceBase {
|
|
|
106
118
|
}
|
|
107
119
|
|
|
108
120
|
// Retrieve initial values and updateHomekit
|
|
109
|
-
this.debugLog('
|
|
121
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
110
122
|
this.refreshStatus();
|
|
111
123
|
|
|
112
|
-
// Retrieve initial values and updateHomekit
|
|
113
|
-
this.updateHomeKitCharacteristics();
|
|
114
|
-
|
|
115
124
|
//regisiter webhook event handler
|
|
125
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
116
126
|
this.registerWebhook();
|
|
117
127
|
|
|
118
128
|
// Start an update interval
|
|
@@ -124,18 +134,24 @@ export class WaterDetector extends deviceBase {
|
|
|
124
134
|
});
|
|
125
135
|
}
|
|
126
136
|
|
|
127
|
-
async BLEparseStatus(
|
|
137
|
+
async BLEparseStatus(): Promise<void> {
|
|
128
138
|
await this.debugLog('BLEparseStatus');
|
|
139
|
+
await this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}),`
|
|
140
|
+
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
141
|
+
|
|
142
|
+
//LeakSensor
|
|
129
143
|
if (this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
144
|
+
|
|
130
145
|
// StatusActive
|
|
131
|
-
this.LeakSensor.StatusActive = serviceData.state;
|
|
146
|
+
this.LeakSensor.StatusActive = this.serviceData.state;
|
|
132
147
|
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
148
|
+
|
|
133
149
|
// LeakDetected
|
|
134
|
-
this.LeakSensor.LeakDetected = serviceData.status;
|
|
150
|
+
this.LeakSensor.LeakDetected = this.serviceData.status;
|
|
135
151
|
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
136
152
|
}
|
|
137
153
|
// BatteryLevel
|
|
138
|
-
this.Battery.BatteryLevel =
|
|
154
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
139
155
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
140
156
|
// StatusLowBattery
|
|
141
157
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
@@ -143,27 +159,36 @@ export class WaterDetector extends deviceBase {
|
|
|
143
159
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
144
160
|
}
|
|
145
161
|
|
|
146
|
-
async openAPIparseStatus(
|
|
162
|
+
async openAPIparseStatus(): Promise<void> {
|
|
147
163
|
await this.debugLog('openAPIparseStatus');
|
|
164
|
+
await this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}),`
|
|
165
|
+
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
166
|
+
|
|
167
|
+
//LeakSensor
|
|
148
168
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
169
|
+
|
|
149
170
|
// StatusActive
|
|
150
|
-
this.LeakSensor.StatusActive = deviceStatus.battery === 0 ? false : true;
|
|
171
|
+
this.LeakSensor.StatusActive = this.deviceStatus.battery === 0 ? false : true;
|
|
151
172
|
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
173
|
+
|
|
152
174
|
// LeakDetected
|
|
153
|
-
this.LeakSensor.LeakDetected = deviceStatus.status;
|
|
175
|
+
this.LeakSensor.LeakDetected = this.deviceStatus.status;
|
|
154
176
|
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
155
177
|
}
|
|
178
|
+
|
|
156
179
|
// BatteryLevel
|
|
157
|
-
this.Battery.BatteryLevel =
|
|
180
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
158
181
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
182
|
+
|
|
159
183
|
// StatusLowBattery
|
|
160
184
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
161
185
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
162
186
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
187
|
+
|
|
163
188
|
// FirmwareVersion
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
189
|
+
if (this.deviceStatus.version) {
|
|
190
|
+
const version = this.deviceStatus.version.toString();
|
|
191
|
+
await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`);
|
|
167
192
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
168
193
|
this.accessory
|
|
169
194
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -171,26 +196,32 @@ export class WaterDetector extends deviceBase {
|
|
|
171
196
|
.setCharacteristic(this.hap.Characteristic.FirmwareRevision, deviceVersion)
|
|
172
197
|
.getCharacteristic(this.hap.Characteristic.FirmwareRevision)
|
|
173
198
|
.updateValue(deviceVersion);
|
|
174
|
-
this.accessory.context.
|
|
175
|
-
await this.debugSuccessLog(`
|
|
199
|
+
this.accessory.context.version = deviceVersion;
|
|
200
|
+
await this.debugSuccessLog(`version: ${this.accessory.context.version}`);
|
|
176
201
|
}
|
|
177
202
|
}
|
|
178
203
|
|
|
179
|
-
async parseStatusWebhook(
|
|
204
|
+
async parseStatusWebhook(): Promise<void> {
|
|
180
205
|
await this.debugLog('parseStatusWebhook');
|
|
181
|
-
await this.debugLog(`(detectionState, battery) = Webhook: (${
|
|
206
|
+
await this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}),`
|
|
182
207
|
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
208
|
+
|
|
209
|
+
//LeakSensor
|
|
183
210
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
211
|
+
|
|
184
212
|
// StatusActive
|
|
185
|
-
this.LeakSensor.StatusActive =
|
|
213
|
+
this.LeakSensor.StatusActive = this.webhookContext.detectionState ? true : false;
|
|
186
214
|
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
215
|
+
|
|
187
216
|
// LeakDetected
|
|
188
|
-
this.LeakSensor.LeakDetected =
|
|
217
|
+
this.LeakSensor.LeakDetected = this.webhookContext.detectionState;
|
|
189
218
|
await this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
190
219
|
}
|
|
220
|
+
|
|
191
221
|
// BatteryLevel
|
|
192
|
-
this.Battery.BatteryLevel =
|
|
222
|
+
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
193
223
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
224
|
+
|
|
194
225
|
// StatusLowBattery
|
|
195
226
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
196
227
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
@@ -223,10 +254,11 @@ export class WaterDetector extends deviceBase {
|
|
|
223
254
|
// Start to monitor advertisement packets
|
|
224
255
|
(async () => {
|
|
225
256
|
// Start to monitor advertisement packets
|
|
226
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as
|
|
257
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
|
|
227
258
|
// Update HomeKit
|
|
228
259
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
229
|
-
|
|
260
|
+
this.serviceData = serviceData;
|
|
261
|
+
await this.BLEparseStatus();
|
|
230
262
|
await this.updateHomeKitCharacteristics();
|
|
231
263
|
} else {
|
|
232
264
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -244,7 +276,8 @@ export class WaterDetector extends deviceBase {
|
|
|
244
276
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
245
277
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
246
278
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
247
|
-
|
|
279
|
+
this.deviceStatus = deviceStatus.body;
|
|
280
|
+
await this.openAPIparseStatus();
|
|
248
281
|
await this.updateHomeKitCharacteristics();
|
|
249
282
|
} else {
|
|
250
283
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -262,7 +295,8 @@ export class WaterDetector extends deviceBase {
|
|
|
262
295
|
this.platform.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
|
|
263
296
|
try {
|
|
264
297
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
265
|
-
|
|
298
|
+
this.webhookContext = context;
|
|
299
|
+
await this.parseStatusWebhook();
|
|
266
300
|
await this.updateHomeKitCharacteristics();
|
|
267
301
|
} catch (e: any) {
|
|
268
302
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -294,7 +328,7 @@ export class WaterDetector extends deviceBase {
|
|
|
294
328
|
}
|
|
295
329
|
|
|
296
330
|
async BLERefreshConnection(switchbot: any): Promise<void> {
|
|
297
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
331
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${switchbot}`);
|
|
298
332
|
if (this.platform.config.credentials?.token && this.device.connectionType === 'BLE/OpenAPI') {
|
|
299
333
|
await this.warnLog('Using OpenAPI Connection to Refresh Status');
|
|
300
334
|
await this.openAPIRefreshStatus();
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
<tbody>
|
|
52
52
|
<tr>
|
|
53
53
|
<th scope="row">Device ID</th>
|
|
54
|
-
<td id="
|
|
54
|
+
<td id="deviceId"></td>
|
|
55
55
|
</tr>
|
|
56
56
|
<tr>
|
|
57
57
|
<th scope="row">Model</th>
|
|
@@ -166,7 +166,7 @@
|
|
|
166
166
|
const thisAcc = cachedAccessories.find((x) => x.UUID === UUID);
|
|
167
167
|
const context = thisAcc.context;
|
|
168
168
|
document.getElementById('displayName').innerHTML = thisAcc.displayName;
|
|
169
|
-
document.getElementById('
|
|
169
|
+
document.getElementById('deviceId').innerHTML = context.deviceId;
|
|
170
170
|
document.getElementById('model').innerHTML = context.model;
|
|
171
171
|
document.getElementById('version').innerHTML = context.version;
|
|
172
172
|
document.getElementById('deviceType').innerHTML = context.deviceType;
|