@switchbot/homebridge-switchbot 4.0.0-beta.0 → 4.0.0-beta.2

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.
@@ -5,7 +5,7 @@
5
5
 
6
6
  import type { API, CharacteristicValue, HAP, Logging, PlatformAccessory, Service } from 'homebridge'
7
7
  import type { MqttClient } from 'mqtt'
8
- import type { ad, bodyChange, device } from 'node-switchbot'
8
+ import type { ad, bodyChange, device, deviceStatus, deviceStatusRequest, pushResponse } from 'node-switchbot'
9
9
 
10
10
  import type { SwitchBotPlatform } from '../platform.js'
11
11
  import type { blindTiltConfig, botConfig, ceilingLightConfig, colorBulbConfig, contactConfig, curtainConfig, devicesConfig, hubConfig, humidifierConfig, indoorOutdoorSensorConfig, lockConfig, meterConfig, motionConfig, stripLightConfig, SwitchBotPlatformConfig, waterDetectorConfig } from '../settings.js'
@@ -379,17 +379,17 @@ export abstract class deviceBase {
379
379
  }
380
380
  }
381
381
 
382
- async pushChangeRequest(bodyChange: bodyChange): Promise<{ body: any, statusCode: number }> {
382
+ async pushChangeRequest(bodyChange: bodyChange): Promise<{ body: pushResponse['body'], statusCode: pushResponse['statusCode'] }> {
383
383
  const { response, statusCode } = await this.platform.switchBotAPI.controlDevice(this.device.deviceId, bodyChange.command, bodyChange.parameter, bodyChange.commandType)
384
384
  return { body: response, statusCode }
385
385
  }
386
386
 
387
- async deviceRefreshStatus(): Promise<{ body: any, statusCode: number }> {
387
+ async deviceRefreshStatus(): Promise<{ body: deviceStatus, statusCode: deviceStatusRequest['statusCode'] }> {
388
388
  const { response, statusCode } = await this.platform.retryRequest(this.device.deviceId, this.deviceMaxRetries, this.deviceDelayBetweenRetries)
389
389
  return { body: response, statusCode }
390
390
  }
391
391
 
392
- async successfulStatusCodes(deviceStatus: any) {
392
+ async successfulStatusCodes(deviceStatus: deviceStatusRequest) {
393
393
  return (deviceStatus.statusCode === 200 || deviceStatus.statusCode === 100)
394
394
  }
395
395
 
package/src/platform.ts CHANGED
@@ -20,7 +20,7 @@ import { EveHomeKitTypes } from 'homebridge-lib/EveHomeKitTypes'
20
20
  * import type { blindTilt, curtain, curtain3, device, irdevice } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
21
21
  * import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
22
22
  */
23
- import type { blindTilt, curtain, curtain3, device, irdevice } from 'node-switchbot'
23
+ import type { blindTilt, curtain, curtain3, device, deviceStatus, deviceStatusRequest, irdevice } from 'node-switchbot'
24
24
 
25
25
  import { LogLevel, SwitchBotBLE, SwitchBotModel, SwitchBotOpenAPI } from 'node-switchbot'
26
26
  import { queueScheduler } from 'rxjs'
@@ -2534,7 +2534,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2534
2534
  }
2535
2535
  }
2536
2536
 
2537
- async retryRequest(deviceId: string, deviceMaxRetries: number, deviceDelayBetweenRetries: number): Promise<{ response: any, statusCode: number }> {
2537
+ async retryRequest(deviceId: string, deviceMaxRetries: number, deviceDelayBetweenRetries: number): Promise<{ response: deviceStatus, statusCode: deviceStatusRequest['statusCode'] }> {
2538
2538
  let retryCount = 0
2539
2539
  const maxRetries = deviceMaxRetries
2540
2540
  const delayBetweenRetries = deviceDelayBetweenRetries
@@ -2550,7 +2550,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2550
2550
  await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`)
2551
2551
  await sleep(delayBetweenRetries)
2552
2552
  }
2553
- return { response: null, statusCode: 500 }
2553
+ return { response: {
2554
+ deviceId: '',
2555
+ deviceType: '',
2556
+ hubDeviceId: '',
2557
+ version: 0,
2558
+ deviceName: '',
2559
+ enableCloudService: false,
2560
+ }, statusCode: 500 }
2554
2561
  }
2555
2562
 
2556
2563
  // BLE Connection