@switchbot/homebridge-switchbot 3.8.3-beta.2 → 3.8.3-beta.21
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 +2 -1
- package/CHANGELOG.md +8 -0
- 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 +28 -31
- 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 +5 -14
- package/dist/platform.d.ts.map +1 -1
- package/dist/platform.js +53 -161
- 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/package.json +9 -10
- 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 +29 -35
- 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 +55 -161
- package/src/settings.ts +1 -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/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)
|
package/src/device/motion.ts
CHANGED
|
@@ -3,13 +3,10 @@
|
|
|
3
3
|
* motion.ts: @switchbot/homebridge-switchbot.
|
|
4
4
|
*/
|
|
5
5
|
import type { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'
|
|
6
|
+
import type { device, motionSensorServiceData, motionSensorStatus, motionSensorWebhookContext } from 'node-switchbot'
|
|
6
7
|
|
|
7
8
|
import type { SwitchBotPlatform } from '../platform.js'
|
|
8
9
|
import type { devicesConfig } from '../settings.js'
|
|
9
|
-
import type { motionSensorServiceData } from '../types/bledevicestatus.js'
|
|
10
|
-
import type { device } from '../types/devicelist.js'
|
|
11
|
-
import type { motionSensorStatus } from '../types/devicestatus.js'
|
|
12
|
-
import type { motionSensorWebhookContext } from '../types/devicewebhookstatus.js'
|
|
13
10
|
|
|
14
11
|
/*
|
|
15
12
|
* For Testing Locally:
|
|
@@ -307,17 +304,17 @@ export class Motion extends deviceBase {
|
|
|
307
304
|
async openAPIRefreshStatus(): Promise<void> {
|
|
308
305
|
await this.debugLog('openAPIRefreshStatus')
|
|
309
306
|
try {
|
|
310
|
-
const { body
|
|
311
|
-
const deviceStatus: any = await body
|
|
312
|
-
await this.debugLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
313
|
-
if (await this.successfulStatusCodes(
|
|
314
|
-
await this.debugSuccessLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
307
|
+
const { body } = await this.deviceRefreshStatus()
|
|
308
|
+
const deviceStatus: any = await body
|
|
309
|
+
await this.debugLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
310
|
+
if (await this.successfulStatusCodes(deviceStatus)) {
|
|
311
|
+
await this.debugSuccessLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
315
312
|
this.deviceStatus = deviceStatus.body
|
|
316
313
|
await this.openAPIparseStatus()
|
|
317
314
|
await this.updateHomeKitCharacteristics()
|
|
318
315
|
} else {
|
|
319
|
-
await this.debugWarnLog(`statusCode: ${statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
320
|
-
await this.debugWarnLog(
|
|
316
|
+
await this.debugWarnLog(`statusCode: ${deviceStatus.statusCode}, deviceStatus: ${JSON.stringify(deviceStatus)}`)
|
|
317
|
+
await this.debugWarnLog(deviceStatus)
|
|
321
318
|
}
|
|
322
319
|
} catch (e: any) {
|
|
323
320
|
await this.apiError(e)
|
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:
|
|
@@ -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)
|
|
@@ -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) {
|