@switchbot/homebridge-switchbot 3.5.0-beta.6 → 3.5.0-beta.60

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.
Files changed (177) hide show
  1. package/.vscode/settings.json +4 -1
  2. package/CHANGELOG.md +4 -1
  3. package/config.schema.json +120 -17
  4. package/dist/device/blindtilt.d.ts +23 -96
  5. package/dist/device/blindtilt.d.ts.map +1 -1
  6. package/dist/device/blindtilt.js +408 -779
  7. package/dist/device/blindtilt.js.map +1 -1
  8. package/dist/device/bot.d.ts +26 -72
  9. package/dist/device/bot.d.ts.map +1 -1
  10. package/dist/device/bot.js +696 -822
  11. package/dist/device/bot.js.map +1 -1
  12. package/dist/device/ceilinglight.d.ts +14 -68
  13. package/dist/device/ceilinglight.d.ts.map +1 -1
  14. package/dist/device/ceilinglight.js +237 -606
  15. package/dist/device/ceilinglight.js.map +1 -1
  16. package/dist/device/colorbulb.d.ts +14 -75
  17. package/dist/device/colorbulb.d.ts.map +1 -1
  18. package/dist/device/colorbulb.js +279 -658
  19. package/dist/device/colorbulb.js.map +1 -1
  20. package/dist/device/contact.d.ts +15 -66
  21. package/dist/device/contact.d.ts.map +1 -1
  22. package/dist/device/contact.js +242 -544
  23. package/dist/device/contact.js.map +1 -1
  24. package/dist/device/curtain.d.ts +19 -88
  25. package/dist/device/curtain.d.ts.map +1 -1
  26. package/dist/device/curtain.js +402 -805
  27. package/dist/device/curtain.js.map +1 -1
  28. package/dist/device/device.d.ts +59 -0
  29. package/dist/device/device.d.ts.map +1 -0
  30. package/dist/device/device.js +684 -0
  31. package/dist/device/device.js.map +1 -0
  32. package/dist/device/fan.d.ts +51 -0
  33. package/dist/device/fan.d.ts.map +1 -0
  34. package/dist/device/fan.js +535 -0
  35. package/dist/device/fan.js.map +1 -0
  36. package/dist/device/hub.d.ts +16 -60
  37. package/dist/device/hub.d.ts.map +1 -1
  38. package/dist/device/hub.js +246 -613
  39. package/dist/device/hub.js.map +1 -1
  40. package/dist/device/humidifier.d.ts +11 -66
  41. package/dist/device/humidifier.d.ts.map +1 -1
  42. package/dist/device/humidifier.js +232 -593
  43. package/dist/device/humidifier.js.map +1 -1
  44. package/dist/device/iosensor.d.ts +11 -64
  45. package/dist/device/iosensor.d.ts.map +1 -1
  46. package/dist/device/iosensor.js +185 -600
  47. package/dist/device/iosensor.js.map +1 -1
  48. package/dist/device/lightstrip.d.ts +11 -69
  49. package/dist/device/lightstrip.d.ts.map +1 -1
  50. package/dist/device/lightstrip.js +277 -586
  51. package/dist/device/lightstrip.js.map +1 -1
  52. package/dist/device/lock.d.ts +16 -63
  53. package/dist/device/lock.d.ts.map +1 -1
  54. package/dist/device/lock.js +241 -560
  55. package/dist/device/lock.js.map +1 -1
  56. package/dist/device/meter.d.ts +14 -64
  57. package/dist/device/meter.d.ts.map +1 -1
  58. package/dist/device/meter.js +181 -593
  59. package/dist/device/meter.js.map +1 -1
  60. package/dist/device/meterplus.d.ts +14 -65
  61. package/dist/device/meterplus.d.ts.map +1 -1
  62. package/dist/device/meterplus.js +170 -593
  63. package/dist/device/meterplus.js.map +1 -1
  64. package/dist/device/motion.d.ts +13 -69
  65. package/dist/device/motion.d.ts.map +1 -1
  66. package/dist/device/motion.js +178 -531
  67. package/dist/device/motion.js.map +1 -1
  68. package/dist/device/plug.d.ts +9 -57
  69. package/dist/device/plug.d.ts.map +1 -1
  70. package/dist/device/plug.js +92 -458
  71. package/dist/device/plug.js.map +1 -1
  72. package/dist/device/robotvacuumcleaner.d.ts +12 -63
  73. package/dist/device/robotvacuumcleaner.d.ts.map +1 -1
  74. package/dist/device/robotvacuumcleaner.js +197 -521
  75. package/dist/device/robotvacuumcleaner.js.map +1 -1
  76. package/dist/device/waterdetector.d.ts +10 -65
  77. package/dist/device/waterdetector.d.ts.map +1 -1
  78. package/dist/device/waterdetector.js +139 -495
  79. package/dist/device/waterdetector.js.map +1 -1
  80. package/dist/homebridge-ui/public/index.html +22 -16
  81. package/dist/homebridge-ui/server.js +1 -1
  82. package/dist/homebridge-ui/server.js.map +1 -1
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +2 -2
  86. package/dist/index.js.map +1 -1
  87. package/dist/irdevice/airconditioner.d.ts +9 -49
  88. package/dist/irdevice/airconditioner.d.ts.map +1 -1
  89. package/dist/irdevice/airconditioner.js +309 -419
  90. package/dist/irdevice/airconditioner.js.map +1 -1
  91. package/dist/irdevice/airpurifier.d.ts +8 -39
  92. package/dist/irdevice/airpurifier.d.ts.map +1 -1
  93. package/dist/irdevice/airpurifier.js +72 -304
  94. package/dist/irdevice/airpurifier.js.map +1 -1
  95. package/dist/irdevice/camera.d.ts +7 -36
  96. package/dist/irdevice/camera.d.ts.map +1 -1
  97. package/dist/irdevice/camera.js +34 -278
  98. package/dist/irdevice/camera.js.map +1 -1
  99. package/dist/irdevice/fan.d.ts +10 -43
  100. package/dist/irdevice/fan.d.ts.map +1 -1
  101. package/dist/irdevice/fan.js +100 -338
  102. package/dist/irdevice/fan.js.map +1 -1
  103. package/dist/irdevice/irdevice.d.ts +40 -0
  104. package/dist/irdevice/irdevice.d.ts.map +1 -0
  105. package/dist/irdevice/irdevice.js +330 -0
  106. package/dist/irdevice/irdevice.js.map +1 -0
  107. package/dist/irdevice/light.d.ts +12 -45
  108. package/dist/irdevice/light.d.ts.map +1 -1
  109. package/dist/irdevice/light.js +87 -357
  110. package/dist/irdevice/light.js.map +1 -1
  111. package/dist/irdevice/other.d.ts +19 -48
  112. package/dist/irdevice/other.d.ts.map +1 -1
  113. package/dist/irdevice/other.js +352 -546
  114. package/dist/irdevice/other.js.map +1 -1
  115. package/dist/irdevice/tv.d.ts +8 -40
  116. package/dist/irdevice/tv.d.ts.map +1 -1
  117. package/dist/irdevice/tv.js +82 -321
  118. package/dist/irdevice/tv.js.map +1 -1
  119. package/dist/irdevice/vacuumcleaner.d.ts +7 -36
  120. package/dist/irdevice/vacuumcleaner.d.ts.map +1 -1
  121. package/dist/irdevice/vacuumcleaner.js +41 -284
  122. package/dist/irdevice/vacuumcleaner.js.map +1 -1
  123. package/dist/irdevice/waterheater.d.ts +7 -36
  124. package/dist/irdevice/waterheater.d.ts.map +1 -1
  125. package/dist/irdevice/waterheater.js +42 -287
  126. package/dist/irdevice/waterheater.js.map +1 -1
  127. package/dist/platform.d.ts +19 -6
  128. package/dist/platform.d.ts.map +1 -1
  129. package/dist/platform.js +310 -169
  130. package/dist/platform.js.map +1 -1
  131. package/dist/settings.d.ts +62 -19
  132. package/dist/settings.d.ts.map +1 -1
  133. package/dist/settings.js +16 -552
  134. package/dist/settings.js.map +1 -1
  135. package/dist/utils.d.ts +77 -0
  136. package/dist/utils.d.ts.map +1 -1
  137. package/dist/utils.js +638 -1
  138. package/dist/utils.js.map +1 -1
  139. package/eslint.config.js +96 -0
  140. package/package.json +19 -15
  141. package/src/custom.d.ts +2 -1
  142. package/src/device/blindtilt.ts +442 -814
  143. package/src/device/bot.ts +754 -915
  144. package/src/device/ceilinglight.ts +255 -633
  145. package/src/device/colorbulb.ts +294 -685
  146. package/src/device/contact.ts +277 -571
  147. package/src/device/curtain.ts +431 -835
  148. package/src/device/device.ts +709 -0
  149. package/src/device/fan.ts +591 -0
  150. package/src/device/hub.ts +286 -644
  151. package/src/device/humidifier.ts +266 -646
  152. package/src/device/iosensor.ts +220 -625
  153. package/src/device/lightstrip.ts +305 -620
  154. package/src/device/lock.ts +280 -600
  155. package/src/device/meter.ts +216 -617
  156. package/src/device/meterplus.ts +205 -619
  157. package/src/device/motion.ts +206 -556
  158. package/src/device/plug.ts +107 -490
  159. package/src/device/robotvacuumcleaner.ts +223 -550
  160. package/src/device/waterdetector.ts +160 -519
  161. package/src/homebridge-ui/public/index.html +22 -16
  162. package/src/homebridge-ui/server.ts +1 -1
  163. package/src/index.ts +4 -3
  164. package/src/irdevice/airconditioner.ts +333 -447
  165. package/src/irdevice/airpurifier.ts +92 -322
  166. package/src/irdevice/camera.ts +45 -294
  167. package/src/irdevice/fan.ts +115 -353
  168. package/src/irdevice/irdevice.ts +346 -0
  169. package/src/irdevice/light.ts +110 -385
  170. package/src/irdevice/other.ts +399 -616
  171. package/src/irdevice/tv.ts +103 -340
  172. package/src/irdevice/vacuumcleaner.ts +52 -306
  173. package/src/irdevice/waterheater.ts +53 -311
  174. package/src/platform.ts +355 -216
  175. package/src/settings.ts +116 -611
  176. package/src/utils.ts +642 -1
  177. package/src/device/waterdetector.json +0 -11
