@switchbot/homebridge-switchbot 3.8.3-beta.3 → 3.8.3-beta.30
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/dist/device/blindtilt.d.ts +1 -4
- package/dist/device/blindtilt.d.ts.map +1 -1
- package/dist/device/blindtilt.js +18 -19
- 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 +15 -16
- 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 +35 -39
- 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 +35 -39
- 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 +7 -7
- 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 +16 -17
- 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 +30 -14
- 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 +32 -34
- 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 +7 -7
- 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 +28 -31
- 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 +7 -7
- 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 +28 -31
- 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 +15 -16
- 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 +7 -7
- 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 +7 -7
- 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 +7 -7
- 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 +14 -15
- 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 +21 -23
- 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 +7 -7
- 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 +105 -170
- package/dist/platform.js.map +1 -1
- package/dist/settings.d.ts +1 -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 +13 -14
- package/src/device/blindtilt.ts +20 -24
- package/src/device/bot.ts +16 -20
- package/src/device/ceilinglight.ts +36 -43
- package/src/device/colorbulb.ts +36 -43
- package/src/device/contact.ts +8 -11
- package/src/device/curtain.ts +18 -22
- package/src/device/device.ts +29 -18
- package/src/device/fan.ts +33 -38
- package/src/device/hub.ts +8 -11
- package/src/device/humidifier.ts +29 -35
- package/src/device/iosensor.ts +8 -11
- package/src/device/lightstrip.ts +29 -35
- package/src/device/lock.ts +16 -20
- package/src/device/meter.ts +8 -11
- package/src/device/meterplus.ts +8 -11
- package/src/device/motion.ts +8 -11
- package/src/device/plug.ts +15 -19
- package/src/device/robotvacuumcleaner.ts +22 -31
- package/src/device/waterdetector.ts +8 -11
- 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 +110 -171
- package/src/settings.ts +5 -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/fan.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 { batteryCirculatorFanServiceData, batteryCirculatorFanStatus, batteryCirculatorFanWebhookContext, bodyChange, device } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { batteryCirculatorFanServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { batteryCirculatorFanStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { batteryCirculatorFanWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -204,7 +201,8 @@ export class Fan extends deviceBase {
|
|
|
204
201
|
await this.debugLog(`Active: ${this.Fan.Active}`)
|
|
205
202
|
|
|
206
203
|
// RotationSpeed
|
|
207
|
-
this.Fan.RotationSpeed = this.serviceData.fanSpeed
|
|
204
|
+
this.Fan.RotationSpeed = this.serviceData.fanSpeed // ?? 0
|
|
205
|
+
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`)
|
|
208
206
|
}
|
|
209
207
|
|
|
210
208
|
async openAPIparseStatus() {
|
|
@@ -222,7 +220,7 @@ export class Fan extends deviceBase {
|
|
|
222
220
|
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`)
|
|
223
221
|
|
|
224
222
|
// RotationSpeed
|
|
225
|
-
this.Fan.RotationSpeed = this.deviceStatus.fanSpeed
|
|
223
|
+
this.Fan.RotationSpeed = this.deviceStatus.fanSpeed ?? 0
|
|
226
224
|
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`)
|
|
227
225
|
|
|
228
226
|
// ChargingState
|
|
@@ -271,7 +269,7 @@ export class Fan extends deviceBase {
|
|
|
271
269
|
await this.debugLog(`SwingMode: ${this.Fan.SwingMode}`)
|
|
272
270
|
|
|
273
271
|
// RotationSpeed
|
|
274
|
-
this.Fan.RotationSpeed = this.webhookContext.fanSpeed
|
|
272
|
+
this.Fan.RotationSpeed = this.webhookContext.fanSpeed // ?? 0
|
|
275
273
|
await this.debugLog(`RotationSpeed: ${this.Fan.RotationSpeed}`)
|
|
276
274
|
|
|
277
275
|
// BatteryLevel
|
|
@@ -372,17 +370,17 @@ export class Fan extends deviceBase {
|
|
|
372
370
|
async openAPIRefreshStatus(): Promise<void> {
|
|
373
371
|
await this.debugLog('openAPIRefreshStatus')
|
|
374
372
|
try {
|
|
375
|
-
const { body
|
|
376
|
-
const deviceStatus: any = await body
|
|
377
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
|
-
if (await this.successfulStatusCodes(
|
|
379
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
373
|
+
const { body } = await this.deviceRefreshStatus()
|
|
374
|
+
const deviceStatus: any = await body
|
|
375
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
376
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
377
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
380
378
|
this.deviceStatus = deviceStatus.body
|
|
381
379
|
await this.openAPIparseStatus()
|
|
382
380
|
await this.updateHomeKitCharacteristics()
|
|
383
381
|
} else {
|
|
384
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
385
|
-
await this.debugWarnLog(
|
|
382
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
383
|
+
await this.debugWarnLog(deviceStatus)
|
|
386
384
|
}
|
|
387
385
|
} catch (e: any) {
|
|
388
386
|
await this.apiError(e)
|
|
@@ -498,21 +496,20 @@ export class Fan extends deviceBase {
|
|
|
498
496
|
await this.debugLog('openAPIpushChanges')
|
|
499
497
|
if (this.Fan.Active !== this.accessory.context.Active) {
|
|
500
498
|
const command = this.Fan.Active ? 'turnOn' : 'turnOff'
|
|
501
|
-
const bodyChange =
|
|
499
|
+
const bodyChange: bodyChange = {
|
|
502
500
|
command: `${command}`,
|
|
503
501
|
parameter: 'default',
|
|
504
502
|
commandType: 'command',
|
|
505
|
-
}
|
|
503
|
+
}
|
|
506
504
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
507
505
|
try {
|
|
508
|
-
const { body
|
|
509
|
-
const deviceStatus: any = await body
|
|
510
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
511
|
-
if (await this.successfulStatusCodes(
|
|
512
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
506
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
507
|
+
const deviceStatus: any = await body
|
|
508
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
509
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
510
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
511
|
await this.updateHomeKitCharacteristics()
|
|
514
512
|
} else {
|
|
515
|
-
await this.statusCode(statusCode)
|
|
516
513
|
await this.statusCode(deviceStatus.statusCode)
|
|
517
514
|
}
|
|
518
515
|
} catch (e: any) {
|
|
@@ -527,21 +524,20 @@ export class Fan extends deviceBase {
|
|
|
527
524
|
async pushRotationSpeedChanges(): Promise<void> {
|
|
528
525
|
await this.debugLog('pushRotationSpeedChanges')
|
|
529
526
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
530
|
-
const bodyChange =
|
|
527
|
+
const bodyChange: bodyChange = {
|
|
531
528
|
command: 'setWindSpeed',
|
|
532
529
|
parameter: `${this.Fan.RotationSpeed}`,
|
|
533
530
|
commandType: 'command',
|
|
534
|
-
}
|
|
531
|
+
}
|
|
535
532
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
536
533
|
try {
|
|
537
|
-
const { body
|
|
538
|
-
const deviceStatus: any = await body
|
|
539
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
540
|
-
if (await this.successfulStatusCodes(
|
|
541
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
534
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
535
|
+
const deviceStatus: any = await body
|
|
536
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
537
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
538
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
542
539
|
await this.updateHomeKitCharacteristics()
|
|
543
540
|
} else {
|
|
544
|
-
await this.statusCode(statusCode)
|
|
545
541
|
await this.statusCode(deviceStatus.statusCode)
|
|
546
542
|
}
|
|
547
543
|
} catch (e: any) {
|
|
@@ -557,21 +553,20 @@ export class Fan extends deviceBase {
|
|
|
557
553
|
await this.debugLog('pushSwingModeChanges')
|
|
558
554
|
if (this.Fan.SwingMode !== this.accessory.context.SwingMode) {
|
|
559
555
|
const parameter = this.Fan.SwingMode === this.hap.Characteristic.SwingMode.SWING_ENABLED ? 'on' : 'off'
|
|
560
|
-
const bodyChange =
|
|
556
|
+
const bodyChange: bodyChange = {
|
|
561
557
|
command: 'setOscillation',
|
|
562
558
|
parameter: `${parameter}`,
|
|
563
559
|
commandType: 'command',
|
|
564
|
-
}
|
|
560
|
+
}
|
|
565
561
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
566
562
|
try {
|
|
567
|
-
const { body
|
|
568
|
-
const deviceStatus: any = await body
|
|
569
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
570
|
-
if (await this.successfulStatusCodes(
|
|
571
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
563
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
564
|
+
const deviceStatus: any = await body
|
|
565
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
566
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
567
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
572
568
|
await this.updateHomeKitCharacteristics()
|
|
573
569
|
} else {
|
|
574
|
-
await this.statusCode(statusCode)
|
|
575
570
|
await this.statusCode(deviceStatus.statusCode)
|
|
576
571
|
}
|
|
577
572
|
} catch (e: any) {
|
package/src/device/hub.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* hub.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, hub2ServiceData, hub2Status, hub2WebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { hub2ServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { hub2Status } from '../types/devicestatus.js'
|
|
12
|
-
import type { hub2WebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -340,17 +337,17 @@ export class Hub extends deviceBase {
|
|
|
340
337
|
async openAPIRefreshStatus(): Promise<void> {
|
|
341
338
|
await this.debugLog('openAPIRefreshStatus')
|
|
342
339
|
try {
|
|
343
|
-
const { body
|
|
344
|
-
const deviceStatus: any = await body
|
|
345
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
346
|
-
if (await this.successfulStatusCodes(
|
|
347
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
|
+
const { body } = await this.deviceRefreshStatus()
|
|
341
|
+
const deviceStatus: any = await body
|
|
342
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
344
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
348
345
|
this.deviceStatus = deviceStatus.body
|
|
349
346
|
await this.openAPIparseStatus()
|
|
350
347
|
await this.updateHomeKitCharacteristics()
|
|
351
348
|
} else {
|
|
352
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
353
|
-
await this.debugWarnLog(
|
|
349
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
350
|
+
await this.debugWarnLog(deviceStatus)
|
|
354
351
|
}
|
|
355
352
|
} catch (e: any) {
|
|
356
353
|
await this.apiError(e)
|
package/src/device/humidifier.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* humidifier.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, humidifierServiceData, humidifierStatus, humidifierWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { humidifierServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { humidifierStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { humidifierWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -370,17 +367,17 @@ export class Humidifier extends deviceBase {
|
|
|
370
367
|
async openAPIRefreshStatus(): Promise<void> {
|
|
371
368
|
await this.debugLog('openAPIRefreshStatus')
|
|
372
369
|
try {
|
|
373
|
-
const { body
|
|
374
|
-
const deviceStatus: any = await body
|
|
375
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
376
|
-
if (await this.successfulStatusCodes(
|
|
377
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
370
|
+
const { body } = await this.deviceRefreshStatus()
|
|
371
|
+
const deviceStatus: any = await body
|
|
372
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
373
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
374
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
375
|
this.deviceStatus = deviceStatus.body
|
|
379
376
|
await this.openAPIparseStatus()
|
|
380
377
|
await this.updateHomeKitCharacteristics()
|
|
381
378
|
} else {
|
|
382
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
383
|
-
await this.debugWarnLog(
|
|
379
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
380
|
+
await this.debugWarnLog(deviceStatus)
|
|
384
381
|
}
|
|
385
382
|
} catch (e: any) {
|
|
386
383
|
await this.apiError(e)
|
|
@@ -470,21 +467,20 @@ export class Humidifier extends deviceBase {
|
|
|
470
467
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)
|
|
471
468
|
&& (this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold !== this.HumidifierDehumidifier.CurrentRelativeHumidity)) {
|
|
472
469
|
await this.debugLog(`Auto Off, RelativeHumidityHumidifierThreshold: ${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}!`)
|
|
473
|
-
const bodyChange =
|
|
470
|
+
const bodyChange: bodyChange = {
|
|
474
471
|
command: 'setMode',
|
|
475
472
|
parameter: `${this.HumidifierDehumidifier.RelativeHumidityHumidifierThreshold}`,
|
|
476
473
|
commandType: 'command',
|
|
477
|
-
}
|
|
474
|
+
}
|
|
478
475
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
479
476
|
try {
|
|
480
|
-
const { body
|
|
481
|
-
const deviceStatus: any = await body
|
|
482
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
483
|
-
if (await this.successfulStatusCodes(
|
|
484
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
477
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
478
|
+
const deviceStatus: any = await body
|
|
479
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
480
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
481
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
485
482
|
await this.updateHomeKitCharacteristics()
|
|
486
483
|
} else {
|
|
487
|
-
await this.statusCode(statusCode)
|
|
488
484
|
await this.statusCode(deviceStatus.statusCode)
|
|
489
485
|
}
|
|
490
486
|
} catch (e: any) {
|
|
@@ -507,21 +503,20 @@ export class Humidifier extends deviceBase {
|
|
|
507
503
|
=== this.hap.Characteristic.TargetHumidifierDehumidifierState.HUMIDIFIER_OR_DEHUMIDIFIER)
|
|
508
504
|
&& (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.ACTIVE)) {
|
|
509
505
|
await this.debugLog('Pushing Auto')
|
|
510
|
-
const bodyChange =
|
|
506
|
+
const bodyChange: bodyChange = {
|
|
511
507
|
command: 'setMode',
|
|
512
508
|
parameter: 'auto',
|
|
513
509
|
commandType: 'command',
|
|
514
|
-
}
|
|
510
|
+
}
|
|
515
511
|
await this.debugLog(`pushAutoChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
516
512
|
try {
|
|
517
|
-
const { body
|
|
518
|
-
const deviceStatus: any = await body
|
|
519
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
520
|
-
if (await this.successfulStatusCodes(
|
|
521
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
513
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
514
|
+
const deviceStatus: any = await body
|
|
515
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
516
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
517
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
522
518
|
await this.updateHomeKitCharacteristics()
|
|
523
519
|
} else {
|
|
524
|
-
await this.statusCode(statusCode)
|
|
525
520
|
await this.statusCode(deviceStatus.statusCode)
|
|
526
521
|
}
|
|
527
522
|
} catch (e: any) {
|
|
@@ -540,21 +535,20 @@ export class Humidifier extends deviceBase {
|
|
|
540
535
|
await this.debugLog('pushActiveChanges')
|
|
541
536
|
if (this.HumidifierDehumidifier.Active === this.hap.Characteristic.Active.INACTIVE) {
|
|
542
537
|
await this.debugLog('Pushing Off')
|
|
543
|
-
const bodyChange =
|
|
538
|
+
const bodyChange: bodyChange = {
|
|
544
539
|
command: 'turnOff',
|
|
545
540
|
parameter: 'default',
|
|
546
541
|
commandType: 'command',
|
|
547
|
-
}
|
|
542
|
+
}
|
|
548
543
|
await this.debugLog(`pushActiveChanges, SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
549
544
|
try {
|
|
550
|
-
const { body
|
|
551
|
-
const deviceStatus: any = await body
|
|
552
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
553
|
-
if (await this.successfulStatusCodes(
|
|
554
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
545
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
546
|
+
const deviceStatus: any = await body
|
|
547
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
548
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
549
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
555
550
|
await this.updateHomeKitCharacteristics()
|
|
556
551
|
} else {
|
|
557
|
-
await this.statusCode(statusCode)
|
|
558
552
|
await this.statusCode(deviceStatus.statusCode)
|
|
559
553
|
}
|
|
560
554
|
} catch (e: any) {
|
package/src/device/iosensor.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* iosensor.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, outdoorMeterServiceData, outdoorMeterStatus, outdoorMeterWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { outdoorMeterServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { outdoorMeterStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { outdoorMeterWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -335,17 +332,17 @@ export class IOSensor extends deviceBase {
|
|
|
335
332
|
async openAPIRefreshStatus(): Promise<void> {
|
|
336
333
|
await this.debugLog('openAPIRefreshStatus')
|
|
337
334
|
try {
|
|
338
|
-
const { body
|
|
339
|
-
const deviceStatus: any = await body
|
|
340
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
341
|
-
if (await this.successfulStatusCodes(
|
|
342
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
|
+
const { body } = await this.deviceRefreshStatus()
|
|
336
|
+
const deviceStatus: any = await body
|
|
337
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
339
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
340
|
this.deviceStatus = deviceStatus.body
|
|
344
341
|
await this.openAPIparseStatus()
|
|
345
342
|
await this.updateHomeKitCharacteristics()
|
|
346
343
|
} else {
|
|
347
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
348
|
-
await this.debugWarnLog(
|
|
344
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
345
|
+
await this.debugWarnLog(deviceStatus)
|
|
349
346
|
}
|
|
350
347
|
} catch (e: any) {
|
|
351
348
|
await this.apiError(e)
|
package/src/device/lightstrip.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* lightstrip.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, Controller, ControllerConstructor, ControllerServiceMap, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, stripLightServiceData, stripLightStatus, stripLightWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { stripLightServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { stripLightStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { stripLightWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -362,17 +359,17 @@ export class StripLight extends deviceBase {
|
|
|
362
359
|
async openAPIRefreshStatus(): Promise<void> {
|
|
363
360
|
await this.debugLog('openAPIRefreshStatus')
|
|
364
361
|
try {
|
|
365
|
-
const { body
|
|
366
|
-
const deviceStatus: any = await body
|
|
367
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
368
|
-
if (await this.successfulStatusCodes(
|
|
369
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
362
|
+
const { body } = await this.deviceRefreshStatus()
|
|
363
|
+
const deviceStatus: any = await body
|
|
364
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
365
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
366
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
370
367
|
this.deviceStatus = deviceStatus.body
|
|
371
368
|
await this.openAPIparseStatus()
|
|
372
369
|
await this.updateHomeKitCharacteristics()
|
|
373
370
|
} else {
|
|
374
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
375
|
-
await this.debugWarnLog(
|
|
371
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
372
|
+
await this.debugWarnLog(deviceStatus)
|
|
376
373
|
}
|
|
377
374
|
} catch (e: any) {
|
|
378
375
|
await this.apiError(e)
|
|
@@ -580,21 +577,20 @@ export class StripLight extends deviceBase {
|
|
|
580
577
|
await this.debugLog('openAPIpushChanges')
|
|
581
578
|
if (this.LightBulb.On !== this.accessory.context.On) {
|
|
582
579
|
const command = this.LightBulb.On ? 'turnOn' : 'turnOff'
|
|
583
|
-
const bodyChange =
|
|
580
|
+
const bodyChange: bodyChange = {
|
|
584
581
|
command: `${command}`,
|
|
585
582
|
parameter: 'default',
|
|
586
583
|
commandType: 'command',
|
|
587
|
-
}
|
|
584
|
+
}
|
|
588
585
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
589
586
|
try {
|
|
590
|
-
const { body
|
|
591
|
-
const deviceStatus: any = await body
|
|
592
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
593
|
-
if (await this.successfulStatusCodes(
|
|
594
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
587
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
588
|
+
const deviceStatus: any = await body
|
|
589
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
590
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
591
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
595
592
|
await this.updateHomeKitCharacteristics()
|
|
596
593
|
} else {
|
|
597
|
-
await this.statusCode(statusCode)
|
|
598
594
|
await this.statusCode(deviceStatus.statusCode)
|
|
599
595
|
}
|
|
600
596
|
} catch (e: any) {
|
|
@@ -612,21 +608,20 @@ export class StripLight extends deviceBase {
|
|
|
612
608
|
await this.debugLog(`Hue: ${JSON.stringify(this.LightBulb.Hue)}, Saturation: ${JSON.stringify(this.LightBulb.Saturation)}`)
|
|
613
609
|
const [red, green, blue] = hs2rgb(this.LightBulb.Hue, this.LightBulb.Saturation)
|
|
614
610
|
await this.debugLog(`rgb: ${JSON.stringify([red, green, blue])}`)
|
|
615
|
-
const bodyChange =
|
|
611
|
+
const bodyChange: bodyChange = {
|
|
616
612
|
command: 'setColor',
|
|
617
613
|
parameter: `${red}:${green}:${blue}`,
|
|
618
614
|
commandType: 'command',
|
|
619
|
-
}
|
|
615
|
+
}
|
|
620
616
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
621
617
|
try {
|
|
622
|
-
const { body
|
|
623
|
-
const deviceStatus: any = await body
|
|
624
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
625
|
-
if (await this.successfulStatusCodes(
|
|
626
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
618
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
619
|
+
const deviceStatus: any = await body
|
|
620
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
621
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
622
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
627
623
|
await this.updateHomeKitCharacteristics()
|
|
628
624
|
} else {
|
|
629
|
-
await this.statusCode(statusCode)
|
|
630
625
|
await this.statusCode(deviceStatus.statusCode)
|
|
631
626
|
}
|
|
632
627
|
} catch (e: any) {
|
|
@@ -641,21 +636,20 @@ export class StripLight extends deviceBase {
|
|
|
641
636
|
async pushBrightnessChanges(): Promise<void> {
|
|
642
637
|
await this.debugLog('pushBrightnessChanges')
|
|
643
638
|
if (this.LightBulb.Brightness !== this.accessory.context.Brightness) {
|
|
644
|
-
const bodyChange =
|
|
639
|
+
const bodyChange: bodyChange = {
|
|
645
640
|
command: 'setBrightness',
|
|
646
641
|
parameter: `${this.LightBulb.Brightness}`,
|
|
647
642
|
commandType: 'command',
|
|
648
|
-
}
|
|
643
|
+
}
|
|
649
644
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
650
645
|
try {
|
|
651
|
-
const { body
|
|
652
|
-
const deviceStatus: any = await body
|
|
653
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
654
|
-
if (await this.successfulStatusCodes(
|
|
655
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
646
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
647
|
+
const deviceStatus: any = await body
|
|
648
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
649
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
650
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
656
651
|
await this.updateHomeKitCharacteristics()
|
|
657
652
|
} else {
|
|
658
|
-
await this.statusCode(statusCode)
|
|
659
653
|
await this.statusCode(deviceStatus.statusCode)
|
|
660
654
|
}
|
|
661
655
|
} catch (e: any) {
|
package/src/device/lock.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* lock.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { bodyChange, device, lockProServiceData, lockProStatus, lockProWebhookContext, lockServiceData, lockStatus, lockWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { lockProServiceData, lockServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { lockProStatus, lockStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { lockProWebhookContext, lockWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -222,7 +219,7 @@ export class Lock extends deviceBase {
|
|
|
222
219
|
|
|
223
220
|
// Contact Sensor
|
|
224
221
|
if (!this.device.lock?.hide_contactsensor && this.ContactSensor?.Service) {
|
|
225
|
-
this.ContactSensor.ContactSensorState = this.serviceData.door_open
|
|
222
|
+
this.ContactSensor.ContactSensorState = this.serviceData.door_open
|
|
226
223
|
? this.hap.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
|
|
227
224
|
: this.hap.Characteristic.ContactSensorState.CONTACT_DETECTED
|
|
228
225
|
await this.debugLog(`ContactSensorState: ${this.ContactSensor.ContactSensorState}`)
|
|
@@ -375,17 +372,17 @@ export class Lock extends deviceBase {
|
|
|
375
372
|
async openAPIRefreshStatus(): Promise<void> {
|
|
376
373
|
await this.debugLog('openAPIRefreshStatus')
|
|
377
374
|
try {
|
|
378
|
-
const { body
|
|
379
|
-
const deviceStatus: any = await body
|
|
380
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
381
|
-
if (await this.successfulStatusCodes(
|
|
382
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
375
|
+
const { body } = await this.deviceRefreshStatus()
|
|
376
|
+
const deviceStatus: any = await body
|
|
377
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
378
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
379
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
383
380
|
this.deviceStatus = deviceStatus.body
|
|
384
381
|
await this.openAPIparseStatus()
|
|
385
382
|
await this.updateHomeKitCharacteristics()
|
|
386
383
|
} else {
|
|
387
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
388
|
-
await this.debugWarnLog(
|
|
384
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
385
|
+
await this.debugWarnLog(deviceStatus)
|
|
389
386
|
}
|
|
390
387
|
} catch (e: any) {
|
|
391
388
|
await this.apiError(e)
|
|
@@ -486,21 +483,20 @@ export class Lock extends deviceBase {
|
|
|
486
483
|
if ((this.LockMechanism.LockTargetState !== this.accessory.context.LockTargetState) || LatchUnlock) {
|
|
487
484
|
// Determine the command based on the LockTargetState or the forceUnlock parameter
|
|
488
485
|
const command = LatchUnlock ? 'unlock' : this.LockMechanism.LockTargetState ? 'lock' : 'unlock'
|
|
489
|
-
const bodyChange =
|
|
486
|
+
const bodyChange: bodyChange = {
|
|
490
487
|
command: `${command}`,
|
|
491
488
|
parameter: 'default',
|
|
492
489
|
commandType: 'command',
|
|
493
|
-
}
|
|
490
|
+
}
|
|
494
491
|
await this.debugLog(`SwitchBot OpenAPI bodyChange: ${JSON.stringify(bodyChange)}`)
|
|
495
492
|
try {
|
|
496
|
-
const { body
|
|
497
|
-
const deviceStatus: any = await body
|
|
498
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
499
|
-
if (await this.successfulStatusCodes(
|
|
500
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
493
|
+
const { body } = await this.pushChangeRequest(bodyChange)
|
|
494
|
+
const deviceStatus: any = await body
|
|
495
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
496
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
497
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
501
498
|
await this.updateHomeKitCharacteristics()
|
|
502
499
|
} else {
|
|
503
|
-
await this.statusCode(statusCode)
|
|
504
500
|
await this.statusCode(deviceStatus.statusCode)
|
|
505
501
|
}
|
|
506
502
|
} catch (e: any) {
|
package/src/device/meter.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* meter.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, meterServiceData, meterStatus, meterWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { meterServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { meterStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { meterWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -330,17 +327,17 @@ export class Meter extends deviceBase {
|
|
|
330
327
|
async openAPIRefreshStatus(): Promise<void> {
|
|
331
328
|
await this.debugLog('openAPIRefreshStatus')
|
|
332
329
|
try {
|
|
333
|
-
const { body
|
|
334
|
-
const deviceStatus: any = await body
|
|
335
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
336
|
-
if (await this.successfulStatusCodes(
|
|
337
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
330
|
+
const { body } = await this.deviceRefreshStatus()
|
|
331
|
+
const deviceStatus: any = await body
|
|
332
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
333
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
334
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
335
|
this.deviceStatus = deviceStatus.body
|
|
339
336
|
await this.openAPIparseStatus()
|
|
340
337
|
await this.updateHomeKitCharacteristics()
|
|
341
338
|
} else {
|
|
342
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
343
|
-
await this.debugWarnLog(
|
|
339
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
|
+
await this.debugWarnLog(deviceStatus)
|
|
344
341
|
}
|
|
345
342
|
} catch (e: any) {
|
|
346
343
|
await this.apiError(e)
|
package/src/device/meterplus.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* meterplus.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, meterPlusServiceData, meterPlusStatus, meterPlusWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { meterPlusServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { meterPlusStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { meterPlusWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
import { Units } from 'homebridge'
|
|
15
12
|
/*
|
|
@@ -332,17 +329,17 @@ export class MeterPlus extends deviceBase {
|
|
|
332
329
|
async openAPIRefreshStatus(): Promise<void> {
|
|
333
330
|
await this.debugLog('openAPIRefreshStatus')
|
|
334
331
|
try {
|
|
335
|
-
const { body
|
|
336
|
-
const deviceStatus: any = await body
|
|
337
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
338
|
-
if (await this.successfulStatusCodes(
|
|
339
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
332
|
+
const { body } = await this.deviceRefreshStatus()
|
|
333
|
+
const deviceStatus: any = await body
|
|
334
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
335
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
336
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
340
337
|
this.deviceStatus = deviceStatus.body
|
|
341
338
|
await this.openAPIparseStatus()
|
|
342
339
|
await this.updateHomeKitCharacteristics()
|
|
343
340
|
} else {
|
|
344
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
345
|
-
await this.debugWarnLog(
|
|
341
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
342
|
+
await this.debugWarnLog(deviceStatus)
|
|
346
343
|
}
|
|
347
344
|
} catch (e: any) {
|
|
348
345
|
await this.apiError(e)
|