@switchbot/homebridge-switchbot 4.3.7 → 4.3.9

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/src/platform.ts CHANGED
@@ -26,6 +26,7 @@ import { CeilingLight } from './device/ceilinglight.js'
26
26
  import { ColorBulb } from './device/colorbulb.js'
27
27
  import { Contact } from './device/contact.js'
28
28
  import { Curtain } from './device/curtain.js'
29
+ import { AirPurifier as AirPurifierDevice } from './device/airpurifier.js'
29
30
  import { Fan } from './device/fan.js'
30
31
  import { Hub } from './device/hub.js'
31
32
  import { Humidifier } from './device/humidifier.js'
@@ -618,6 +619,12 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
618
619
  'Ceiling Light Pro': this.createCeilingLight.bind(this),
619
620
  'Strip Light': this.createStripLight.bind(this),
620
621
  'Battery Circulator Fan': this.createFan.bind(this),
622
+ 'Air Purifier': this.createAirPurifierDevice.bind(this),
623
+ 'Air Purifier Table': this.createAirPurifierDevice.bind(this),
624
+ 'Air Purifier VOC': this.createAirPurifierDevice.bind(this),
625
+ 'Air Purifier Table VOC': this.createAirPurifierDevice.bind(this),
626
+ 'Air Purifier PM2.5': this.createAirPurifierDevice.bind(this),
627
+ 'Air Purifier Table PM2.5': this.createAirPurifierDevice.bind(this),
621
628
  }
622
629
 
623
630
  if (deviceTypeHandlers[device.deviceType!]) {
@@ -1955,6 +1962,67 @@ export class SwitchBotPlatform implements DynamicPlatformPlugin {
1955
1962
  }
1956
1963
  }
1957
1964
 