package/src/settings.ts CHANGED
@@ -1,10 +1,9 @@
1
- /* Copyright(C) 2017-2023, donavanbecker (https://github.com/donavanbecker). All rights reserved.
1
+ /* Copyright(C) 2017-2024, donavanbecker (https://github.com/donavanbecker). All rights reserved.
2
2
  *
3
3
  * settings.ts: @switchbot/homebridge-switchbot platform class.
4
4
  */
5
- /* eslint-disable max-len */
6
- import { MacAddress, PlatformConfig } from 'homebridge';
7
- import { IClientOptions } from 'async-mqtt';
5
+ import type { IClientOptions } from 'async-mqtt';
6
+ import type { MacAddress, PlatformConfig } from 'homebridge';
8
7
  /**
9
8
  * This is the name of the platform that users will use to register the plugin in the Homebridge config.json
10
9
  */
@@ -20,6 +19,26 @@ export const PLUGIN_NAME = '@switchbot/homebridge-switchbot';
20
19
  */
21
20
  export const Devices = 'https://api.switch-bot.com/v1.1/devices';
22
21
 
22
+ /**
23
+ * This is the updateWebhook url used to access SwitchBot API
24
+ */
25
+ export const setupWebhook = 'https://api.switch-bot.com/v1.1/webhook/setupWebhook';
26
+
27
+ /**
28
+ * This is the updateWebhook url used to access SwitchBot API
29
+ */
30
+ export const queryWebhook = 'https://api.switch-bot.com/v1.1/webhook/queryWebhook';
31
+
32
+ /**
33
+ * This is the updateWebhook url used to access SwitchBot API
34
+ */
35
+ export const updateWebhook = 'https://api.switch-bot.com/v1.1/webhook/updateWebhook';
36
+
37
+ /**
38
+ * This is the deleteWebhook url used to access SwitchBot API
39
+ */
40
+ export const deleteWebhook = 'https://api.switch-bot.com/v1.1/webhook/deleteWebhook';
41
+
23
42
  //Config
