@switchbot/homebridge-switchbot 3.5.1-beta.11 → 3.5.1-beta.13
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/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 +57 -45
- 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 +38 -24
- 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 +44 -27
- 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 +47 -32
- 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 +40 -28
- 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 +35 -22
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +13 -2
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +223 -108
- 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 +48 -29
- 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 +43 -26
- 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 +43 -26
- 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 +39 -24
- 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 +43 -27
- 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 +33 -22
- 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 +38 -24
- 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 +37 -24
- 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 +33 -22
- 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 +27 -16
- 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 +34 -21
- 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 +38 -23
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -3
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +32 -138
- 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 +13 -44
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +3 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +7 -25
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +1 -1
- package/dist/irdevice/irdevice.js +5 -5
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -27
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.js +1 -1
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +3 -18
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +2 -9
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +2 -9
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +0 -11
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +11 -184
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +9 -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 +9 -9
- package/src/device/blindtilt.ts +60 -47
- package/src/device/bot.ts +47 -25
- package/src/device/ceilinglight.ts +53 -27
- package/src/device/colorbulb.ts +50 -39
- package/src/device/contact.ts +43 -28
- package/src/device/curtain.ts +45 -23
- package/src/device/device.ts +226 -96
- package/src/device/fan.ts +61 -30
- package/src/device/hub.ts +55 -29
- package/src/device/humidifier.ts +55 -31
- package/src/device/iosensor.ts +45 -27
- package/src/device/lightstrip.ts +48 -28
- package/src/device/lock.ts +49 -23
- package/src/device/meter.ts +54 -26
- package/src/device/meterplus.ts +50 -26
- package/src/device/motion.ts +45 -24
- package/src/device/plug.ts +34 -17
- package/src/device/robotvacuumcleaner.ts +49 -23
- package/src/device/waterdetector.ts +56 -25
- package/src/irdevice/airconditioner.ts +41 -125
- package/src/irdevice/airpurifier.ts +18 -40
- package/src/irdevice/camera.ts +4 -9
- package/src/irdevice/fan.ts +10 -22
- package/src/irdevice/irdevice.ts +5 -5
- package/src/irdevice/light.ts +10 -24
- package/src/irdevice/other.ts +1 -1
- package/src/irdevice/tv.ts +5 -16
- package/src/irdevice/vacuumcleaner.ts +3 -8
- package/src/irdevice/waterheater.ts +3 -8
- package/src/platform.ts +11 -184
- package/src/settings.ts +10 -8
- package/src/types/bledevicestatus.ts +4 -2
- package/src/types/devicestatus.ts +1 -1
|
@@ -35,6 +35,15 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
35
35
|
ChargingState: CharacteristicValue;
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// OpenAPI
|
|
39
|
+
deviceStatus!: robotVacuumCleanerS1Status | robotVacuumCleanerS1PlusStatus | floorCleaningRobotS10Status;
|
|
40
|
+
|
|
41
|
+
//Webhook
|
|
42
|
+
webhookContext!: robotVacuumCleanerS1WebhookContext | robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext;
|
|
43
|
+
|
|
44
|
+
// BLE
|
|
45
|
+
serviceData!: robotVacuumCleanerServiceData;
|
|
46
|
+
|
|
38
47
|
// Updates
|
|
39
48
|
robotVacuumCleanerUpdateInProgress!: boolean;
|
|
40
49
|
doRobotVacuumCleanerUpdate!: Subject<void>;
|
|
@@ -115,12 +124,11 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
115
124
|
});
|
|
116
125
|
|
|
117
126
|
// Retrieve initial values and updateHomekit
|
|
127
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
118
128
|
this.refreshStatus();
|
|
119
129
|
|
|
120
|
-
// Update Homekit
|
|
121
|
-
this.updateHomeKitCharacteristics();
|
|
122
|
-
|
|
123
130
|
//regisiter webhook event handler
|
|
131
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
124
132
|
this.registerWebhook();
|
|
125
133
|
|
|
126
134
|
// Start an update interval
|
|
@@ -150,39 +158,51 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
150
158
|
});
|
|
151
159
|
}
|
|
152
160
|
|
|
153
|
-
async BLEparseStatus(
|
|
161
|
+
async BLEparseStatus(): Promise<void> {
|
|
154
162
|
await this.debugLog('BLEparseStatus');
|
|
163
|
+
await this.debugLog(`(state, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.battery}),`
|
|
164
|
+
+ ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel})`);
|
|
165
|
+
|
|
155
166
|
// On
|
|
156
|
-
this.LightBulb.On = serviceData.state === 'on' ? true : false;
|
|
167
|
+
this.LightBulb.On = this.serviceData.state === 'on' ? true : false;
|
|
157
168
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
169
|
+
|
|
158
170
|
// BatteryLevel
|
|
159
|
-
this.Battery.BatteryLevel =
|
|
171
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
160
172
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
173
|
+
|
|
161
174
|
// StatusLowBattery
|
|
162
175
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
163
176
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
164
177
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
165
178
|
}
|
|
166
179
|
|
|
167
|
-
async openAPIparseStatus(
|
|
180
|
+
async openAPIparseStatus() {
|
|
168
181
|
await this.debugLog('openAPIparseStatus');
|
|
182
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = API: (${this.deviceStatus.onlineStatus}, ${this.deviceStatus.battery},`
|
|
183
|
+
+ ` ${this.deviceStatus.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
184
|
+
|
|
169
185
|
// On
|
|
170
|
-
this.LightBulb.On = deviceStatus.onlineStatus === 'online' ? true : false;
|
|
186
|
+
this.LightBulb.On = this.deviceStatus.onlineStatus === 'online' ? true : false;
|
|
171
187
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
188
|
+
|
|
172
189
|
// BatteryLevel
|
|
173
|
-
this.Battery.BatteryLevel =
|
|
190
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
174
191
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
192
|
+
|
|
175
193
|
// StatusLowBattery
|
|
176
194
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
177
195
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
178
196
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
197
|
+
|
|
179
198
|
// ChargingState
|
|
180
|
-
this.Battery.ChargingState = deviceStatus.workingStatus === 'Charging'
|
|
199
|
+
this.Battery.ChargingState = this.deviceStatus.workingStatus === 'Charging'
|
|
181
200
|
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
182
201
|
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
202
|
+
|
|
183
203
|
// Firmware Version
|
|
184
|
-
if (deviceStatus.version) {
|
|
185
|
-
const version = deviceStatus.version.toString();
|
|
204
|
+
if (this.deviceStatus.version) {
|
|
205
|
+
const version = this.deviceStatus.version.toString();
|
|
186
206
|
await this.debugLog(`Firmware Version: ${version.replace(/^V|-.*$/g, '')}`);
|
|
187
207
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
188
208
|
this.accessory
|
|
@@ -196,23 +216,26 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
196
216
|
}
|
|
197
217
|
}
|
|
198
218
|
|
|
199
|
-
async parseStatusWebhook(
|
|
200
|
-
| floorCleaningRobotS10WebhookContext): Promise<void> {
|
|
219
|
+
async parseStatusWebhook(): Promise<void> {
|
|
201
220
|
await this.debugLog('parseStatusWebhook');
|
|
202
|
-
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${
|
|
203
|
-
+ ` current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
221
|
+
await this.debugLog(`(onlineStatus, battery, workingStatus) = Webhook: (${this.webhookContext.onlineStatus}, ${this.webhookContext.battery},`
|
|
222
|
+
+ ` ${this.webhookContext.workingStatus}), current: (${this.LightBulb.On}, ${this.Battery.BatteryLevel}, ${this.Battery.ChargingState})`);
|
|
223
|
+
|
|
204
224
|
// On
|
|
205
|
-
this.LightBulb.On =
|
|
225
|
+
this.LightBulb.On = this.webhookContext.onlineStatus === 'online' ? true : false;
|
|
206
226
|
await this.debugLog(`On: ${this.LightBulb.On}`);
|
|
227
|
+
|
|
207
228
|
// BatteryLevel
|
|
208
|
-
this.Battery.BatteryLevel =
|
|
229
|
+
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
209
230
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
231
|
+
|
|
210
232
|
// StatusLowBattery
|
|
211
233
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
212
234
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
213
235
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
236
|
+
|
|
214
237
|
// ChargingState
|
|
215
|
-
this.Battery.ChargingState =
|
|
238
|
+
this.Battery.ChargingState = this.webhookContext.workingStatus === 'Charging'
|
|
216
239
|
? this.hap.Characteristic.ChargingState.CHARGING : this.hap.Characteristic.ChargingState.NOT_CHARGING;
|
|
217
240
|
await this.debugLog(`ChargingState: ${this.Battery.ChargingState}`);
|
|
218
241
|
}
|
|
@@ -246,7 +269,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
246
269
|
const serviceData = await this.monitorAdvertisementPackets(switchbot) as unknown as robotVacuumCleanerServiceData;
|
|
247
270
|
// Update HomeKit
|
|
248
271
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
249
|
-
|
|
272
|
+
this.serviceData = serviceData;
|
|
273
|
+
await this.BLEparseStatus();
|
|
250
274
|
await this.updateHomeKitCharacteristics();
|
|
251
275
|
} else {
|
|
252
276
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -264,7 +288,8 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
264
288
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
265
289
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
266
290
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
267
|
-
|
|
291
|
+
this.deviceStatus = deviceStatus.body;
|
|
292
|
+
await this.openAPIparseStatus();
|
|
268
293
|
await this.updateHomeKitCharacteristics();
|
|
269
294
|
} else {
|
|
270
295
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -279,11 +304,12 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
279
304
|
async registerWebhook() {
|
|
280
305
|
if (this.device.webhook) {
|
|
281
306
|
await this.debugLog('is listening webhook.');
|
|
282
|
-
this.
|
|
307
|
+
this.webhookEventHandler[this.device.deviceId] = async (context: robotVacuumCleanerS1WebhookContext
|
|
283
308
|
| robotVacuumCleanerS1PlusWebhookContext | floorCleaningRobotS10WebhookContext) => {
|
|
284
309
|
try {
|
|
285
310
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
286
|
-
|
|
311
|
+
this.webhookContext = context;
|
|
312
|
+
await this.parseStatusWebhook();
|
|
287
313
|
await this.updateHomeKitCharacteristics();
|
|
288
314
|
} catch (e: any) {
|
|
289
315
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -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>;
|
|
@@ -106,13 +115,11 @@ export class WaterDetector extends deviceBase {
|
|
|
106
115
|
}
|
|
107
116
|
|
|
108
117
|
// Retrieve initial values and updateHomekit
|
|
109
|
-
this.debugLog('
|
|
118
|
+
this.debugLog('Retrieve initial values and update Homekit');
|
|
110
119
|
this.refreshStatus();
|
|
111
120
|
|
|
112
|
-
// Retrieve initial values and updateHomekit
|
|
113
|
-
// this.updateHomeKitCharacteristics();
|
|
114
|
-
|
|
115
121
|
//regisiter webhook event handler
|
|
122
|
+
this.debugLog('Registering Webhook Event Handler');
|
|
116
123
|
this.registerWebhook();
|
|
117
124
|
|
|
118
125
|
// Start an update interval
|
|
@@ -124,18 +131,24 @@ export class WaterDetector extends deviceBase {
|
|
|
124
131
|
});
|
|
125
132
|
}
|
|
126
133
|
|
|
127
|
-
async BLEparseStatus(
|
|
134
|
+
async BLEparseStatus(): Promise<void> {
|
|
128
135
|
await this.debugLog('BLEparseStatus');
|
|
136
|
+
await this.debugLog(`(state, status, battery) = BLE: (${this.serviceData.state}, ${this.serviceData.status}, ${this.serviceData.battery}),`
|
|
137
|
+
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
138
|
+
|
|
139
|
+
//LeakSensor
|
|
129
140
|
if (this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
141
|
+
|
|
130
142
|
// StatusActive
|
|
131
|
-
this.LeakSensor.StatusActive = serviceData.state;
|
|
143
|
+
this.LeakSensor.StatusActive = this.serviceData.state;
|
|
132
144
|
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
145
|
+
|
|
133
146
|
// LeakDetected
|
|
134
|
-
this.LeakSensor.LeakDetected = serviceData.status;
|
|
147
|
+
this.LeakSensor.LeakDetected = this.serviceData.status;
|
|
135
148
|
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
136
149
|
}
|
|
137
150
|
// BatteryLevel
|
|
138
|
-
this.Battery.BatteryLevel =
|
|
151
|
+
this.Battery.BatteryLevel = this.serviceData.battery;
|
|
139
152
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
140
153
|
// StatusLowBattery
|
|
141
154
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
@@ -143,27 +156,36 @@ export class WaterDetector extends deviceBase {
|
|
|
143
156
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
144
157
|
}
|
|
145
158
|
|
|
146
|
-
async openAPIparseStatus(
|
|
159
|
+
async openAPIparseStatus(): Promise<void> {
|
|
147
160
|
await this.debugLog('openAPIparseStatus');
|
|
161
|
+
await this.debugLog(`(status, battery) = OpenAPI: (${this.deviceStatus.status}, ${this.deviceStatus.battery}),`
|
|
162
|
+
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
163
|
+
|
|
164
|
+
//LeakSensor
|
|
148
165
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
166
|
+
|
|
149
167
|
// StatusActive
|
|
150
|
-
this.LeakSensor.StatusActive = deviceStatus.battery === 0 ? false : true;
|
|
168
|
+
this.LeakSensor.StatusActive = this.deviceStatus.battery === 0 ? false : true;
|
|
151
169
|
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
170
|
+
|
|
152
171
|
// LeakDetected
|
|
153
|
-
this.LeakSensor.LeakDetected = deviceStatus.status;
|
|
172
|
+
this.LeakSensor.LeakDetected = this.deviceStatus.status;
|
|
154
173
|
this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
155
174
|
}
|
|
175
|
+
|
|
156
176
|
// BatteryLevel
|
|
157
|
-
this.Battery.BatteryLevel =
|
|
177
|
+
this.Battery.BatteryLevel = this.deviceStatus.battery;
|
|
158
178
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
179
|
+
|
|
159
180
|
// StatusLowBattery
|
|
160
181
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
161
182
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
162
183
|
await this.debugLog(`StatusLowBattery: ${this.Battery.StatusLowBattery}`);
|
|
184
|
+
|
|
163
185
|
// FirmwareVersion
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
186
|
+
if (this.deviceStatus.version) {
|
|
187
|
+
const version = this.deviceStatus.version.toString();
|
|
188
|
+
await this.debugLog(`FirmwareVersion: ${version.replace(/^V|-.*$/g, '')}`);
|
|
167
189
|
const deviceVersion = version.replace(/^V|-.*$/g, '') ?? '0.0.0';
|
|
168
190
|
this.accessory
|
|
169
191
|
.getService(this.hap.Service.AccessoryInformation)!
|
|
@@ -176,21 +198,27 @@ export class WaterDetector extends deviceBase {
|
|
|
176
198
|
}
|
|
177
199
|
}
|
|
178
200
|
|
|
179
|
-
async parseStatusWebhook(
|
|
201
|
+
async parseStatusWebhook(): Promise<void> {
|
|
180
202
|
await this.debugLog('parseStatusWebhook');
|
|
181
|
-
await this.debugLog(`(detectionState, battery) = Webhook: (${
|
|
203
|
+
await this.debugLog(`(detectionState, battery) = Webhook: (${this.webhookContext.detectionState}, ${this.webhookContext.battery}),`
|
|
182
204
|
+ ` current:(${this.LeakSensor?.LeakDetected}, ${this.Battery.BatteryLevel})`);
|
|
205
|
+
|
|
206
|
+
//LeakSensor
|
|
183
207
|
if (!this.device.waterdetector?.hide_leak && this.LeakSensor?.Service) {
|
|
208
|
+
|
|
184
209
|
// StatusActive
|
|
185
|
-
this.LeakSensor.StatusActive =
|
|
210
|
+
this.LeakSensor.StatusActive = this.webhookContext.detectionState ? true : false;
|
|
186
211
|
await this.debugLog(`StatusActive: ${this.LeakSensor.StatusActive}`);
|
|
212
|
+
|
|
187
213
|
// LeakDetected
|
|
188
|
-
this.LeakSensor.LeakDetected =
|
|
214
|
+
this.LeakSensor.LeakDetected = this.webhookContext.detectionState;
|
|
189
215
|
await this.debugLog(`LeakDetected: ${this.LeakSensor.LeakDetected}`);
|
|
190
216
|
}
|
|
217
|
+
|
|
191
218
|
// BatteryLevel
|
|
192
|
-
this.Battery.BatteryLevel =
|
|
219
|
+
this.Battery.BatteryLevel = this.webhookContext.battery;
|
|
193
220
|
await this.debugLog(`BatteryLevel: ${this.Battery.BatteryLevel}`);
|
|
221
|
+
|
|
194
222
|
// StatusLowBattery
|
|
195
223
|
this.Battery.StatusLowBattery = this.Battery.BatteryLevel < 10
|
|
196
224
|
? this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW : this.hap.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL;
|
|
@@ -223,10 +251,11 @@ export class WaterDetector extends deviceBase {
|
|
|
223
251
|
// Start to monitor advertisement packets
|
|
224
252
|
(async () => {
|
|
225
253
|
// Start to monitor advertisement packets
|
|
226
|
-
const serviceData = await this.monitorAdvertisementPackets(switchbot) as
|
|
254
|
+
const serviceData = await this.monitorAdvertisementPackets(switchbot) as waterLeakDetectorServiceData;
|
|
227
255
|
// Update HomeKit
|
|
228
256
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
229
|
-
|
|
257
|
+
this.serviceData = serviceData;
|
|
258
|
+
await this.BLEparseStatus();
|
|
230
259
|
await this.updateHomeKitCharacteristics();
|
|
231
260
|
} else {
|
|
232
261
|
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`);
|
|
@@ -244,7 +273,8 @@ export class WaterDetector extends deviceBase {
|
|
|
244
273
|
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);;
|
|
245
274
|
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
246
275
|
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
247
|
-
|
|
276
|
+
this.deviceStatus = deviceStatus.body;
|
|
277
|
+
await this.openAPIparseStatus();
|
|
248
278
|
await this.updateHomeKitCharacteristics();
|
|
249
279
|
} else {
|
|
250
280
|
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`);
|
|
@@ -259,10 +289,11 @@ export class WaterDetector extends deviceBase {
|
|
|
259
289
|
async registerWebhook() {
|
|
260
290
|
if (this.device.webhook) {
|
|
261
291
|
await this.debugLog('is listening webhook.');
|
|
262
|
-
this.
|
|
292
|
+
this.webhookEventHandler[this.device.deviceId] = async (context: waterLeakDetectorWebhookContext) => {
|
|
263
293
|
try {
|
|
264
294
|
await this.debugLog(`received Webhook: ${JSON.stringify(context)}`);
|
|
265
|
-
|
|
295
|
+
this.webhookContext = context;
|
|
296
|
+
await this.parseStatusWebhook();
|
|
266
297
|
await this.updateHomeKitCharacteristics();
|
|
267
298
|
} catch (e: any) {
|
|
268
299
|
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`);
|
|
@@ -28,6 +28,7 @@ export class AirConditioner extends irdeviceBase {
|
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
meter?: PlatformAccessory;
|
|
31
|
+
|
|
31
32
|
private HumiditySensor?: {
|
|
32
33
|
Name: CharacteristicValue;
|
|
33
34
|
Service: Service;
|
|
@@ -351,7 +352,7 @@ export class AirConditioner extends irdeviceBase {
|
|
|
351
352
|
const { body, statusCode } = await this.pushChangeRequest(bodyChange);
|
|
352
353
|
const deviceStatus: any = await body.json();
|
|
353
354
|
await this.pushStatusCodes(statusCode, deviceStatus);
|
|
354
|
-
if (
|
|
355
|
+
if (await this.successfulStatusCodes(statusCode, deviceStatus)) {
|
|
355
356
|
await this.successfulPushChange(statusCode, deviceStatus, bodyChange);
|
|
356
357
|
await this.updateHomeKitCharacteristics();
|
|
357
358
|
} else {
|
|
@@ -500,39 +501,25 @@ export class AirConditioner extends irdeviceBase {
|
|
|
500
501
|
}
|
|
501
502
|
|
|
502
503
|
async ThresholdTemperatureGet(): Promise<CharacteristicValue> {
|
|
504
|
+
this.HeaterCooler.Active = this.HeaterCooler.Active === undefined ? this.hap.Characteristic.Active.INACTIVE
|
|
505
|
+
: this.HeaterCooler.Active ?? this.accessory.context.Active;
|
|
503
506
|
|
|
504
|
-
|
|
505
|
-
this.
|
|
506
|
-
|
|
507
|
-
this.HeaterCooler.Active = this.HeaterCooler.Active ? this.HeaterCooler.Active : this.accessory.context.Active;
|
|
508
|
-
}
|
|
507
|
+
this.HeaterCooler.CurrentTemperature = (this.HeaterCooler.CurrentTemperature === undefined
|
|
508
|
+
&& this.accessory.context.CurrentTemperature === undefined) ? 24 : this.HeaterCooler.CurrentTemperature
|
|
509
|
+
?? this.accessory.context.CurrentTemperature;
|
|
509
510
|
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
} else {
|
|
513
|
-
this.HeaterCooler.CurrentTemperature = this.HeaterCooler.CurrentTemperature || this.accessory.context.CurrentTemperature;
|
|
514
|
-
}
|
|
511
|
+
this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature === undefined ? 24 : this.HeaterCooler.ThresholdTemperature
|
|
512
|
+
?? this.accessory.context.ThresholdTemperature;
|
|
515
513
|
|
|
516
|
-
|
|
517
|
-
this.HeaterCooler.
|
|
518
|
-
} else {
|
|
519
|
-
this.HeaterCooler.ThresholdTemperature = this.HeaterCooler.ThresholdTemperature || this.accessory.context.ThresholdTemperature;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
if (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) {
|
|
523
|
-
this.HeaterCooler.RotationSpeed = 4;
|
|
524
|
-
} else {
|
|
525
|
-
this.HeaterCooler.RotationSpeed = this.HeaterCooler.RotationSpeed || this.accessory.context.RotationSpeed;
|
|
526
|
-
}
|
|
514
|
+
this.HeaterCooler.RotationSpeed = (this.HeaterCooler.RotationSpeed === undefined && this.accessory.context.RotationSpeed === undefined) ? 4
|
|
515
|
+
: this.HeaterCooler.RotationSpeed ?? this.accessory.context.RotationSpeed;
|
|
527
516
|
|
|
528
517
|
await this.getAirConditionerConfigSettings(this.accessory, this.device);
|
|
529
518
|
|
|
530
|
-
if (this.meter) {
|
|
531
|
-
|
|
532
|
-
this.
|
|
533
|
-
|
|
534
|
-
this.HumiditySensor!.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity || this.accessory.context.CurrentRelativeHumidity;
|
|
535
|
-
}
|
|
519
|
+
if (this.meter && this.HumiditySensor?.Service) {
|
|
520
|
+
this.HumiditySensor.CurrentRelativeHumidity = (this.HumiditySensor.CurrentRelativeHumidity === undefined
|
|
521
|
+
&& this.accessory.context.CurrentRelativeHumidity === undefined) ? 0 : this.HumiditySensor.CurrentRelativeHumidity
|
|
522
|
+
?? this.accessory.context.CurrentRelativeHumidity;
|
|
536
523
|
}
|
|
537
524
|
await this.debugLog(`Get ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
|
|
538
525
|
return this.HeaterCooler.ThresholdTemperature;
|
|
@@ -548,73 +535,34 @@ export class AirConditioner extends irdeviceBase {
|
|
|
548
535
|
async updateHomeKitCharacteristics(): Promise<void> {
|
|
549
536
|
await this.debugLog('updateHomeKitCharacteristics');
|
|
550
537
|
// Active
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
} else {
|
|
554
|
-
this.accessory.context.Active = this.HeaterCooler.Active;
|
|
555
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, this.HeaterCooler.Active);
|
|
556
|
-
await this.debugLog(`updateCharacteristic Active: ${this.HeaterCooler.Active}`);
|
|
557
|
-
}
|
|
538
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.Active,
|
|
539
|
+
this.HeaterCooler.Active, 'Active');
|
|
558
540
|
// RotationSpeed
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
} else {
|
|
562
|
-
this.accessory.context.RotationSpeed = this.HeaterCooler.RotationSpeed;
|
|
563
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, this.HeaterCooler.RotationSpeed);
|
|
564
|
-
await this.debugLog('updateCharacteristic'
|
|
565
|
-
+ ` RotationSpeed: ${this.HeaterCooler.RotationSpeed}`);
|
|
566
|
-
}
|
|
541
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.RotationSpeed,
|
|
542
|
+
this.HeaterCooler.RotationSpeed, 'RotationSpeed');
|
|
567
543
|
// CurrentTemperature
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
} else {
|
|
571
|
-
this.accessory.context.CurrentTemperature = this.HeaterCooler.CurrentTemperature;
|
|
572
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, this.HeaterCooler.CurrentTemperature);
|
|
573
|
-
await this.debugLog('updateCharacteristic'
|
|
574
|
-
+ ` CurrentTemperature: ${this.HeaterCooler.CurrentTemperature}`);
|
|
575
|
-
}
|
|
576
|
-
// CurrentRelativeHumidity
|
|
577
|
-
if (this.meter) {
|
|
578
|
-
if (this.HumiditySensor!.CurrentRelativeHumidity === undefined) {
|
|
579
|
-
await this.debugLog(`CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
580
|
-
} else {
|
|
581
|
-
this.accessory.context.CurrentRelativeHumidity = this.HumiditySensor!.CurrentRelativeHumidity;
|
|
582
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentRelativeHumidity,
|
|
583
|
-
this.HumiditySensor!.CurrentRelativeHumidity);
|
|
584
|
-
await this.debugLog('updateCharacteristic'
|
|
585
|
-
+ ` CurrentRelativeHumidity: ${this.HumiditySensor!.CurrentRelativeHumidity}`);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
544
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentTemperature,
|
|
545
|
+
this.HeaterCooler.CurrentTemperature, 'CurrentTemperature');
|
|
588
546
|
// TargetHeaterCoolerState
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
} else {
|
|
592
|
-
this.accessory.context.TargetHeaterCoolerState = this.HeaterCooler.TargetHeaterCoolerState;
|
|
593
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.TargetHeaterCoolerState, this.HeaterCooler.TargetHeaterCoolerState);
|
|
594
|
-
await this.debugLog('updateCharacteristic'
|
|
595
|
-
+ ` TargetHeaterCoolerState: ${this.HeaterCooler.TargetHeaterCoolerState}`);
|
|
596
|
-
}
|
|
547
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.TargetHeaterCoolerState,
|
|
548
|
+
this.HeaterCooler.TargetHeaterCoolerState, 'TargetHeaterCoolerState');
|
|
597
549
|
// CurrentHeaterCoolerState
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
this.HeaterCooler.
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
if (this.
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.HeatingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
|
|
611
|
-
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CoolingThresholdTemperature, this.HeaterCooler.ThresholdTemperature);
|
|
612
|
-
await this.debugLog('updateCharacteristic'
|
|
613
|
-
+ ` ThresholdTemperature: ${this.HeaterCooler.ThresholdTemperature}`);
|
|
550
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CurrentHeaterCoolerState,
|
|
551
|
+
this.HeaterCooler.CurrentHeaterCoolerState, 'CurrentHeaterCoolerState');
|
|
552
|
+
// HeatingThresholdTemperature
|
|
553
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.HeatingThresholdTemperature,
|
|
554
|
+
this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
|
|
555
|
+
// CoolingThresholdTemperature
|
|
556
|
+
await this.updateCharacteristic(this.HeaterCooler.Service, this.hap.Characteristic.CoolingThresholdTemperature,
|
|
557
|
+
this.HeaterCooler.ThresholdTemperature, 'ThresholdTemperature');
|
|
558
|
+
if (this.meter && this.HumiditySensor?.Service) {
|
|
559
|
+
// CurrentRelativeHumidity
|
|
560
|
+
await this.updateCharacteristic(this.HumiditySensor.Service, this.hap.Characteristic.CurrentRelativeHumidity,
|
|
561
|
+
this.HumiditySensor.CurrentRelativeHumidity, 'CurrentRelativeHumidity');
|
|
614
562
|
}
|
|
615
563
|
}
|
|
616
564
|
|
|
617
|
-
async apiError(
|
|
565
|
+
async apiError(e: any): Promise<void> {
|
|
618
566
|
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.Active, e);
|
|
619
567
|
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.RotationSpeed, e);
|
|
620
568
|
this.HeaterCooler.Service.updateCharacteristic(this.hap.Characteristic.CurrentTemperature, e);
|
|
@@ -626,42 +574,10 @@ export class AirConditioner extends irdeviceBase {
|
|
|
626
574
|
}
|
|
627
575
|
|
|
628
576
|
async getAirConditionerConfigSettings(accessory: PlatformAccessory, device: irdevice & irDevicesConfig): Promise<void> {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
accessory.context.hide_automode = this.hide_automode;
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
if (this.device.irair?.set_max_heat) {
|
|
638
|
-
this.set_max_heat = device.irair?.set_max_heat;
|
|
639
|
-
accessory.context.set_max_heat = this.set_max_heat;
|
|
640
|
-
} else {
|
|
641
|
-
this.set_max_heat = 35;
|
|
642
|
-
accessory.context.set_max_heat = this.set_max_heat;
|
|
643
|
-
}
|
|
644
|
-
if (this.device.irair?.set_min_heat) {
|
|
645
|
-
this.set_min_heat = device.irair?.set_min_heat;
|
|
646
|
-
accessory.context.set_min_heat = this.set_min_heat;
|
|
647
|
-
} else {
|
|
648
|
-
this.set_min_heat = 0;
|
|
649
|
-
accessory.context.set_min_heat = this.set_min_heat;
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
if (this.device.irair?.set_max_cool) {
|
|
653
|
-
this.set_max_cool = device.irair?.set_max_cool;
|
|
654
|
-
accessory.context.set_max_cool = this.set_max_cool;
|
|
655
|
-
} else {
|
|
656
|
-
this.set_max_cool = 35;
|
|
657
|
-
accessory.context.set_max_cool = this.set_max_cool;
|
|
658
|
-
}
|
|
659
|
-
if (this.device.irair?.set_min_cool) {
|
|
660
|
-
this.set_min_cool = device.irair?.set_min_cool;
|
|
661
|
-
accessory.context.set_min_cool = this.set_min_cool;
|
|
662
|
-
} else {
|
|
663
|
-
this.set_min_cool = 0;
|
|
664
|
-
accessory.context.set_min_cool = this.set_min_cool;
|
|
665
|
-
}
|
|
577
|
+
accessory.context.hide_automode = this.hide_automode = device.irair?.hide_automode;
|
|
578
|
+
accessory.context.set_max_heat = this.set_max_heat = device.irair?.set_max_heat ?? 35;
|
|
579
|
+
accessory.context.set_min_heat = this.set_min_heat = device.irair?.set_min_heat ?? 0;
|
|
580
|
+
accessory.context.set_max_cool = this.set_max_cool = device.irair?.set_max_cool ?? 35;
|
|
581
|
+
accessory.context.set_min_cool = this.set_min_cool = device.irair?.set_min_cool ?? 0;
|
|
666
582
|
}
|
|
667
583
|
}
|