@switchbot/homebridge-switchbot 3.5.0-beta.8 → 3.5.0

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