24
43
  export interface SwitchBotPlatformConfig extends PlatformConfig {
25
44
  credentials?: credentials;
@@ -36,9 +55,11 @@ export type credentials = {
36
55
  export type options = {
37
56
  refreshRate?: number;
38
57
  pushRate?: number;
58
+ maxRetries?: number;
59
+ delayBetweenRetries?: number;
39
60
  logging?: string;
40
- devices?: Array<devicesConfig>;
41
- irdevices?: Array<irDevicesConfig>;
61
+ devices?: devicesConfig[];
62
+ irdevices?: irDevicesConfig[];
42
63
  webhookURL?: string;
43
64
  mqttURL?: string;
44
65
  mqttOptions?: IClientOptions;
@@ -46,11 +67,15 @@ export type options = {
46
67
  };
47
68
 
48
69
  export interface devicesConfig extends device {
70
+ bleMac?: string;
71
+ model?: string;
72
+ bleModel?: string;
49
73
  configDeviceType: string;
50
74
  configDeviceName?: string;
51
75
  deviceId: string;
52
76
  external?: boolean;
53
77
  refreshRate?: number;
78
+ updateRate?: number;
54
79
  firmware?: string;
55
80
  logging?: string;
56
81
  connectionType?: string;
@@ -59,6 +84,8 @@ export interface devicesConfig extends device {
59
84
  hide_device?: boolean;
60
85
  offline?: boolean;
61
86
  maxRetry?: number;
87
+ maxRetries?: number;
88
+ delayBetweenRetries?: number;
62
89
  disableCaching?: boolean;
63
90
  mqttURL?: string;
64
91
  mqttOptions?: IClientOptions;
@@ -67,6 +94,7 @@ export interface devicesConfig extends device {
67
94
  webhook?: boolean;
68
95
  bot?: bot;
69
96
  meter?: meter;
97
+ iosensor?: iosensor;
70
98
  humidifier?: humidifier;
71
99
  curtain?: curtain;
72
100
  blindTilt?: blindTilt;
@@ -83,6 +111,13 @@ export interface devicesConfig extends device {
83
111
 
84
112
  export type meter = {
85
113
  hide_temperature?: boolean;
114
+ convertUnitTo?: string;
115
+ hide_humidity?: boolean;
116
+ };
117
+
118
+ export type iosensor = {
119
+ hide_temperature?: boolean;
120
+ convertUnitTo?: string;
86
121
  hide_humidity?: boolean;
87
122
  };
88
123
 
@@ -105,7 +140,6 @@ export type curtain = {
105
140
  hide_lightsensor?: boolean;
106
141
  set_minLux?: number;
107
142
  set_maxLux?: number;
108
- updateRate?: number;
109
143
  set_max?: number;
110
144
  set_min?: number;
111
145
  set_minStep?: number;
@@ -118,7 +152,6 @@ export type blindTilt = {
118
152
  hide_lightsensor?: boolean;
119
153
  set_minLux?: number;
120
154
  set_maxLux?: number;
121
- updateRate?: number;
122
155
  set_max?: number;
123
156
  set_min?: number;
124
157
  set_minStep?: number;
@@ -141,8 +174,6 @@ export type motion = {
141
174
 
142
175
  export type waterdetector = {
143
176
  hide_leak?: boolean;
144
- hide_temperature?: boolean;
145
- hide_humidity?: boolean;
146
177
  };
147
178
 
148
179
  export type colorbulb = {
@@ -167,6 +198,7 @@ export type lock = {
167
198
 
168
199
  export type hub = {
169
200
  hide_temperature?: boolean;
201
+ convertUnitTo?: string;
170
202
  hide_humidity?: boolean;
171
203
  hide_lightsensor?: boolean;
172
204
  };
@@ -232,7 +264,7 @@ export type body = {
232
264
 
233
265
  //a list of physical devices.
234
266
  export type deviceList = {
235
- device: Array<device>;
267
+ device: device[];
236
268
  };
237
269
 
238
270
  export type device = {
@@ -247,9 +279,9 @@ export type device = {
247
279
  //device's parent Hub ID.
248
280
  hubDeviceId: string;
249
281
  //only available for Curtain devices. a list of Curtain device IDs such that the Curtain devices are being paired or grouped.
250
- curtainDevicesIds?: Array<string>;
282
+ curtainDevicesIds?: string[];
251
283
  //only available for Blind Titl devices. a list of Blind Tilt device IDs such that the Blind Tilt devices are being paired or grouped.
252
- blindTiltDevicesIds?: Array<string>;
284
+ blindTiltDevicesIds?: string[];
253
285
  //only available for Curtain/Lock devices. determines if the open position and the close position of a device have been properly calibrated or not
254
286
  calibrate?: boolean;
255
287
  //only available for Curtain devices. determines if a Curtain is paired with or grouped with another Curtain or not.
@@ -263,14 +295,28 @@ export type device = {
263
295
  //the current position, 0-100
264
296
  slidePosition?: string;
265
297
  //the version of the device
266
- version?: number;
267
- //BLE Mac Address
268
- bleMac?: string;
298
+ version?: string;
299
+ // Fan Mode: direct mode: direct; natural mode: "natural"; sleep mode: "sleep"; ultra quiet mode: "baby"
300
+ mode: string;
301
+ //the current battery level
302
+ battery: number;
303
+ //ON/OFF state
304
+ power: string;
305
+ //set nightlight status. turn off: off; mode 1: 1; mode 2: 2
306
+ nightStatus: number;
307
+ //set horizontal oscillation. turn on: on; turn off: off
308
+ oscillation: string;
309
+ //set vertical oscillation. turn on: on; turn off: off
310
+ verticalOscillation: string;
311
+ //battery charge status. charging or uncharged
312
+ chargingStatus: string;
313
+ //fan speed. 1~100
314
+ fanSpeed: number;
269
315
  };
270
316
 
271
317
  //a list of virtual infrared remote devices.
272
318
  export type infraredRemoteList = {
273
- device: Array<irdevice>;
319
+ device: irdevice[];
274
320
  };
275
321
 
276
322
  export type irdevice = {
@@ -278,49 +324,62 @@ export type irdevice = {
278
324
  deviceName: string; //device name
279
325
  remoteType: string; //device type
280
326
  hubDeviceId: string; //remote device's parent Hub ID
327
+ model: string; //device model
281
328
  };
282
329
 
283
330
  export type deviceStatus = {
331
+ statusCode: number;
332
+ message: string;
333
+ body: deviceStatusBody;
334
+ };
335
+
336
+ export type deviceStatusBody = {
284
337
  //v1.1 of API
285
- deviceId: string; //device ID. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
286
- deviceType: string; //device type. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
287
- hubDeviceId: string; //device's parent Hub ID. 000000000000 when the device itself is a Hub or it is connected through Wi-Fi. (Used by the following deviceTypes: Bot, Curtain, Meter, Meter Plus, Lock, Keypad, Keypad Touch, Motion Sensor, Contact Sensor, Ceiling Light, Ceiling Light Pro, Plug Mini (JP), Strip Light, Color Bulb, Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Humidifier, Blind Tilt)
288
- power?: string; //ON/OFF state. (Used by the following deviceTypes: Bot, Ceiling Light, Ceiling Light Pro, PLug, Plug Mini (US), Plug Mini (JP), Strip Light, Color Bulb, Humidifier)
289
- calibrate?: boolean; //determines if device has been calibrated or not. (Used by the following deviceTypes: Curtain, Lock, Blind Tilt)
290
- group?: boolean; //determines if a device is paired with or grouped with another device or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
291
- moving?: boolean; //determines if a device is moving or not. (Used by the following deviceTypes: Curtain, Blind Tilt)
292
- slidePosition?: number; //the current position (0-100) the percentage of the distance between the calibrated open position and closed position. (Used by the following deviceTypes: Curtain, Blind Tilt)
293
- temperature?: number; //temperature in celsius (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
294
- humidity?: number; //humidity percentage. (Used by the following deviceTypes: Meter, Meter Plus, Humidifier, IOSensor)
295
- lockState?: string; //determines if locked or not. (Used by the following deviceTypes: Lock)
296
- doorState?: string; //determines if the door is closed or not. (Used by the following deviceTypes: Lock)
297
- moveDetected?: boolean; //determines if motion is detected. (Used by the following deviceTypes: Motion Sensor, Contact Sensor)
298
- brightness?: string | number; //the ambient brightness picked up by the sensor. bright or dim. (Used by the following deviceTypes: Motion Sensor, Contact Sensor) | the brightness value, range from 1 to 100. (Used by the following deviceTypes: Ceiling Light, Ceiling Light Pro, Strip Light, Color Bulb)
299
- openState?: string; //the open state of the sensor. open, close, or timeOutNotClose. (Used by the following deviceTypes: Contact Sensor)
300
- colorTemperature?: number; //the color temperature value, range from 2700 to 6500. (Used by the following deviceTypes: Ceiling Light, Ceiling Light Pro, Color Bulb)
301
- voltage?: number; //the voltage of the device, measured in Volt. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
302
- weight?: number; //the power consumed in a day, measured in Watts. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
303
- electricityOfDay?: number; //the duration that the device has been used during a day, measured in minutes. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
304
- electricCurrent?: number; //the current of the device at the moment, measured in Amp. (Used by the following deviceTypes: Plug Mini (US), Plug Mini (JP))
305
- color?: string; //the color value, RGB "255:255:255". (Used by the following deviceTypes: Strip Light, Color Bulb)
306
- workingStatus?: string; //the working status of the device. StandBy, Clearing, Paused, GotoChargeBase, Charging, ChargeDone, Dormant, InTrouble, InRemoteControl, or InDustCollecting. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
307
- onlineStatus?: string; //the connection status of the device. online or offline. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus)
308
- battery?: number; //the current battery level. (Used by the following deviceTypes: Robot Vacuum Cleaner S1, Robot Vacuum Cleaner S1 Plus, Blind Tilt, IOSensor)
309
- deviceName?: string; //device name. (Used by the following deviceTypes: Robot Vacuum Cleaner S1 Plus)
310
- nebulizationEfficiency?: number; //atomization efficiency percentage. (Used by the following deviceTypes: Humidifier)
311
- auto?: boolean; //determines if a Humidifier is in Auto Mode or not. (Used by the following deviceTypes: Humidifier)
312
- childLock?: boolean; //determines if a Humidifier's safety lock is on or not. (Used by the following deviceTypes: Humidifier)
313
- sound?: boolean; //determines if a Humidifier is muted or not. (Used by the following deviceTypes: Humidifier)
314
- lackWater?: boolean; //determines if the water tank is empty or not. (Used by the following deviceTypes: Humidifier)
315
- version?: number; //the version of the device. (Used by the following deviceTypes: Blind Tilt, Meter, MeterPlus, IOSensor)
316
- direction?: string; //the opening direction of a Blind Tilt device. (Used by the following deviceTypes: Blind Tilt)
317
- runStatus?: string; //'static' when not moving. (Used by the following deviceTypes: Blind Tilt)
318
- mode?: number; //available for devices. the fan mode. (Used by the following deviceTypes: Smart Fan)
319
- speed?: number; //the fan speed. (Used by the following deviceTypes: Smart Fan)
320
- shaking?: boolean; //determines if the fan is swinging or not. (Used by the following deviceTypes: Smart Fan)
321
- shakeCenter?: string; //the fan's swing direction. (Used by the following deviceTypes: Smart Fan)
322
- shakeRange?: string; //the fan's swing range, 0~120°. (Used by the following deviceTypes: Smart Fan)
323
- status?: number //the leak status. 0 for no leak, 1 for leak. (Used by the following deviceTypes: Water Detector)
338
+ deviceId: string;
339
+ deviceType: string;
340
+ hubDeviceId: string;
341
+ power?: string;
342
+ calibrate?: boolean;
343
+ group?: boolean;
344
+ moving?: boolean;
345
+ slidePosition?: number;
346
+ temperature?: number;
347
+ humidity?: number;
348
+ lockState?: string;
349
+ doorState?: string;
350
+ moveDetected?: boolean;
351
+ brightness?: string | number;
352
+ openState?: string;
353
+ colorTemperature?: number;
354
+ voltage?: number;
355
+ weight?: number;
356
+ electricityOfDay?: number;
357
+ electricCurrent?: number;
358
+ color?: string;
359
+ workingStatus?: string;
360
+ onlineStatus?: string;
361
+ battery?: number;
362
+ deviceName?: string;
363
+ nebulizationEfficiency?: number;
364
+ auto?: boolean;
365
+ childLock?: boolean;
366
+ sound?: boolean;
367
+ lackWater?: boolean;
368
+ version?: number;
369
+ direction?: string;
370
+ runStatus?: string;
371
+ mode?: number | string;
372
+ speed?: number;
373
+ shaking?: boolean;
374
+ shakeCenter?: string;
375
+ shakeRange?: string;
376
+ status?: number;
377
+ lightLevel?: number;
378
+ nightStatus: number;
379
+ oscillation: string;
380
+ verticalOscillation: string;
381
+ chargingStatus: string;
382
+ fanSpeed: number;
324
383
  };
325
384
 
326
385
  export type ad = {
@@ -357,7 +416,7 @@ export type serviceData = {
357
416
  battery?: number;
358
417
  //Humidifier's humidity level percentage
359
418
  percentage?: boolean | string;
360
- //Humidifier's humidity level percentage
419
+ //Humidifier's state
361
420
  onState?: boolean;
362
421
  //Humidifier's AutoMode
363
422
  autoMode?: boolean;
@@ -408,557 +467,3 @@ export type switchbot = {
408
467
  wait: (arg0: number) => any;
409
468
  };
410
469
 
411
- export function rgb2hs(r: any, g: any, b: any) {
412
- /*
413
- Credit:
414
- https://github.com/WickyNilliams/pure-color
415
- */
416
- r = parseInt(r);
417
- g = parseInt(g);
418
- b = parseInt(b);
419
- const min = Math.min(r, g, b);
420
- const max = Math.max(r, g, b);
421
- const delta = max - min;
422
- let h;
423
- let s;
424
- if (max === 0) {
425
- s = 0;
426
- } else {
427
- s = (delta / max) * 100;
428
- }
429
- if (max === min) {
430
- h = 0;
431
- } else if (r === max) {
432
- h = (g - b) / delta;
433
- } else if (g === max) {
434
- h = 2 + (b - r) / delta;
435
- } else if (b === max) {
436
- h = 4 + (r - g) / delta;
437
- }
438
- h = Math.min(h * 60, 360);
439
-
440
- if (h < 0) {
441
- h += 360;
442
- }
443
- return [Math.round(h), Math.round(s)];
444
- }
445
-
446
- export function hs2rgb(h: any, s: any) {
447
- /*
448
- Credit:
449
- https://github.com/WickyNilliams/pure-color
450
- */
451
- h = parseInt(h) / 60;
452
- s = parseInt(s) / 100;
453
- const f = h - Math.floor(h);
454
- const p = 255 * (1 - s);
455
- const q = 255 * (1 - s * f);
456
- const t = 255 * (1 - s * (1 - f));
457
- let rgb;
458
- switch (Math.floor(h) % 6) {
459
- case 0:
460
- rgb = [255, t, p];
461
- break;
462
- case 1:
463
- rgb = [q, 255, p];
464
- break;
465
- case 2:
466
- rgb = [p, 255, t];
467
- break;
468
- case 3:
469
- rgb = [p, q, 255];
470
- break;
471
- case 4:
472
- rgb = [t, p, 255];
473
- break;
474
- case 5:
475
- rgb = [255, p, q];
476
- break;
477
- }
478
- if (rgb[0] === 255) {
479
- rgb[1] *= 0.8;
480
- rgb[2] *= 0.8;
481
- if (rgb[1] <= 25 && rgb[2] <= 25) {
482
- rgb[1] = 0;
483
- rgb[2] = 0;
484
- }
485
- }
486
- return [Math.round(rgb[0]), Math.round(rgb[1]), Math.round(rgb[2])];
487
- }
488
-
489
- export function k2rgb(k: number) {
490
- // Set kelvin to nearest 100, between 2000 and 7100
491
- k = Math.round(k / 100) * 100;
492
- k = Math.max(Math.min(k, 7100), 2000);
493
-
494
- // k should now appear in our table of kelvin to rgb
495
- const values = {
496
- 2000: [255, 141, 11],
497
- 2100: [255, 146, 29],
498
- 2200: [255, 147, 44],
499
- 2300: [255, 152, 54],
500
- 2400: [255, 157, 63],
501
- 2500: [255, 166, 69],
502
- 2600: [255, 170, 77],
503
- 2700: [255, 174, 84],
504
- 2800: [255, 173, 94],
505
- 2900: [255, 177, 101],
506
- 3000: [255, 180, 107],
507
- 3100: [255, 189, 111],
508
- 3200: [255, 187, 120],
509
- 3300: [255, 195, 124],
510
- 3400: [255, 198, 130],
511
- 3500: [255, 201, 135],
512
- 3600: [255, 203, 141],
513
- 3700: [255, 206, 146],
514
- 3800: [255, 204, 153],
515
- 3900: [255, 206, 159],
516
- 4000: [255, 213, 161],
517
- 4100: [255, 215, 166],
518
- 4200: [255, 217, 171],
519
- 4300: [255, 219, 175],
520
- 4400: [255, 221, 180],
521
- 4500: [255, 223, 184],
522
- 4600: [255, 225, 188],
523
- 4700: [255, 226, 192],
524
- 4800: [255, 228, 196],
525
- 4900: [255, 229, 200],
526
- 5000: [255, 231, 204],
527
- 5100: [255, 230, 210],
528
- 5200: [255, 234, 211],
529
- 5300: [255, 235, 215],
530
- 5400: [255, 237, 218],
531
- 5500: [255, 236, 224],
532
- 5700: [255, 240, 228],
533
- 5800: [255, 241, 231],
534
- 5900: [255, 243, 234],
535
- 6000: [255, 244, 237],
536
- 6100: [255, 245, 240],
537
- 6200: [255, 246, 243],
538
- 6300: [255, 247, 247],
539
- 6400: [255, 248, 251],
540
- 6500: [255, 249, 253],
541
- 6600: [254, 249, 255],
542
- 6700: [252, 247, 255],
543
- 6800: [249, 246, 255],
544
- 6900: [247, 245, 255],
545
- 7000: [245, 243, 255],
546
- 7100: [243, 242, 255],
547
- };
548
-
549
- // Return the value
550
- return values[k];
551
- }
552
-
553
- export function m2hs(m) {
554
- /*
555
- Credit:
556
- https://github.com/homebridge/HAP-NodeJS
557
- */
558
- const table = {
559
- 100: [19, 222.1],
560
- 101: [18.7, 222.2],
561
- 102: [18.4, 222.3],
562
- 103: [18.2, 222.3],
563
- 104: [17.9, 222.4],
564
- 105: [17.6, 222.5],
565
- 106: [17.3, 222.7],
566
- 107: [17, 222.8],
567
- 108: [16.7, 222.9],
568
- 109: [16.4, 223],
569
- 110: [16.1, 223.2],
570
- 111: [15.8, 223.3],
571
- 112: [15.4, 223.4],
572
- 113: [15.2, 223.6],
573
- 114: [14.9, 223.8],
574
- 115: [14.7, 223.9],
575
- 116: [14.3, 224.1],
576
- 117: [14.1, 224.2],
577
- 118: [13.8, 224.4],
578
- 119: [13.5, 224.6],
579
- 120: [13.2, 224.8],
580
- 121: [12.9, 225],
581
- 122: [12.5, 225.3],
582
- 123: [12.2, 225.6],
583
- 124: [11.8, 225.9],
584
- 125: [11.4, 226.3],
585
- 126: [11.1, 226.7],
586
- 127: [10.7, 227.1],
587
- 128: [10.3, 227.6],
588
- 129: [9.9, 228],
589
- 130: [9.6, 228.5],
590
- 131: [9.3, 229.1],
591
- 132: [8.9, 229.6],
592
- 133: [8.5, 230.2],
593
- 134: [8.2, 230.9],
594
- 135: [7.8, 231.6],
595
- 136: [7.5, 232.5],
596
- 137: [7.1, 233.5],
597
- 138: [6.7, 234.6],
598
- 139: [6.3, 235.8],
599
- 140: [6, 237.1],
600
- 141: [5.6, 238.9],
601
- 142: [5.2, 240.9],
602
- 143: [5, 242.9],
603
- 144: [4.8, 244.9],
604
- 145: [4.6, 246.9],
605
- 146: [4.4, 249.3],
606
- 147: [4.3, 251.9],
607
- 148: [4.1, 254.9],
608
- 149: [3.9, 258],
609
- 150: [3.7, 261.8],
610
- 151: [3.4, 265.9],
611
- 152: [3.2, 271],
612
- 153: [3, 276.4],
613
- 154: [2.8, 283.6],
614
- 155: [2.6, 290.4],
615
- 156: [2.3, 295.3],
616
- 157: [2.1, 300],
617
- 158: [1.9, 300],
618
- 159: [1.6, 300],
619
- 160: [1.4, 195.8],
620
- 161: [1.2, 84.3],
621
- 162: [1.3, 58.2],
622
- 163: [1.5, 55.9],
623
- 164: [1.7, 53.2],
624
- 165: [1.9, 50.2],
625
- 166: [2.1, 47.1],
626
- 167: [2.4, 44.5],
627
- 168: [2.6, 42.6],
628
- 169: [2.9, 40.9],
629
- 170: [3.1, 39.5],
630
- 171: [3.4, 38.3],
631
- 172: [3.7, 37.3],
632
- 173: [3.9, 36.5],
633
- 174: [4.2, 35.7],
634
- 175: [4.4, 35.1],
635
- 176: [4.6, 34.5],
636
- 177: [4.9, 34],
637
- 178: [5.1, 33.5],
638
- 179: [5.3, 33],
639
- 180: [5.6, 32.7],
640
- 181: [5.8, 32.3],
641
- 182: [6, 32],
642
- 183: [6.3, 31.7],
643
- 184: [6.5, 31.4],
644
- 185: [6.7, 31.2],
645
- 186: [7, 30.9],
646
- 187: [7.2, 30.7],
647
- 188: [7.4, 30.5],
648
- 189: [7.6, 30.3],
649
- 190: [7.9, 30.1],
650
- 191: [8.1, 29.9],
651
- 192: [8.4, 29.7],
652
- 193: [8.6, 29.6],
653
- 194: [8.9, 29.5],
654
- 195: [9.1, 29.3],
655
- 196: [9.4, 29.2],
656
- 197: [9.6, 29.1],
657
- 198: [9.8, 29],
658
- 199: [10, 28.9],
659
- 200: [10.2, 28.7],
660
- 201: [10.5, 28.7],
661
- 202: [10.7, 28.6],
662
- 203: [11, 28.5],
663
- 204: [11.2, 28.4],
664
- 205: [11.4, 28.3],
665
- 206: [11.6, 28.3],
666
- 207: [11.8, 28.2],
667
- 208: [12.1, 28.1],
668
- 209: [12.3, 28.1],
669
- 210: [12.5, 28],
670
- 211: [12.7, 28],
671
- 212: [12.9, 27.9],
672
- 213: [13.2, 27.8],
673
- 214: [13.4, 27.8],
674
- 215: [13.6, 27.7],
675
- 216: [13.8, 27.7],
676
- 217: [14, 27.7],
677
- 218: [14.3, 27.6],
678
- 219: [14.5, 27.6],
679
- 220: [14.7, 27.5],
680
- 221: [14.9, 27.5],
681
- 222: [15.1, 27.5],
682
- 223: [15.3, 27.4],
683
- 224: [15.5, 27.4],
684
- 225: [15.8, 27.4],
685
- 226: [16, 27.3],
686
- 227: [16.2, 27.3],
687
- 228: [16.4, 27.3],
688
- 229: [16.6, 27.3],
689
- 230: [16.8, 27.2],
690
- 231: [17, 27.2],
691
- 232: [17.2, 27.2],
692
- 233: [17.4, 27.2],
693
- 234: [17.6, 27.2],
694
- 235: [17.8, 27.1],
695
- 236: [18, 27.1],
696
- 237: [18.2, 27.1],
697
- 238: [18.4, 27.1],
698
- 239: [18.7, 27.1],
699
- 240: [18.8, 27],
700
- 241: [19, 27],
701
- 242: [19.2, 27],
702
- 243: [19.4, 27],
703
- 244: [19.6, 27],
704
- 245: [19.8, 27],
705
- 246: [20, 27],
706
- 247: [20.3, 26.9],
707
- 248: [20.5, 26.9],
708
- 249: [20.6, 26.9],
709
- 250: [20.8, 26.9],
710
- 251: [21, 26.9],
711
- 252: [21.3, 26.9],
712
- 253: [21.5, 26.9],
713
- 254: [21.6, 26.9],
714
- 255: [21.8, 26.8],
715
- 256: [22, 26.8],
716
- 257: [22.2, 26.8],
717
- 258: [22.4, 26.8],
718
- 259: [22.6, 26.8],
719
- 260: [22.8, 26.8],
720
- 261: [23, 26.8],
721
- 262: [23.2, 26.8],
722
- 263: [23.4, 26.8],
723
- 264: [23.6, 26.8],
724
- 265: [23.8, 26.8],
725
- 266: [24, 26.8],
726
- 267: [24.1, 26.8],
727
- 268: [24.3, 26.8],
728
- 269: [24.5, 26.8],
729
- 270: [24.7, 26.8],
730
- 271: [24.8, 26.8],
731
- 272: [25.1, 26.7],
732
- 273: [25.3, 26.7],
733
- 274: [25.4, 26.7],
734
- 275: [25.6, 26.7],
735
- 276: [25.8, 26.7],
736
- 277: [26, 26.7],
737
- 278: [26.1, 26.7],
738
- 279: [26.3, 26.7],
739
- 280: [26.5, 26.7],
740
- 281: [26.7, 26.7],
741
- 282: [26.9, 26.7],
742
- 283: [27.1, 26.7],
743
- 284: [27.3, 26.7],
744
- 285: [27.5, 26.7],
745
- 286: [27.7, 26.7],
746
- 287: [27.8, 26.7],
747
- 288: [28, 26.7],
748
- 289: [28.2, 26.7],
749
- 290: [28.4, 26.7],
750
- 291: [28.6, 26.7],
751
- 292: [28.8, 26.7],
752
- 293: [28.9, 26.7],
753
- 294: [29.1, 26.7],
754
- 295: [29.3, 26.7],
755
- 296: [29.5, 26.7],
756
- 297: [29.6, 26.7],
757
- 298: [29.8, 26.7],
758
- 299: [30, 26.7],
759
- 300: [30.2, 26.7],
760
- 301: [30.4, 26.7],
761
- 302: [30.5, 26.7],
762
- 303: [30.7, 26.7],
763
- 304: [30.9, 26.7],
764
- 305: [31.1, 26.7],
765
- 306: [31.2, 26.7],
766
- 307: [31.4, 26.7],
767
- 308: [31.6, 26.7],
768
- 309: [31.8, 26.8],
769
- 310: [31.9, 26.8],
770
- 311: [32.1, 26.8],
771
- 312: [32.3, 26.8],
772
- 313: [32.5, 26.8],
773
- 314: [32.6, 26.8],
774
- 315: [32.8, 26.8],
775
- 316: [33, 26.8],
776
- 317: [33.2, 26.8],
777
- 318: [33.3, 26.8],
778
- 319: [33.5, 26.8],
779
- 320: [33.7, 26.8],
780
- 321: [33.8, 26.8],
781
- 322: [34, 26.8],
782
- 323: [34.2, 26.8],
783
- 324: [34.4, 26.8],
784
- 325: [34.5, 26.8],
785
- 326: [34.7, 26.8],
786
- 327: [34.9, 26.8],
787
- 328: [35.1, 26.8],
788
- 329: [35.2, 26.8],
789
- 330: [35.4, 26.8],
790
- 331: [35.5, 26.8],
791
- 332: [35.7, 26.8],
792
- 333: [35.9, 26.8],
793
- 334: [36.1, 26.8],
794
- 335: [36.3, 26.9],
795
- 336: [36.5, 26.9],
796
- 337: [36.7, 26.9],
797
- 338: [36.9, 26.9],
798
- 339: [37.1, 26.9],
799
- 340: [37.2, 26.9],
800
- 341: [37.4, 26.9],
801
- 342: [37.5, 26.9],
802
- 343: [37.7, 26.9],
803
- 344: [37.9, 26.9],
804
- 345: [38.1, 26.9],
805
- 346: [38.3, 26.9],
806
- 347: [38.5, 26.9],
807
- 348: [38.7, 26.9],
808
- 349: [38.9, 26.9],
809
- 350: [39, 26.9],
810
- 351: [39.2, 26.9],
811
- 352: [39.3, 27],
812
- 353: [39.5, 27],
813
- 354: [39.7, 27],
814
- 355: [39.9, 27],
815
- 356: [40.1, 27],
816
- 357: [40.2, 27],
817
- 358: [40.4, 27],
818
- 359: [40.6, 27],
819
- 360: [40.8, 27],
820
- 361: [40.9, 27],
821
- 362: [41.1, 27],
822
- 363: [41.2, 27],
823
- 364: [41.4, 27],
824
- 365: [41.6, 27],
825
- 366: [41.8, 27],
826
- 367: [42, 27],
827
- 368: [42.1, 27.1],
828
- 369: [42.3, 27.1],
829
- 370: [42.4, 27.1],
830
- 371: [42.6, 27.1],
831
- 372: [42.8, 27.1],
832
- 373: [43, 27.1],
833
- 374: [43.1, 27.1],
834
- 375: [43.2, 27.1],
835
- 376: [43.4, 27.1],
836
- 377: [43.6, 27.1],
837
- 378: [43.8, 27.1],
838
- 379: [43.9, 27.1],
839
- 380: [44.1, 27.1],
840
- 381: [44.3, 27.2],
841
- 382: [44.4, 27.2],
842
- 383: [44.6, 27.2],
843
- 384: [44.7, 27.2],
844
- 385: [44.9, 27.2],
845
- 386: [45.1, 27.2],
846
- 387: [45.3, 27.2],
847
- 388: [45.5, 27.2],
848
- 389: [45.6, 27.2],
849
- 390: [45.8, 27.2],
850
- 391: [46, 27.2],
851
- 392: [46.2, 27.2],
852
- 393: [46.4, 27.3],
853
- 394: [46.5, 27.3],
854
- 395: [46.7, 27.3],
855
- 396: [46.9, 27.3],
856
- 397: [47.1, 27.3],
857
- 398: [47.2, 27.3],
858
- 399: [47.4, 27.3],
859
- 400: [47.6, 27.3],
860
- 401: [47.7, 27.3],
861
- 402: [47.9, 27.3],
862
- 403: [48.1, 27.3],
863
- 404: [48.3, 27.3],
864
- 405: [48.5, 27.4],
865
- 406: [48.7, 27.4],
866
- 407: [48.8, 27.4],
867
- 408: [49, 27.4],
868
- 409: [49.2, 27.4],
869
- 410: [49.4, 27.4],
870
- 411: [49.6, 27.4],
871
- 412: [49.7, 27.4],
872
- 413: [49.9, 27.4],
873
- 414: [50.1, 27.4],
874
- 415: [50.2, 27.4],
875
- 416: [50.4, 27.4],
876
- 417: [50.6, 27.5],
877
- 418: [50.7, 27.5],
878
- 419: [50.9, 27.5],
879
- 420: [51.1, 27.5],
880
- 421: [51.2, 27.5],
881
- 422: [51.4, 27.5],
882
- 423: [51.6, 27.5],
883
- 424: [51.7, 27.5],
884
- 425: [51.9, 27.5],
885
- 426: [52.1, 27.5],
886
- 427: [51.2, 27.6],
887
- 428: [52.4, 27.6],
888
- 429: [52.5, 27.6],
889
- 430: [52.7, 27.6],
890
- 431: [52.9, 27.6],
891
- 432: [53.1, 27.6],
892
- 433: [53.2, 27.6],
893
- 434: [53.4, 27.6],
894
- 435: [53.6, 27.6],
895
- 436: [53.7, 27.6],
896
- 437: [53.9, 27.6],
897
- 438: [54.1, 27.7],
898
- 439: [54.2, 27.7],
899
- 440: [54.3, 27.7],
900
- 441: [54.5, 27.7],
901
- 442: [54.7, 27.7],
902
- 443: [54.8, 27.7],
903
- 444: [55, 27.7],
904
- 445: [55.2, 27.7],
905
- 446: [55.3, 27.7],
906
- 447: [55.5, 27.7],
907
- 448: [55.7, 27.7],
908
- 449: [55.8, 27.8],
909
- 450: [56, 27.8],
910
- 451: [56.2, 27.8],
911
- 452: [56.3, 27.8],
912
- 453: [56.5, 27.8],
913
- 454: [56.7, 27.8],
914
- 455: [56.8, 27.8],
915
- 456: [57, 27.8],
916
- 457: [57.2, 27.8],
917
- 458: [57.3, 27.9],
918
- 459: [57.4, 27.9],
919
- 460: [57.6, 27.9],
920
- 461: [57.8, 27.9],
921
- 462: [57.9, 27.9],
922
- 463: [58.1, 27.9],
923
- 464: [58.3, 27.9],
924
- 465: [58.4, 27.9],
925
- 466: [58.6, 27.9],
926
- 467: [58.8, 27.9],
927
- 468: [59, 28],
928
- 469: [59.1, 28],
929
- 470: [59.2, 28],
930
- 471: [59.4, 28],
931
- 472: [59.6, 28],
932
- 473: [59.7, 28],
933
- 474: [60, 28],
934
- 475: [60.1, 28],
935
- 476: [60.2, 28],
936
- 477: [60.4, 28],
937
- 478: [60.6, 28.1],
938
- 479: [60.7, 28.1],
939
- 480: [60.9, 28.1],
940
- 481: [60.1, 28.1],
941
- 482: [60.3, 28.1],
942
- 483: [61.4, 28.1],
943
- 484: [61.5, 28.1],
944
- 485: [61.7, 28.1],
945
- 486: [61.9, 28.1],
946
- 487: [62, 28.2],
947
- 488: [62.2, 28.2],
948
- 489: [62.3, 28.2],
949
- 490: [62.5, 28.2],
950
- 491: [62.7, 28.2],
951
- 492: [62.8, 28.2],
952
- 493: [63, 28.2],
953
- 494: [63.2, 28.2],
954
- 495: [63.3, 28.2],
955
- 496: [63.4, 28.2],
956
- 497: [63.6, 28.2],
957
- 498: [63.8, 28.3],
958
- 499: [63.9, 28.3],
959
- 500: [64.1, 28.3],
960
- };
961
- const input = Math.min(Math.max(Math.round(m), 140), 500);
962
- const toReturn = table[input];
963
- return [Math.round(toReturn[1]), Math.round(toReturn[0])];
964
- }