@switchbot/homebridge-switchbot 3.8.3-beta.3 → 3.8.3-beta.31
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/.github/workflows/beta-release.yml +7 -4
- package/.github/workflows/release.yml +7 -6
- package/CHANGELOG.md +2 -1
- package/config.schema.json +24 -0
- package/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +33 -34
- package/dist/device/blindtilt.js.map +1 -1
- package/dist/device/bot.d.ts +1 -4
- package/dist/device/bot.d.ts.map +1 -1
- package/dist/device/bot.js +30 -31
- package/dist/device/bot.js.map +1 -1
- package/dist/device/ceilinglight.d.ts +1 -4
- package/dist/device/ceilinglight.d.ts.map +1 -1
- package/dist/device/ceilinglight.js +50 -54
- package/dist/device/ceilinglight.js.map +1 -1
- package/dist/device/colorbulb.d.ts +1 -4
- package/dist/device/colorbulb.d.ts.map +1 -1
- package/dist/device/colorbulb.js +62 -66
- package/dist/device/colorbulb.js.map +1 -1
- package/dist/device/contact.d.ts +1 -4
- package/dist/device/contact.d.ts.map +1 -1
- package/dist/device/contact.js +18 -18
- package/dist/device/contact.js.map +1 -1
- package/dist/device/curtain.d.ts +1 -4
- package/dist/device/curtain.d.ts.map +1 -1
- package/dist/device/curtain.js +31 -32
- package/dist/device/curtain.js.map +1 -1
- package/dist/device/device.d.ts +6 -6
- package/dist/device/device.d.ts.map +1 -1
- package/dist/device/device.js +33 -17
- package/dist/device/device.js.map +1 -1
- package/dist/device/fan.d.ts +1 -4
- package/dist/device/fan.d.ts.map +1 -1
- package/dist/device/fan.js +47 -49
- package/dist/device/fan.js.map +1 -1
- package/dist/device/hub.d.ts +1 -4
- package/dist/device/hub.d.ts.map +1 -1
- package/dist/device/hub.js +18 -18
- package/dist/device/hub.js.map +1 -1
- package/dist/device/humidifier.d.ts +1 -4
- package/dist/device/humidifier.d.ts.map +1 -1
- package/dist/device/humidifier.js +43 -46
- package/dist/device/humidifier.js.map +1 -1
- package/dist/device/iosensor.d.ts +1 -4
- package/dist/device/iosensor.d.ts.map +1 -1
- package/dist/device/iosensor.js +18 -18
- package/dist/device/iosensor.js.map +1 -1
- package/dist/device/lightstrip.d.ts +1 -4
- package/dist/device/lightstrip.d.ts.map +1 -1
- package/dist/device/lightstrip.js +51 -54
- package/dist/device/lightstrip.js.map +1 -1
- package/dist/device/lock.d.ts +1 -4
- package/dist/device/lock.d.ts.map +1 -1
- package/dist/device/lock.js +31 -32
- package/dist/device/lock.js.map +1 -1
- package/dist/device/meter.d.ts +1 -4
- package/dist/device/meter.d.ts.map +1 -1
- package/dist/device/meter.js +18 -18
- package/dist/device/meter.js.map +1 -1
- package/dist/device/meterplus.d.ts +1 -4
- package/dist/device/meterplus.d.ts.map +1 -1
- package/dist/device/meterplus.js +18 -18
- package/dist/device/meterplus.js.map +1 -1
- package/dist/device/motion.d.ts +1 -4
- package/dist/device/motion.d.ts.map +1 -1
- package/dist/device/motion.js +18 -18
- package/dist/device/motion.js.map +1 -1
- package/dist/device/plug.d.ts +1 -4
- package/dist/device/plug.d.ts.map +1 -1
- package/dist/device/plug.js +29 -30
- package/dist/device/plug.js.map +1 -1
- package/dist/device/robotvacuumcleaner.d.ts +1 -4
- package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
- package/dist/device/robotvacuumcleaner.js +36 -38
- package/dist/device/robotvacuumcleaner.js.map +1 -1
- package/dist/device/waterdetector.d.ts +1 -4
- package/dist/device/waterdetector.d.ts.map +1 -1
- package/dist/device/waterdetector.js +18 -18
- package/dist/device/waterdetector.js.map +1 -1
- package/dist/irdevice/airconditioner.d.ts +1 -1
- package/dist/irdevice/airconditioner.d.ts.map +1 -1
- package/dist/irdevice/airconditioner.js +11 -12
- package/dist/irdevice/airconditioner.js.map +1 -1
- package/dist/irdevice/airpurifier.d.ts +1 -1
- package/dist/irdevice/airpurifier.d.ts.map +1 -1
- package/dist/irdevice/airpurifier.js +11 -12
- package/dist/irdevice/airpurifier.js.map +1 -1
- package/dist/irdevice/camera.d.ts +1 -1
- package/dist/irdevice/camera.d.ts.map +1 -1
- package/dist/irdevice/camera.js +9 -10
- package/dist/irdevice/camera.js.map +1 -1
- package/dist/irdevice/fan.d.ts +1 -1
- package/dist/irdevice/fan.d.ts.map +1 -1
- package/dist/irdevice/fan.js +15 -16
- package/dist/irdevice/fan.js.map +1 -1
- package/dist/irdevice/irdevice.d.ts +6 -6
- package/dist/irdevice/irdevice.d.ts.map +1 -1
- package/dist/irdevice/irdevice.js +7 -13
- package/dist/irdevice/irdevice.js.map +1 -1
- package/dist/irdevice/light.d.ts +1 -1
- package/dist/irdevice/light.d.ts.map +1 -1
- package/dist/irdevice/light.js +9 -10
- package/dist/irdevice/light.js.map +1 -1
- package/dist/irdevice/other.d.ts +1 -1
- package/dist/irdevice/other.d.ts.map +1 -1
- package/dist/irdevice/other.js +9 -10
- package/dist/irdevice/other.js.map +1 -1
- package/dist/irdevice/tv.d.ts +1 -1
- package/dist/irdevice/tv.d.ts.map +1 -1
- package/dist/irdevice/tv.js +27 -28
- package/dist/irdevice/tv.js.map +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts +1 -1
- package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
- package/dist/irdevice/vacuumcleaner.js +9 -10
- package/dist/irdevice/vacuumcleaner.js.map +1 -1
- package/dist/irdevice/waterheater.d.ts +1 -1
- package/dist/irdevice/waterheater.d.ts.map +1 -1
- package/dist/irdevice/waterheater.js +9 -10
- package/dist/irdevice/waterheater.js.map +1 -1
- package/dist/platform.d.ts +6 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +127 -188
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +4 -3
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js.map +1 -1
- package/docs/assets/highlight.css +42 -0
- package/docs/assets/main.js +1 -1
- package/docs/functions/default.html +1 -1
- package/docs/index.html +61 -50
- package/docs/media/security-privacy-bluetooth.png +0 -0
- package/package.json +14 -15
- package/src/device/blindtilt.ts +35 -39
- package/src/device/bot.ts +31 -35
- package/src/device/ceilinglight.ts +51 -58
- package/src/device/colorbulb.ts +63 -70
- package/src/device/contact.ts +19 -22
- package/src/device/curtain.ts +33 -37
- package/src/device/device.ts +32 -21
- package/src/device/fan.ts +48 -53
- package/src/device/hub.ts +19 -22
- package/src/device/humidifier.ts +44 -50
- package/src/device/iosensor.ts +19 -22
- package/src/device/lightstrip.ts +52 -58
- package/src/device/lock.ts +32 -36
- package/src/device/meter.ts +19 -22
- package/src/device/meterplus.ts +19 -22
- package/src/device/motion.ts +19 -22
- package/src/device/plug.ts +30 -34
- package/src/device/robotvacuumcleaner.ts +37 -46
- package/src/device/waterdetector.ts +19 -22
- package/src/irdevice/airconditioner.ts +12 -14
- package/src/irdevice/airpurifier.ts +12 -13
- package/src/irdevice/camera.ts +10 -11
- package/src/irdevice/fan.ts +16 -17
- package/src/irdevice/irdevice.ts +9 -17
- package/src/irdevice/light.ts +10 -11
- package/src/irdevice/other.ts +10 -11
- package/src/irdevice/tv.ts +28 -29
- package/src/irdevice/vacuumcleaner.ts +10 -11
- package/src/irdevice/waterheater.ts +10 -11
- package/src/platform.ts +131 -188
- package/src/settings.ts +8 -4
- package/src/utils.ts +2 -1
- package/dist/types/bledevicestatus.d.ts +0 -281
- package/dist/types/bledevicestatus.d.ts.map +0 -1
- package/dist/types/bledevicestatus.js +0 -2
- package/dist/types/bledevicestatus.js.map +0 -1
- package/dist/types/devicelist.d.ts +0 -89
- package/dist/types/devicelist.d.ts.map +0 -1
- package/dist/types/devicelist.js +0 -6
- package/dist/types/devicelist.js.map +0 -1
- package/dist/types/deviceresponse.d.ts +0 -13
- package/dist/types/deviceresponse.d.ts.map +0 -1
- package/dist/types/deviceresponse.js +0 -2
- package/dist/types/deviceresponse.js.map +0 -1
- package/dist/types/devicestatus.d.ts +0 -149
- package/dist/types/devicestatus.d.ts.map +0 -1
- package/dist/types/devicestatus.js +0 -3
- package/dist/types/devicestatus.js.map +0 -1
- package/dist/types/devicewebhookstatus.d.ts +0 -156
- package/dist/types/devicewebhookstatus.d.ts.map +0 -1
- package/dist/types/devicewebhookstatus.js +0 -2
- package/dist/types/devicewebhookstatus.js.map +0 -1
- package/dist/types/irdevicelist.d.ts +0 -10
- package/dist/types/irdevicelist.d.ts.map +0 -1
- package/dist/types/irdevicelist.js +0 -2
- package/dist/types/irdevicelist.js.map +0 -1
- package/dist/types/pushbody.d.ts +0 -6
- package/dist/types/pushbody.d.ts.map +0 -1
- package/dist/types/pushbody.js +0 -2
- package/dist/types/pushbody.js.map +0 -1
- package/src/types/bledevicestatus.ts +0 -303
- package/src/types/devicelist.ts +0 -124
- package/src/types/deviceresponse.ts +0 -14
- package/src/types/devicestatus.ts +0 -178
- package/src/types/devicewebhookstatus.ts +0 -191
- package/src/types/irdevicelist.ts +0 -15
- package/src/types/pushbody.ts +0 -9
package/src/device/plug.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* plug.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, plugMiniJPServiceData, plugMiniJPWebhookContext, plugMiniStatus, plugMiniUSServiceData, plugMiniUSWebhookContext, plugStatus, plugWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { plugMiniJPServiceData, plugMiniUSServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { plugMiniStatus, plugStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { plugMiniJPWebhookContext, plugMiniUSWebhookContext, plugWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -74,7 +71,7 @@ export class Plug extends deviceBase {
|
|
|
74
71
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
75
72
|
this.refreshStatus()
|
|
76
73
|
} catch (e: any) {
|
|
77
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
74
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
78
75
|
}
|
|
79
76
|
|
|
80
77
|
// regisiter webhook event handler if enabled
|
|
@@ -82,7 +79,7 @@ export class Plug extends deviceBase {
|
|
|
82
79
|
this.debugLog('Registering Webhook Event Handler')
|
|
83
80
|
this.registerWebhook()
|
|
84
81
|
} catch (e: any) {
|
|
85
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
82
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
// regisiter platform BLE event handler if enabled
|
|
@@ -90,7 +87,7 @@ export class Plug extends deviceBase {
|
|
|
90
87
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
91
88
|
this.registerPlatformBLE()
|
|
92
89
|
} catch (e: any) {
|
|
93
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
90
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
94
91
|
}
|
|
95
92
|
|
|
96
93
|
// Start an update interval
|
|
@@ -180,14 +177,14 @@ export class Plug extends deviceBase {
|
|
|
180
177
|
|
|
181
178
|
async BLERefreshStatus(): Promise<void> {
|
|
182
179
|
await this.debugLog('BLERefreshStatus')
|
|
183
|
-
const
|
|
184
|
-
if (
|
|
185
|
-
await this.BLERefreshConnection(
|
|
180
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
181
|
+
if (switchBotBLE === undefined) {
|
|
182
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
186
183
|
} else {
|
|
187
184
|
// Start to monitor advertisement packets
|
|
188
185
|
(async () => {
|
|
189
186
|
// Start to monitor advertisement packets
|
|
190
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
187
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as plugMiniUSServiceData | plugMiniJPServiceData
|
|
191
188
|
// Update HomeKit
|
|
192
189
|
if ((serviceData.model === SwitchBotBLEModel.PlugMiniUS || SwitchBotBLEModel.PlugMiniJP)
|
|
193
190
|
&& serviceData.modelName === (SwitchBotBLEModelName.PlugMini || SwitchBotBLEModelName.PlugMini)) {
|
|
@@ -195,8 +192,8 @@ export class Plug extends deviceBase {
|
|
|
195
192
|
await this.BLEparseStatus()
|
|
196
193
|
await this.updateHomeKitCharacteristics()
|
|
197
194
|
} else {
|
|
198
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
199
|
-
await this.BLERefreshConnection(
|
|
195
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
196
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
200
197
|
}
|
|
201
198
|
})()
|
|
202
199
|
}
|
|
@@ -217,7 +214,7 @@ export class Plug extends deviceBase {
|
|
|
217
214
|
await this.BLEparseStatus()
|
|
218
215
|
await this.updateHomeKitCharacteristics()
|
|
219
216
|
} catch (e: any) {
|
|
220
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
217
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
221
218
|
}
|
|
222
219
|
}
|
|
223
220
|
} catch (error) {
|
|
@@ -231,17 +228,17 @@ export class Plug extends deviceBase {
|
|
|
231
228
|
async openAPIRefreshStatus(): Promise<void> {
|
|
232
229
|
await this.debugLog('openAPIRefreshStatus')
|
|
233
230
|
try {
|
|
234
|
-
const { body
|
|
235
|
-
const deviceStatus: any = await body
|
|
236
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
237
|
-
if (await this.successfulStatusCodes(
|
|
238
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
231
|
+
const { body } = await this.deviceRefreshStatus()
|
|
232
|
+
const deviceStatus: any = await body
|
|
233
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
234
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
235
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
239
236
|
this.deviceStatus = deviceStatus.body
|
|
240
237
|
await this.openAPIparseStatus()
|
|
241
238
|
await this.updateHomeKitCharacteristics()
|
|
242
239
|
} else {
|
|
243
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
244
|
-
await this.debugWarnLog(
|
|
240
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
241
|
+
await this.debugWarnLog(deviceStatus)
|
|
245
242
|
}
|
|
246
243
|
} catch (e: any) {
|
|
247
244
|
await this.apiError(e)
|
|
@@ -259,7 +256,7 @@ export class Plug extends deviceBase {
|
|
|
259
256
|
await this.parseStatusWebhook()
|
|
260
257
|
await this.updateHomeKitCharacteristics()
|
|
261
258
|
} catch (e: any) {
|
|
262
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
259
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
263
260
|
}
|
|
264
261
|
}
|
|
265
262
|
} else {
|
|
@@ -301,13 +298,13 @@ export class Plug extends deviceBase {
|
|
|
301
298
|
await this.debugLog('BLEpushChanges')
|
|
302
299
|
if (this.Outlet.On !== this.accessory.context.On) {
|
|
303
300
|
await this.debugLog(`BLEpushChanges On: ${this.Outlet.On}, OnCached: ${this.accessory.context.On}`)
|
|
304
|
-
const
|
|
301
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
305
302
|
try {
|
|
306
303
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
307
304
|
this.device.bleMac = formattedDeviceId
|
|
308
305
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
309
|
-
if (
|
|
310
|
-
|
|
306
|
+
if (switchBotBLE !== false) {
|
|
307
|
+
switchBotBLE
|
|
311
308
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
312
309
|
.then(async (device_list: any) => {
|
|
313
310
|
await this.infoLog(`On: ${this.Outlet.On}`)
|
|
@@ -332,7 +329,7 @@ export class Plug extends deviceBase {
|
|
|
332
329
|
await this.BLEPushConnection()
|
|
333
330
|
})
|
|
334
331
|
} else {
|
|
335
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
332
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
336
333
|
await this.BLEPushConnection()
|
|
337
334
|
}
|
|
338
335
|
} catch (error) {
|
|
@@ -347,21 +344,20 @@ export class Plug extends deviceBase {
|
|
|
347
344
|
await this.debugLog('openAPIpushChanges')
|
|
348
345
|
if (this.Outlet.On !== this.accessory.context.On) {
|
|
349
346
|
const command = this.Outlet.On ? 'turnOn' : 'turnOff'
|
|
350
|
-
const bodyChange =
|
|
347
|
+
const bodyChange: bodyChange = {
|
|
351
348
|
command: `${command}`,
|
|
352
349
|
parameter: 'default',
|
|
353
350
|
commandType: 'command',
|
|
354
|
-
}
|
|
351
|
+
}
|
|
355
352
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
356
353
|
try {
|
|
357
|
-
const { body
|
|
358
|
-
const deviceStatus: any = await body
|
|
359
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
360
|
-
if (await this.successfulStatusCodes(
|
|
361
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
354
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
355
|
+
const deviceStatus: any = await body
|
|
356
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
357
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
358
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
362
359
|
await this.updateHomeKitCharacteristics()
|
|
363
360
|
} else {
|
|
364
|
-
await this.statusCode(statusCode)
|
|
365
361
|
await this.statusCode(deviceStatus.statusCode)
|
|
366
362
|
}
|
|
367
363
|
} catch (e: any) {
|
|
@@ -3,17 +3,10 @@
|
|
|
3
3
|
* robotvacuumcleaner.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, floorCleaningRobotS10Status, floorCleaningRobotS10WebhookContext, robotVacuumCleanerS1PlusStatus, robotVacuumCleanerS1PlusWebhookContext, robotVacuumCleanerS1Status, robotVacuumCleanerS1WebhookContext, robotVacuumCleanerServiceData } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { robotVacuumCleanerServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { floorCleaningRobotS10Status, robotVacuumCleanerS1PlusStatus, robotVacuumCleanerS1Status } from '../types/devicestatus.js'
|
|
12
|
-
import type {
|
|
13
|
-
floorCleaningRobotS10WebhookContext,
|
|
14
|
-
robotVacuumCleanerS1PlusWebhookContext,
|
|
15
|
-
robotVacuumCleanerS1WebhookContext,
|
|
16
|
-
} from '../types/devicewebhookstatus.js'
|
|
17
10
|
|
|
18
11
|
/*
|
|
19
12
|
* For Testing Locally:
|
|
@@ -123,7 +116,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
123
116
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
124
117
|
this.refreshStatus()
|
|
125
118
|
} catch (e: any) {
|
|
126
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
119
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
127
120
|
}
|
|
128
121
|
|
|
129
122
|
// regisiter webhook event handler if enabled
|
|
@@ -131,7 +124,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
131
124
|
this.debugLog('Registering Webhook Event Handler')
|
|
132
125
|
this.registerWebhook()
|
|
133
126
|
} catch (e: any) {
|
|
134
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
127
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
135
128
|
}
|
|
136
129
|
|
|
137
130
|
// regisiter platform BLE event handler if enabled
|
|
@@ -139,7 +132,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
139
132
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
140
133
|
this.registerPlatformBLE()
|
|
141
134
|
} catch (e: any) {
|
|
142
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
135
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
143
136
|
}
|
|
144
137
|
|
|
145
138
|
// Start an update interval
|
|
@@ -271,22 +264,22 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
271
264
|
|
|
272
265
|
async BLERefreshStatus(): Promise<void> {
|
|
273
266
|
await this.debugLog('BLERefreshStatus')
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
await this.BLERefreshConnection(
|
|
267
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
268
|
+
if (switchBotBLE === undefined) {
|
|
269
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
277
270
|
} else {
|
|
278
271
|
// Start to monitor advertisement packets
|
|
279
272
|
(async () => {
|
|
280
273
|
// Start to monitor advertisement packets
|
|
281
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
274
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as unknown as robotVacuumCleanerServiceData
|
|
282
275
|
// Update HomeKit
|
|
283
276
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
284
277
|
this.serviceData = serviceData
|
|
285
278
|
await this.BLEparseStatus()
|
|
286
279
|
await this.updateHomeKitCharacteristics()
|
|
287
280
|
} else {
|
|
288
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
289
|
-
await this.BLERefreshConnection(
|
|
281
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
282
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
290
283
|
}
|
|
291
284
|
})()
|
|
292
285
|
}
|
|
@@ -307,7 +300,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
307
300
|
await this.BLEparseStatus()
|
|
308
301
|
await this.updateHomeKitCharacteristics()
|
|
309
302
|
} catch (e: any) {
|
|
310
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
303
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
311
304
|
}
|
|
312
305
|
}
|
|
313
306
|
} catch (error) {
|
|
@@ -321,17 +314,17 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
321
314
|
async openAPIRefreshStatus(): Promise<void> {
|
|
322
315
|
await this.debugLog('openAPIRefreshStatus')
|
|
323
316
|
try {
|
|
324
|
-
const { body
|
|
325
|
-
const deviceStatus: any = await body
|
|
326
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
327
|
-
if (await this.successfulStatusCodes(
|
|
328
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
317
|
+
const { body } = await this.deviceRefreshStatus()
|
|
318
|
+
const deviceStatus: any = await body
|
|
319
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
320
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
321
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
329
322
|
this.deviceStatus = deviceStatus.body
|
|
330
323
|
await this.openAPIparseStatus()
|
|
331
324
|
await this.updateHomeKitCharacteristics()
|
|
332
325
|
} else {
|
|
333
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
334
|
-
await this.debugWarnLog(
|
|
326
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
327
|
+
await this.debugWarnLog(deviceStatus)
|
|
335
328
|
}
|
|
336
329
|
} catch (e: any) {
|
|
337
330
|
await this.apiError(e)
|
|
@@ -349,7 +342,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
349
342
|
await this.parseStatusWebhook()
|
|
350
343
|
await this.updateHomeKitCharacteristics()
|
|
351
344
|
} catch (e: any) {
|
|
352
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
345
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
353
346
|
}
|
|
354
347
|
}
|
|
355
348
|
} else {
|
|
@@ -388,13 +381,13 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
388
381
|
async BLEpushChanges(): Promise<void> {
|
|
389
382
|
await this.debugLog('BLEpushChanges')
|
|
390
383
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
391
|
-
const
|
|
384
|
+
const switchBotBLE = await this.platform.connectBLE(this.accessory, this.device)
|
|
392
385
|
try {
|
|
393
386
|
const formattedDeviceId = formatDeviceIdAsMac(this.device.deviceId)
|
|
394
387
|
this.device.bleMac = formattedDeviceId
|
|
395
388
|
await this.debugLog(`bleMac: ${this.device.bleMac}`)
|
|
396
|
-
if (
|
|
397
|
-
|
|
389
|
+
if (switchBotBLE !== false) {
|
|
390
|
+
switchBotBLE
|
|
398
391
|
.discover({ model: this.device.bleModel, id: this.device.bleMac })
|
|
399
392
|
.then(async (device_list: any) => {
|
|
400
393
|
await this.infoLog(`On: ${this.LightBulb.On}`)
|
|
@@ -419,7 +412,7 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
419
412
|
await this.BLEPushConnection()
|
|
420
413
|
})
|
|
421
414
|
} else {
|
|
422
|
-
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${
|
|
415
|
+
await this.errorLog(`wasn't able to establish BLE Connection, node-switchbot: ${JSON.stringify(switchBotBLE)}`)
|
|
423
416
|
await this.BLEPushConnection()
|
|
424
417
|
}
|
|
425
418
|
} catch (error) {
|
|
@@ -434,21 +427,20 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
434
427
|
await this.debugLog('openAPIpushChanges')
|
|
435
428
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
436
429
|
const command = this.LightBulb.On ? 'start' : 'dock'
|
|
437
|
-
const bodyChange =
|
|
430
|
+
const bodyChange: bodyChange = {
|
|
438
431
|
command: `${command}`,
|
|
439
432
|
parameter: 'default',
|
|
440
433
|
commandType: 'command',
|
|
441
|
-
}
|
|
434
|
+
}
|
|
442
435
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
443
436
|
try {
|
|
444
|
-
const { body
|
|
445
|
-
const deviceStatus: any = await body
|
|
446
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
447
|
-
if (await this.successfulStatusCodes(
|
|
448
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
437
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
438
|
+
const deviceStatus: any = await body
|
|
439
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
440
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
441
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
449
442
|
await this.updateHomeKitCharacteristics()
|
|
450
443
|
} else {
|
|
451
|
-
await this.statusCode(statusCode)
|
|
452
444
|
await this.statusCode(deviceStatus.statusCode)
|
|
453
445
|
}
|
|
454
446
|
} catch (e: any) {
|
|
@@ -471,21 +463,20 @@ export class RobotVacuumCleaner extends deviceBase {
|
|
|
471
463
|
: this.LightBulb.Brightness === 75
|
|
472
464
|
? '2'
|
|
473
465
|
: this.LightBulb.Brightness === 100 ? '3' : 'default'
|
|
474
|
-
const bodyChange =
|
|
466
|
+
const bodyChange: bodyChange = {
|
|
475
467
|
command: `${command}`,
|
|
476
468
|
parameter: `${parameter}`,
|
|
477
469
|
commandType: 'command',
|
|
478
|
-
}
|
|
470
|
+
}
|
|
479
471
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
480
472
|
try {
|
|
481
|
-
const { body
|
|
482
|
-
const deviceStatus: any = await body
|
|
483
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
484
|
-
if (await this.successfulStatusCodes(
|
|
485
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
473
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
474
|
+
const deviceStatus: any = await body
|
|
475
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
476
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
477
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
486
478
|
await this.updateHomeKitCharacteristics()
|
|
487
479
|
} else {
|
|
488
|
-
await this.statusCode(statusCode)
|
|
489
480
|
await this.statusCode(deviceStatus.statusCode)
|
|
490
481
|
}
|
|
491
482
|
} catch (e: any) {
|
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* waterdetector.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, waterLeakDetectorServiceData, waterLeakDetectorStatus, waterLeakDetectorWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { waterLeakDetectorServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { waterLeakDetectorStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { waterLeakDetectorWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -119,7 +116,7 @@ export class WaterDetector extends deviceBase {
|
|
|
119
116
|
this.debugLog('Retrieve initial values and update Homekit')
|
|
120
117
|
this.refreshStatus()
|
|
121
118
|
} catch (e: any) {
|
|
122
|
-
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e}`)
|
|
119
|
+
this.errorLog(`failed to retrieve initial values and update Homekit, Error: ${e.message ?? e}`)
|
|
123
120
|
}
|
|
124
121
|
|
|
125
122
|
// regisiter webhook event handler if enabled
|
|
@@ -127,7 +124,7 @@ export class WaterDetector extends deviceBase {
|
|
|
127
124
|
this.debugLog('Registering Webhook Event Handler')
|
|
128
125
|
this.registerWebhook()
|
|
129
126
|
} catch (e: any) {
|
|
130
|
-
this.errorLog(`failed to registerWebhook, Error: ${e}`)
|
|
127
|
+
this.errorLog(`failed to registerWebhook, Error: ${e.message ?? e}`)
|
|
131
128
|
}
|
|
132
129
|
|
|
133
130
|
// regisiter platform BLE event handler if enabled
|
|
@@ -135,7 +132,7 @@ export class WaterDetector extends deviceBase {
|
|
|
135
132
|
this.debugLog('Registering Platform BLE Event Handler')
|
|
136
133
|
this.registerPlatformBLE()
|
|
137
134
|
} catch (e: any) {
|
|
138
|
-
this.errorLog(`failed to registerPlatformBLE, Error: ${e}`)
|
|
135
|
+
this.errorLog(`failed to registerPlatformBLE, Error: ${e.message ?? e}`)
|
|
139
136
|
}
|
|
140
137
|
|
|
141
138
|
// Start an update interval
|
|
@@ -271,22 +268,22 @@ export class WaterDetector extends deviceBase {
|
|
|
271
268
|
|
|
272
269
|
async BLERefreshStatus(): Promise<void> {
|
|
273
270
|
await this.debugLog('BLERefreshStatus')
|
|
274
|
-
const
|
|
275
|
-
if (
|
|
276
|
-
await this.BLERefreshConnection(
|
|
271
|
+
const switchBotBLE = await this.switchbotBLE()
|
|
272
|
+
if (switchBotBLE === undefined) {
|
|
273
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
277
274
|
} else {
|
|
278
275
|
// Start to monitor advertisement packets
|
|
279
276
|
(async () => {
|
|
280
277
|
// Start to monitor advertisement packets
|
|
281
|
-
const serviceData = await this.monitorAdvertisementPackets(
|
|
278
|
+
const serviceData = await this.monitorAdvertisementPackets(switchBotBLE) as waterLeakDetectorServiceData
|
|
282
279
|
// Update HomeKit
|
|
283
280
|
if (serviceData.model === SwitchBotBLEModel.Unknown && serviceData.modelName === SwitchBotBLEModelName.Unknown) {
|
|
284
281
|
this.serviceData = serviceData
|
|
285
282
|
await this.BLEparseStatus()
|
|
286
283
|
await this.updateHomeKitCharacteristics()
|
|
287
284
|
} else {
|
|
288
|
-
await this.errorLog(`failed to get serviceData, serviceData: ${serviceData}`)
|
|
289
|
-
await this.BLERefreshConnection(
|
|
285
|
+
await this.errorLog(`failed to get serviceData, serviceData: ${JSON.stringify(serviceData)}`)
|
|
286
|
+
await this.BLERefreshConnection(switchBotBLE)
|
|
290
287
|
}
|
|
291
288
|
})()
|
|
292
289
|
}
|
|
@@ -307,7 +304,7 @@ export class WaterDetector extends deviceBase {
|
|
|
307
304
|
await this.BLEparseStatus()
|
|
308
305
|
await this.updateHomeKitCharacteristics()
|
|
309
306
|
} catch (e: any) {
|
|
310
|
-
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
307
|
+
await this.errorLog(`failed to handle BLE. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
311
308
|
}
|
|
312
309
|
}
|
|
313
310
|
} catch (error) {
|
|
@@ -321,17 +318,17 @@ export class WaterDetector extends deviceBase {
|
|
|
321
318
|
async openAPIRefreshStatus(): Promise<void> {
|
|
322
319
|
await this.debugLog('openAPIRefreshStatus')
|
|
323
320
|
try {
|
|
324
|
-
const { body
|
|
325
|
-
const deviceStatus: any = await body
|
|
326
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
327
|
-
if (await this.successfulStatusCodes(
|
|
328
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
321
|
+
const { body } = await this.deviceRefreshStatus()
|
|
322
|
+
const deviceStatus: any = await body
|
|
323
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
324
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
325
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
329
326
|
this.deviceStatus = deviceStatus.body
|
|
330
327
|
await this.openAPIparseStatus()
|
|
331
328
|
await this.updateHomeKitCharacteristics()
|
|
332
329
|
} else {
|
|
333
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
334
|
-
await this.debugWarnLog(
|
|
330
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
331
|
+
await this.debugWarnLog(deviceStatus)
|
|
335
332
|
}
|
|
336
333
|
} catch (e: any) {
|
|
337
334
|
await this.apiError(e)
|
|
@@ -349,7 +346,7 @@ export class WaterDetector extends deviceBase {
|
|
|
349
346
|
await this.parseStatusWebhook()
|
|
350
347
|
await this.updateHomeKitCharacteristics()
|
|
351
348
|
} catch (e: any) {
|
|
352
|
-
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e}`)
|
|
349
|
+
await this.errorLog(`failed to handle webhook. Received: ${JSON.stringify(context)} Error: ${e.message ?? e}`)
|
|
353
350
|
}
|
|
354
351
|
}
|
|
355
352
|
} else {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* airconditioners.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -162,11 +162,11 @@ export class AirConditioner extends irdeviceBase {
|
|
|
162
162
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
163
163
|
const commandType: string = await this.commandType()
|
|
164
164
|
const command: string = await this.commandOn()
|
|
165
|
-
const bodyChange =
|
|
165
|
+
const bodyChange: bodyChange = {
|
|
166
166
|
command,
|
|
167
167
|
parameter: 'default',
|
|
168
168
|
commandType,
|
|
169
|
-
}
|
|
169
|
+
}
|
|
170
170
|
await this.pushChanges(bodyChange)
|
|
171
171
|
}
|
|
172
172
|
}
|
|
@@ -176,11 +176,11 @@ export class AirConditioner extends irdeviceBase {
|
|
|
176
176
|
if (this.HeaterCooler.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOff) {
|
|
177
177
|
const commandType: string = await this.commandType()
|
|
178
178
|
const command: string = await this.commandOff()
|
|
179
|
-
const bodyChange =
|
|
179
|
+
const bodyChange: bodyChange = {
|
|
180
180
|
command,
|
|
181
181
|
parameter: 'default',
|
|
182
182
|
commandType,
|
|
183
|
-
}
|
|
183
|
+
}
|
|
184
184
|
await this.pushChanges(bodyChange)
|
|
185
185
|
}
|
|
186
186
|
}
|
|
@@ -219,12 +219,11 @@ export class AirConditioner extends irdeviceBase {
|
|
|
219
219
|
const parameter = `${this.HeaterCooler.ThresholdTemperature},${this.CurrentMode},${this.CurrentFanSpeed},${this.state}`
|
|
220
220
|
|
|
221
221
|
await this.UpdateCurrentHeaterCoolerState()
|
|
222
|
-
const bodyChange =
|
|
222
|
+
const bodyChange: bodyChange = {
|
|
223
223
|
command: 'setAll',
|
|
224
224
|
parameter: `${parameter}`,
|
|
225
225
|
commandType: 'command',
|
|
226
|
-
}
|
|
227
|
-
|
|
226
|
+
}
|
|
228
227
|
await this.pushChanges(bodyChange)
|
|
229
228
|
}
|
|
230
229
|
|
|
@@ -317,14 +316,13 @@ export class AirConditioner extends irdeviceBase {
|
|
|
317
316
|
if (this.device.connectionType === 'OpenAPI' && !this.disablePushDetail) {
|
|
318
317
|
await this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
319
318
|
try {
|
|
320
|
-
const { body
|
|
321
|
-
const deviceStatus: any = await body
|
|
322
|
-
await this.pushStatusCodes(
|
|
323
|
-
if (await this.successfulStatusCodes(
|
|
324
|
-
await this.successfulPushChange(
|
|
319
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
320
|
+
const deviceStatus: any = await body
|
|
321
|
+
await this.pushStatusCodes(deviceStatus)
|
|
322
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
323
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
325
324
|
await this.updateHomeKitCharacteristics()
|
|
326
325
|
} else {
|
|
327
|
-
await this.statusCode(statusCode)
|
|
328
326
|
await this.statusCode(deviceStatus.statusCode)
|
|
329
327
|
}
|
|
330
328
|
} catch (e: any) {
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
* airpurifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, irdevice } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { irDevicesConfig } from '../settings.js'
|
|
9
|
-
import type { irdevice } from '../types/irdevicelist.js'
|
|
10
10
|
|
|
11
11
|
import { irdeviceBase } from './irdevice.js'
|
|
12
12
|
|
|
@@ -149,11 +149,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
149
149
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.ACTIVE && !this.disablePushOn) {
|
|
150
150
|
const commandType: string = await this.commandType()
|
|
151
151
|
const command: string = await this.commandOn()
|
|
152
|
-
const bodyChange =
|
|
152
|
+
const bodyChange: bodyChange = {
|
|
153
153
|
command,
|
|
154
154
|
parameter: 'default',
|
|
155
155
|
commandType,
|
|
156
|
-
}
|
|
156
|
+
}
|
|
157
157
|
await this.pushChanges(bodyChange)
|
|
158
158
|
}
|
|
159
159
|
}
|
|
@@ -163,11 +163,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
163
163
|
if (this.AirPurifier.Active === this.hap.Characteristic.Active.INACTIVE && !this.disablePushOn) {
|
|
164
164
|
const commandType: string = await this.commandType()
|
|
165
165
|
const command: string = await this.commandOff()
|
|
166
|
-
const bodyChange =
|
|
166
|
+
const bodyChange: bodyChange = {
|
|
167
167
|
command,
|
|
168
168
|
parameter: 'default',
|
|
169
169
|
commandType,
|
|
170
|
-
}
|
|
170
|
+
}
|
|
171
171
|
await this.pushChanges(bodyChange)
|
|
172
172
|
}
|
|
173
173
|
}
|
|
@@ -191,11 +191,11 @@ export class AirPurifier extends irdeviceBase {
|
|
|
191
191
|
this.CurrentAPFanSpeed = this.CurrentFanSpeed ?? 1
|
|
192
192
|
this.APActive = this.AirPurifier.Active === 1 ? 'on' : 'off'
|
|
193
193
|
const parameter = `${this.CurrentAPTemp},${this.CurrentAPMode},${this.CurrentAPFanSpeed},${this.APActive}`
|
|
194
|
-
const bodyChange =
|
|
194
|
+
const bodyChange: bodyChange = {
|
|
195
195
|
command: 'setAll',
|
|
196
196
|
parameter: `${parameter}`,
|
|
197
197
|
commandType: 'command',
|
|
198
|
-
}
|
|
198
|
+
}
|
|
199
199
|
if (this.AirPurifier.Active === 1) {
|
|
200
200
|
if ((Number(this.TemperatureSensor!.CurrentTemperature) || 24) < (this.LastTemperature || 30)) {
|
|
201
201
|
this.AirPurifier.CurrentHeaterCoolerState = this.hap.Characteristic.CurrentHeaterCoolerState.COOLING
|
|
@@ -213,14 +213,13 @@ export class AirPurifier extends irdeviceBase {
|
|
|
213
213
|
if (this.device.connectionType === 'OpenAPI') {
|
|
214
214
|
this.infoLog(`Sending request to SwitchBot API, body: ${bodyChange},`)
|
|
215
215
|
try {
|
|
216
|
-
const { body
|
|
217
|
-
const deviceStatus: any = await body
|
|
218
|
-
await this.pushStatusCodes(
|
|
219
|
-
if (await this.successfulStatusCodes(
|
|
220
|
-
await this.successfulPushChange(
|
|
216
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
217
|
+
const deviceStatus: any = await body
|
|
218
|
+
await this.pushStatusCodes(deviceStatus)
|
|
219
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
220
|
+
await this.successfulPushChange(deviceStatus, bodyChange)
|
|
221
221
|
await this.updateHomeKitCharacteristics()
|
|
222
222
|
} else {
|
|
223
|
-
await this.statusCode(statusCode)
|
|
224
223
|
await this.statusCode(deviceStatus.statusCode)
|
|
225
224
|
}
|
|
226
225
|
} catch (e: any) {
|