All files / src settings.ts

100% Statements 25/25
100% Branches 0/0
100% Functions 0/0
100% Lines 25/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284                            1x         1x                                                                   1x                                                                                       1x           1x           1x             1x               1x             1x             1x                           1x                             1x               1x             1x           1x       1x           1x           1x           1x           1x                   1x                                                                   1x         1x                       1x         1x  
/* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
 *
 * settings.ts: @switchbot/homebridge-switchbot platform class.
 */
import type { IClientOptions } from 'async-mqtt'
import type { PlatformConfig } from 'homebridge'
/*
* For Testing Locally:
* import type { device, irdevice, SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '/Users/Shared/GitHub/OpenWonderLabs/node-switchbot/dist/index.js';
*/
import type { device, irdevice, SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName, SwitchBotModel } from 'node-switchbot'
/**
 * This is the name of the platform that users will use to register the plugin in the Homebridge config.json
 */
export const PLATFORM_NAME = 'SwitchBot'
 
/**
 * This must match the name of your plugin as defined the package.json
 */
export const PLUGIN_NAME = '@switchbot/homebridge-switchbot'
 
// Config
export interface SwitchBotPlatformConfig extends PlatformConfig {
  credentials?: credentials
  options?: options
}
interface credentials {
  token?: string
  secret?: string
  notice?: string
}
 
export interface options {
  devices?: devicesConfig[]
  deviceConfig?: { [deviceType: string]: devicesConfig }
  irdevices?: irDevicesConfig[]
  irdeviceConfig?: { [remoteType: string]: irDevicesConfig }
  allowInvalidCharacters?: boolean
  mqttURL?: string
  mqttOptions?: IClientOptions
  mqttPubOptions?: IClientOptions
  BLE?: boolean
  discoverBLE?: boolean
  disableLogsforBLE?: boolean
  disableLogsforOpenAPI?: boolean
  hostname?: string
  webhookURL?: string
  maxRetries?: number
  delayBetweenRetries?: number
  refreshRate?: number
  updateRate?: number
  pushRate?: number
  logging?: string
};
 
export type devicesConfig = botConfig | relaySwitch1Config | relaySwitch1PMConfig | meterConfig | meterProConfig | indoorOutdoorSensorConfig | humidifierConfig | curtainConfig | blindTiltConfig | contactConfig | motionConfig | waterDetectorConfig | plugConfig | colorBulbConfig | stripLightConfig | ceilingLightConfig | lockConfig | hubConfig
 
export interface BaseDeviceConfig extends device {
  bleMac?: string
  model: SwitchBotModel
  bleModel: SwitchBotBLEModel
  bleModelName: SwitchBotBLEModelName
  bleModelFriednlyName: SwitchBotBLEModelFriendlyName
  configDeviceType: string
  configDeviceName?: string
  deviceId: string
  external?: boolean
  refreshRate?: number
  updateRate?: number
  pushRate?: number
  firmware?: string
  logging?: string
  connectionType?: string
  customBLEaddress?: string
  scanDuration?: number
  hide_device?: boolean
  offline?: boolean
  maxRetry?: number
  maxRetries?: number
  delayBetweenRetries?: number
  disableCaching?: boolean
  disablePlatformBLE?: boolean
  mqttURL?: string
  mqttOptions?: IClientOptions
  mqttPubOptions?: IClientOptions
  history?: boolean
  webhook?: boolean
}
 
export interface botConfig extends BaseDeviceConfig {
  configDeviceType: 'Bot'
  mode?: string
  type: string
  doublePress?: number
  pushRatePress?: number
  allowPush?: boolean
  multiPress?: boolean
};
 
export interface relaySwitch1Config extends BaseDeviceConfig {
  configDeviceType: 'Relay Switch 1'
  type: string
  allowPush?: boolean
};
 
export interface relaySwitch1PMConfig extends BaseDeviceConfig {
  configDeviceType: 'Relay Switch 1PM'
  type: string
  allowPush?: boolean
};
 
export interface meterConfig extends BaseDeviceConfig {
  configDeviceType: 'Meter' | 'MeterPlus'
  hide_temperature?: boolean
  convertUnitTo?: string
  hide_humidity?: boolean
};
 
export interface meterProConfig extends BaseDeviceConfig {
  configDeviceType: 'Meter Pro' | 'MeterPro(CO2)'
  hide_temperature?: boolean
  convertUnitTo?: string
  hide_humidity?: boolean
  hide_co2?: boolean
};
 
export interface indoorOutdoorSensorConfig extends BaseDeviceConfig {
  configDeviceType: 'WoIOSensor'
  hide_temperature?: boolean
  convertUnitTo?: string
  hide_humidity?: boolean
};
 
