@switchbot/homebridge-switchbot 4.0.0-beta.1 → 4.0.0-beta.3

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'
@@ -113,7 +113,6 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
113
113
  credentials: config.credentials as object,
114
114
  options: config.options as object,
115
115
  devices: config.devices as { deviceId: string }[],
116
- deviceConfig: config.deviceConfig as { [deviceType: string]: devicesConfig },
117
116
  }
118
117
 
119
118
  // Plugin Configuration
@@ -615,9 +614,11 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
615
614
  'Battery Circulator Fan': this.createFan.bind(this),
616
615
  }
617
616
 
617
+ const deviceConfig = this.config.options?.deviceConfig?.[device.deviceType] || {}
618
+
618
619
  if (deviceTypeHandlers[device.deviceType!]) {
619
620
  await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}`)
620
- await deviceTypeHandlers[device.deviceType!](device)
621
+ await deviceTypeHandlers[device.deviceType!]({ ...device, ...deviceConfig })
621
622
  } else if (['Hub Mini', 'Hub Plus', 'Remote', 'Indoor Cam', 'remote with screen'].includes(device.deviceType!)) {
622
623
  await this.debugLog(`Discovered ${device.deviceType}: ${device.deviceId}, is currently not supported, device: ${JSON.stringify(device)}`)
623
624
  } else {
@@ -2534,7 +2535,7 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2534
2535
  }
2535
2536
  }
2536
2537
 
2537
- async retryRequest(deviceId: string, deviceMaxRetries: number, deviceDelayBetweenRetries: number): Promise<{ response: any, statusCode: number }> {
2538
+ async retryRequest(deviceId: string, deviceMaxRetries: number, deviceDelayBetweenRetries: number): Promise<{ response: deviceStatus, statusCode: deviceStatusRequest['statusCode'] }> {
2538
2539
  let retryCount = 0
2539
2540
  const maxRetries = deviceMaxRetries
2540
2541
  const delayBetweenRetries = deviceDelayBetweenRetries
@@ -2550,7 +2551,14 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
2550
2551
  await this.debugLog(`Retry attempt ${retryCount} of ${maxRetries}`)
2551
2552
  await sleep(delayBetweenRetries)
2552
2553
  }
2553
- return { response: null, statusCode: 500 }
2554
+ return { response: {
2555
+ deviceId: '',
2556
+ deviceType: '',
2557
+ hubDeviceId: '',
2558
+ version: 0,
2559
+ deviceName: '',
2560
+ enableCloudService: false,
2561
+ }, statusCode: 500 }
2554
2562
  }
2555
2563
 
2556
2564
  // BLE Connection
package/src/settings.ts CHANGED
@@ -23,7 +23,6 @@ export const PLUGIN_NAME = '@switchbot/homebridge-switchbot'
23
23
  export interface SwitchBotPlatformConfig extends PlatformConfig {
24
24
  credentials?: credentials
25
25
  options?: options
26
- deviceConfig?: { [deviceType: string]: devicesConfig }
27
26
  }
28
27
  interface credentials {
29
28
  token?: string
@@ -33,6 +32,7 @@ interface credentials {
33
32
 
34
33
  export interface options {
35
34
  devices?: devicesConfig[]
35
+ deviceConfig?: { [deviceType: string]: devicesConfig }
36
36
  irdevices?: irDevicesConfig[]
37
37
  allowInvalidCharacters?: boolean
38
38
  mqttURL?: string
@@ -132,7 +132,7 @@ export interface curtainConfig extends BaseDeviceConfig {
132
132
  export interface blindTiltConfig extends BaseDeviceConfig {
133
133
  configDeviceType: 'Blind Tilt'
134
134
  disable_group?: boolean
135
- mode?: string
135
+ mapping?: string
136
136
  hide_lightsensor?: boolean
137
137
  set_minLux?: number
138
138
  set_maxLux?: number