1965
+ private async createAirPurifierDevice(device: device & devicesConfig) {
1966
+ const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1967
+
1968
+ // see if an accessory with the same uuid has already been registered and restored from
1969
+ // the cached devices we stored in the `configureAccessory` method above
1970
+ const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid)
1971
+
1972
+ if (existingAccessory) {
1973
+ // the accessory already exists
1974
+ if (await this.registerDevice(device)) {
1975
+ // if you need to update the accessory.context then you should run `api.updatePlatformAccessories`. eg.:
1976
+ existingAccessory.context.device = device
1977
+ existingAccessory.context.deviceId = device.deviceId
1978
+ existingAccessory.context.deviceType = device.deviceType
1979
+ existingAccessory.context.model = device.deviceType?.includes('Table') ? SwitchBotModel.AirPurifierTable : SwitchBotModel.AirPurifier
1980
+ existingAccessory.displayName = device.configDeviceName
1981
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1982
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
1983
+ existingAccessory.context.connectionType = await this.connectionType(device)
1984
+ existingAccessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
1985
+ this.infoLog(`Restoring existing accessory from cache: ${existingAccessory.displayName} deviceId: ${device.deviceId}`)
1986
+ this.api.updatePlatformAccessories([existingAccessory])
1987
+ // create the accessory handler for the restored accessory
1988
+ // this is imported from `platformAccessory.ts`
1989
+ new AirPurifierDevice(this, existingAccessory, device)
1990
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${existingAccessory.UUID})`)
1991
+ } else {
1992
+ this.unregisterPlatformAccessories(existingAccessory)
1993
+ }
1994
+ } else if (await this.registerDevice(device)) {
1995
+ // create a new accessory
1996
+ const accessory = new this.api.platformAccessory(device.configDeviceName
1997
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
1998
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName), uuid)
1999
+
2000
+ // store a copy of the device object in the `accessory.context`
2001
+ // the `context` property can be used to store any data about the accessory you may need
2002
+ accessory.context.device = device
2003
+ accessory.context.deviceId = device.deviceId
2004
+ accessory.context.deviceType = device.deviceType
2005
+ accessory.context.model = device.deviceType?.includes('Table') ? SwitchBotModel.AirPurifierTable : SwitchBotModel.AirPurifier
2006
+ accessory.displayName = device.configDeviceName
2007
+ ? await this.validateAndCleanDisplayName(device.configDeviceName, 'configDeviceName', device.configDeviceName)
2008
+ : await this.validateAndCleanDisplayName(device.deviceName, 'deviceName', device.deviceName)
2009
+ accessory.context.connectionType = await this.connectionType(device)
2010
+ accessory.context.version = device.firmware ?? device.version ?? this.version ?? '0.0.0'
2011
+ const newOrExternal = !device.external ? 'Adding new' : 'Loading external'
2012
+ this.infoLog(`${newOrExternal} accessory: ${accessory.displayName} deviceId: ${device.deviceId}`)
2013
+ // create the accessory handler for the newly create accessory
2014
+ // this is imported from `platformAccessory.ts`
2015
+ new AirPurifierDevice(this, accessory, device)
2016
+ this.debugLog(`${device.deviceType} uuid: ${device.deviceId}-${device.deviceType}, (${accessory.UUID})`)
2017
+
2018
+ // publish device externally or link the accessory to your platform
2019
+ this.externalOrPlatform(device, accessory)
2020
+ this.accessories.push(accessory)
2021
+ } else {
2022
+ this.debugLog(`Device not registered: ${device.deviceName} ${device.deviceType} deviceId: ${device.deviceId}`)
2023
+ }
2024
+ }
2025
+
1958
2026
  private async createRobotVacuumCleaner(device: device & devicesConfig) {
1959
2027
  const uuid = this.api.hap.uuid.generate(`${device.deviceId}-${device.deviceType}`)
1960
2028
 
package/src/settings.ts CHANGED
@@ -53,7 +53,7 @@ export interface options {
53
53
  logging?: string
54
54
  };
55
55
 
56
- export type devicesConfig = botConfig | relaySwitch1Config | relaySwitch1PMConfig | meterConfig | meterProConfig | indoorOutdoorSensorConfig | humidifierConfig | curtainConfig | blindTiltConfig | contactConfig | motionConfig | waterDetectorConfig | plugConfig | colorBulbConfig | stripLightConfig | ceilingLightConfig | lockConfig | hubConfig
56
+ export type devicesConfig = botConfig | relaySwitch1Config | relaySwitch1PMConfig | meterConfig | meterProConfig | indoorOutdoorSensorConfig | humidifierConfig | curtainConfig | blindTiltConfig | contactConfig | motionConfig | waterDetectorConfig | plugConfig | colorBulbConfig | stripLightConfig | ceilingLightConfig | lockConfig | hubConfig | airPurifierConfig
57
57
 
58
58
  export interface BaseDeviceConfig extends device {
59
59
  bleMac?: string
@@ -224,7 +224,7 @@ export interface lockConfig extends BaseDeviceConfig {
224
224
  };
225
225
 
226
226
  export interface hubConfig extends BaseDeviceConfig {
227
- configDeviceType: 'Hub 2'
227
+ configDeviceType: 'Hub 2' | 'Hub 3'
228
228
  hide_temperature?: boolean
229
229
  convertUnitTo?: string
230
230
  hide_humidity?: boolean
@@ -233,6 +233,10 @@ export interface hubConfig extends BaseDeviceConfig {
233
233
  set_maxLux?: number
234
234
  };
235
235
 
236
+ export interface airPurifierConfig extends BaseDeviceConfig {
237
+ configDeviceType: 'Air Purifier' | 'Air Purifier Table' | 'Air Purifier VOC' | 'Air Purifier Table VOC' | 'Air Purifier PM2.5' | 'Air Purifier Table PM2.5'
238
+ };
239
+
236
240
  export type irDevicesConfig = irFanConfig | irLightConfig | irAirConfig | irOtherConfig
237
241
 
238
242
  export interface irBaseDeviceConfig extends irdevice {