export interface humidifierConfig extends BaseDeviceConfig {
  configDeviceType: 'Humidifier' | 'Humidifier2'
  hide_temperature?: boolean
  convertUnitTo?: string
  set_minStep?: number
};
 
export interface curtainConfig extends BaseDeviceConfig {
  configDeviceType: 'Curtain' | 'Curtain3' | 'WoRollerShade' | 'Roller Shade'
  disable_group?: boolean
  hide_lightsensor?: boolean
  set_minLux?: number
  set_maxLux?: number
  set_max?: number
  set_min?: number
  set_minStep?: number
  setCloseMode?: string
  setOpenMode?: string
  silentModeSwitch?: boolean
};
 
export interface blindTiltConfig extends BaseDeviceConfig {
  configDeviceType: 'Blind Tilt'
  disable_group?: boolean
  mapping?: string
  hide_lightsensor?: boolean
  set_minLux?: number
  set_maxLux?: number
  set_max?: number
  set_min?: number
  set_minStep?: number
  setCloseMode?: string
  setOpenMode?: string
  silentModeSwitch?: boolean
};
 
export interface contactConfig extends BaseDeviceConfig {
  configDeviceType: 'Contact Sensor'
  hide_lightsensor?: boolean
  set_minLux?: number
  set_maxLux?: number
  hide_motionsensor?: boolean
};
 
export interface motionConfig extends BaseDeviceConfig {
  configDeviceType: 'Motion Sensor'
  hide_lightsensor?: boolean
  set_minLux?: number
  set_maxLux?: number
};
 
export interface waterDetectorConfig extends BaseDeviceConfig {
  configDeviceType: 'Water Detector'
  hide_leak?: boolean
  dry?: boolean
};
 
export interface plugConfig extends BaseDeviceConfig {
  configDeviceType: 'Plug' | 'Plug Mini (US)' | 'Plug Mini (JP)'
};
 
export interface colorBulbConfig extends BaseDeviceConfig {
  configDeviceType: 'Color Bulb'
  set_minStep?: number
  adaptiveLightingShift?: number
};
 
export interface stripLightConfig extends BaseDeviceConfig {
  configDeviceType: 'Strip Light'
  set_minStep?: number
  adaptiveLightingShift?: number
};
 
export interface ceilingLightConfig extends BaseDeviceConfig {
  configDeviceType: 'Ceiling Light' | 'Ceiling Light Pro'
  set_minStep?: number
  adaptiveLightingShift?: number
};
 
export interface lockConfig extends BaseDeviceConfig {
  configDeviceType: 'Smart Lock' | 'Smart Lock Pro'
  hide_contactsensor?: boolean
  activate_latchbutton?: boolean
};
 
export interface hubConfig extends BaseDeviceConfig {
  configDeviceType: 'Hub 2'
  hide_temperature?: boolean
  convertUnitTo?: string
  hide_humidity?: boolean
  hide_lightsensor?: boolean
  set_minLux?: number
  set_maxLux?: number
};
 
export type irDevicesConfig = irFanConfig | irLightConfig | irAirConfig | irOtherConfig
 
export interface irBaseDeviceConfig extends irdevice {
  configDeviceName?: string
  configRemoteType?: string
  connectionType?: string
  hide_device?: boolean
  external?: boolean
  refreshRate?: number
  updateRate?: number
  pushRate?: number
  maxRetries?: number
  delayBetweenRetries?: number
  firmware?: string
  deviceId: string
  logging?: string
  customOn?: string
  customOff?: string
  customize?: boolean
  commandType?: string
  disablePushOn?: boolean
  disablePushOff?: boolean
  disablePushDetail?: boolean
}
 
export interface irFanConfig extends irBaseDeviceConfig {
  configRemoteType?: 'Fan' | 'DIY Fan'
  swing_mode?: boolean
  rotation_speed?: boolean
  set_minStep?: number
  set_max?: number
  set_min?: number
};
 
export interface irLightConfig extends irBaseDeviceConfig {
  configRemoteType?: 'Light' | 'DIY Light'
  stateless?: boolean
};
 
export interface irAirConfig extends irBaseDeviceConfig {
  configRemoteType?: 'Air Conditioner' | 'DIY Air Conditioner'
  hide_automode?: boolean
  set_max_heat?: number
  set_min_heat?: number
  set_max_cool?: number
  set_min_cool?: number
  meterType?: string
  meterId?: string
  meterUuid?: string
};
 
export interface irOtherConfig extends irBaseDeviceConfig {
  configRemoteType?: 'Others'
  type?: string
};