node-miio 0.13.0 → 0.15.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 (266) hide show
  1. package/LICENSE.md +25 -0
  2. package/README.md +5 -6
  3. package/dist/lib/connect_to_device.d.ts +2 -2
  4. package/dist/lib/device.d.ts +36 -60
  5. package/dist/lib/device.js +81 -24
  6. package/dist/lib/device.js.map +1 -1
  7. package/dist/lib/device_info.d.ts +1 -1
  8. package/dist/lib/device_info.js.map +1 -1
  9. package/dist/lib/devices/air-monitor.d.ts +8 -2
  10. package/dist/lib/devices/air-monitor.js +6 -3
  11. package/dist/lib/devices/air-monitor.js.map +1 -1
  12. package/dist/lib/devices/air-purifier.d.ts +14 -6
  13. package/dist/lib/devices/air-purifier.js +7 -2
  14. package/dist/lib/devices/air-purifier.js.map +1 -1
  15. package/dist/lib/devices/capabilities/battery-level.d.ts +5 -22
  16. package/dist/lib/devices/capabilities/battery-level.js +6 -5
  17. package/dist/lib/devices/capabilities/battery-level.js.map +1 -1
  18. package/dist/lib/devices/capabilities/buzzer.d.ts +24 -30
  19. package/dist/lib/devices/capabilities/buzzer.js +32 -49
  20. package/dist/lib/devices/capabilities/buzzer.js.map +1 -1
  21. package/dist/lib/devices/capabilities/changeable-led-brightness.d.ts +13 -29
  22. package/dist/lib/devices/capabilities/changeable-led-brightness.js +16 -24
  23. package/dist/lib/devices/capabilities/changeable-led-brightness.js.map +1 -1
  24. package/dist/lib/devices/capabilities/colorable.d.ts +5 -21
  25. package/dist/lib/devices/capabilities/colorable.js +6 -6
  26. package/dist/lib/devices/capabilities/colorable.js.map +1 -1
  27. package/dist/lib/devices/capabilities/device_capability.d.ts +7 -0
  28. package/dist/lib/devices/capabilities/device_capability.js +10 -0
  29. package/dist/lib/devices/capabilities/device_capability.js.map +1 -0
  30. package/dist/lib/devices/capabilities/dimmable.d.ts +5 -21
  31. package/dist/lib/devices/capabilities/dimmable.js +6 -6
  32. package/dist/lib/devices/capabilities/dimmable.js.map +1 -1
  33. package/dist/lib/devices/capabilities/mode.d.ts +5 -21
  34. package/dist/lib/devices/capabilities/mode.js +6 -5
  35. package/dist/lib/devices/capabilities/mode.js.map +1 -1
  36. package/dist/lib/devices/capabilities/power.d.ts +5 -21
  37. package/dist/lib/devices/capabilities/power.js +6 -5
  38. package/dist/lib/devices/capabilities/power.js.map +1 -1
  39. package/dist/lib/devices/capabilities/sensor.d.ts +29 -15
  40. package/dist/lib/devices/capabilities/sensor.js +56 -41
  41. package/dist/lib/devices/capabilities/sensor.js.map +1 -1
  42. package/dist/lib/devices/capabilities/switchable-led.d.ts +13 -29
  43. package/dist/lib/devices/capabilities/switchable-led.js +18 -30
  44. package/dist/lib/devices/capabilities/switchable-led.js.map +1 -1
  45. package/dist/lib/devices/chuangmi.plug.v1.d.ts +10 -29
  46. package/dist/lib/devices/chuangmi.plug.v1.js +39 -31
  47. package/dist/lib/devices/chuangmi.plug.v1.js.map +1 -1
  48. package/dist/lib/devices/eyecare-lamp2.d.ts +29 -59
  49. package/dist/lib/devices/eyecare-lamp2.js +49 -38
  50. package/dist/lib/devices/eyecare-lamp2.js.map +1 -1
  51. package/dist/lib/devices/gateway/controllers.d.ts +60 -0
  52. package/dist/lib/devices/gateway/controllers.js +137 -0
  53. package/dist/lib/devices/gateway/controllers.js.map +1 -0
  54. package/dist/lib/devices/gateway/ctrl_ln1.d.ts +5 -7
  55. package/dist/lib/devices/gateway/ctrl_ln1.js +8 -33
  56. package/dist/lib/devices/gateway/ctrl_ln1.js.map +1 -1
  57. package/dist/lib/devices/gateway/ctrl_ln2.d.ts +5 -7
  58. package/dist/lib/devices/gateway/ctrl_ln2.js +8 -41
  59. package/dist/lib/devices/gateway/ctrl_ln2.js.map +1 -1
  60. package/dist/lib/devices/gateway/ctrl_neutral1.d.ts +5 -7
  61. package/dist/lib/devices/gateway/ctrl_neutral1.js +8 -33
  62. package/dist/lib/devices/gateway/ctrl_neutral1.js.map +1 -1
  63. package/dist/lib/devices/gateway/ctrl_neutral2.d.ts +5 -7
  64. package/dist/lib/devices/gateway/ctrl_neutral2.js +8 -41
  65. package/dist/lib/devices/gateway/ctrl_neutral2.js.map +1 -1
  66. package/dist/lib/devices/gateway/gateway-light.d.ts +27 -0
  67. package/dist/lib/devices/gateway/gateway-light.js +64 -0
  68. package/dist/lib/devices/gateway/gateway-light.js.map +1 -0
  69. package/dist/lib/devices/gateway/light-channel.d.ts +29 -7
  70. package/dist/lib/devices/gateway/light-channel.js +58 -8
  71. package/dist/lib/devices/gateway/light-channel.js.map +1 -1
  72. package/dist/lib/devices/gateway/plug.d.ts +10 -5
  73. package/dist/lib/devices/gateway/plug.js +16 -12
  74. package/dist/lib/devices/gateway/plug.js.map +1 -1
  75. package/dist/lib/devices/gateway/sensors.d.ts +37 -0
  76. package/dist/lib/devices/gateway/sensors.js +86 -0
  77. package/dist/lib/devices/gateway/sensors.js.map +1 -0
  78. package/dist/lib/devices/gateway/subdevice.d.ts +80 -60
  79. package/dist/lib/devices/gateway/subdevice.js +112 -127
  80. package/dist/lib/devices/gateway/subdevice.js.map +1 -1
  81. package/dist/lib/devices/gateway/subdevices.d.ts +6 -49
  82. package/dist/lib/devices/gateway/subdevices.js +27 -15
  83. package/dist/lib/devices/gateway/subdevices.js.map +1 -1
  84. package/dist/lib/devices/gateway/voltage.d.ts +8 -23
  85. package/dist/lib/devices/gateway/voltage.js +11 -12
  86. package/dist/lib/devices/gateway/voltage.js.map +1 -1
  87. package/dist/lib/devices/gateway.d.ts +61 -67
  88. package/dist/lib/devices/gateway.js +127 -111
  89. package/dist/lib/devices/gateway.js.map +1 -1
  90. package/dist/lib/devices/humidifier.d.ts +23 -10
  91. package/dist/lib/devices/humidifier.js +33 -36
  92. package/dist/lib/devices/humidifier.js.map +1 -1
  93. package/dist/lib/devices/philips-light-bulb.d.ts +14 -6
  94. package/dist/lib/devices/philips-light-bulb.js +23 -21
  95. package/dist/lib/devices/philips-light-bulb.js.map +1 -1
  96. package/dist/lib/devices/power-plug.d.ts +9 -28
  97. package/dist/lib/devices/power-plug.js +15 -8
  98. package/dist/lib/devices/power-plug.js.map +1 -1
  99. package/dist/lib/devices/power-strip.d.ts +11 -5
  100. package/dist/lib/devices/power-strip.js +17 -9
  101. package/dist/lib/devices/power-strip.js.map +1 -1
  102. package/dist/lib/devices/vacuums/dreamevacuum.d.ts +3 -24
  103. package/dist/lib/devices/vacuums/dreamevacuum.js +14 -11
  104. package/dist/lib/devices/vacuums/dreamevacuum.js.map +1 -1
  105. package/dist/lib/devices/vacuums/miot-vacuum.d.ts +23 -30
  106. package/dist/lib/devices/vacuums/miot-vacuum.js +302 -46
  107. package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -1
  108. package/dist/lib/devices/vacuums/vacuum.d.ts +3 -24
  109. package/dist/lib/devices/vacuums/vacuum.js +6 -5
  110. package/dist/lib/devices/vacuums/vacuum.js.map +1 -1
  111. package/dist/lib/devices/vacuums/vacuum_device.d.ts +1 -1
  112. package/dist/lib/devices/vacuums/vacuum_device.js +3 -3
  113. package/dist/lib/devices/vacuums/vacuum_device.js.map +1 -1
  114. package/dist/lib/devices/vacuums/vacuum_errors.d.ts +4 -3
  115. package/dist/lib/devices/vacuums/vacuum_errors.js +5 -7
  116. package/dist/lib/devices/vacuums/vacuum_errors.js.map +1 -1
  117. package/dist/lib/devices/vacuums/vacuum_states.d.ts +59 -1
  118. package/dist/lib/devices/vacuums/vacuum_states.js +61 -3
  119. package/dist/lib/devices/vacuums/vacuum_states.js.map +1 -1
  120. package/dist/lib/devices/vacuums/vacuum_thing.d.ts +13 -0
  121. package/dist/lib/devices/vacuums/vacuum_thing.js +19 -0
  122. package/dist/lib/devices/vacuums/vacuum_thing.js.map +1 -0
  123. package/dist/lib/devices/vacuums/viomivacuum.d.ts +3 -24
  124. package/dist/lib/devices/vacuums/viomivacuum.js +6 -5
  125. package/dist/lib/devices/vacuums/viomivacuum.js.map +1 -1
  126. package/dist/lib/devices/yeelight.color.d.ts +13 -2
  127. package/dist/lib/devices/yeelight.color.js +101 -3
  128. package/dist/lib/devices/yeelight.color.js.map +1 -1
  129. package/dist/lib/devices/yeelight.d.ts +36 -154
  130. package/dist/lib/devices/yeelight.js +36 -144
  131. package/dist/lib/devices/yeelight.js.map +1 -1
  132. package/dist/lib/devices/yeelight.mono.d.ts +13 -2
  133. package/dist/lib/devices/yeelight.mono.js +34 -3
  134. package/dist/lib/devices/yeelight.mono.js.map +1 -1
  135. package/dist/lib/discovery.js +2 -2
  136. package/dist/lib/discovery.js.map +1 -1
  137. package/dist/lib/events.d.ts +1 -1
  138. package/dist/lib/index.d.ts +1 -6
  139. package/dist/lib/index.js +4 -1
  140. package/dist/lib/index.js.map +1 -1
  141. package/dist/lib/models.d.ts +26 -239
  142. package/dist/lib/models.js +26 -29
  143. package/dist/lib/models.js.map +1 -1
  144. package/dist/lib/protocol.d.ts +10 -2
  145. package/dist/lib/things/capabilities/actions.d.ts +21 -0
  146. package/dist/lib/things/capabilities/actions.js +36 -0
  147. package/dist/lib/things/capabilities/actions.js.map +1 -0
  148. package/dist/lib/things/capabilities/battery-level.d.ts +13 -0
  149. package/dist/lib/things/capabilities/battery-level.js +26 -0
  150. package/dist/lib/things/capabilities/battery-level.js.map +1 -0
  151. package/dist/lib/things/capabilities/charging.d.ts +20 -0
  152. package/dist/lib/things/capabilities/charging.js +40 -0
  153. package/dist/lib/things/capabilities/charging.js.map +1 -0
  154. package/dist/lib/things/capabilities/children.d.ts +78 -0
  155. package/dist/lib/things/capabilities/children.js +173 -0
  156. package/dist/lib/things/capabilities/children.js.map +1 -0
  157. package/dist/lib/things/capabilities/cleaning.d.ts +40 -0
  158. package/dist/lib/things/capabilities/cleaning.js +85 -0
  159. package/dist/lib/things/capabilities/cleaning.js.map +1 -0
  160. package/dist/lib/things/capabilities/error-state.d.ts +15 -0
  161. package/dist/lib/things/capabilities/error-state.js +33 -0
  162. package/dist/lib/things/capabilities/error-state.js.map +1 -0
  163. package/dist/lib/things/capabilities/fan-speed.d.ts +36 -0
  164. package/dist/lib/things/capabilities/fan-speed.js +59 -0
  165. package/dist/lib/things/capabilities/fan-speed.js.map +1 -0
  166. package/dist/lib/things/capabilities/index.d.ts +14 -0
  167. package/dist/lib/things/capabilities/index.js +31 -0
  168. package/dist/lib/things/capabilities/index.js.map +1 -0
  169. package/dist/lib/things/capabilities/lights/brightness.d.ts +44 -0
  170. package/dist/lib/things/capabilities/lights/brightness.js +87 -0
  171. package/dist/lib/things/capabilities/lights/brightness.js.map +1 -0
  172. package/dist/lib/things/capabilities/lights/color-temperature.d.ts +21 -0
  173. package/dist/lib/things/capabilities/lights/color-temperature.js +43 -0
  174. package/dist/lib/things/capabilities/lights/color-temperature.js.map +1 -0
  175. package/dist/lib/things/capabilities/lights/colorable.d.ts +37 -0
  176. package/dist/lib/things/capabilities/lights/colorable.js +57 -0
  177. package/dist/lib/things/capabilities/lights/colorable.js.map +1 -0
  178. package/dist/lib/things/capabilities/lights/fading.d.ts +13 -0
  179. package/dist/lib/things/capabilities/lights/fading.js +23 -0
  180. package/dist/lib/things/capabilities/lights/fading.js.map +1 -0
  181. package/dist/lib/things/capabilities/lights/index.d.ts +5 -0
  182. package/dist/lib/things/capabilities/lights/index.js +22 -0
  183. package/dist/lib/things/capabilities/lights/index.js.map +1 -0
  184. package/dist/lib/things/capabilities/lights/light.d.ts +25 -0
  185. package/dist/lib/things/capabilities/lights/light.js +23 -0
  186. package/dist/lib/things/capabilities/lights/light.js.map +1 -0
  187. package/dist/lib/things/capabilities/mode.d.ts +45 -0
  188. package/dist/lib/things/capabilities/mode.js +75 -0
  189. package/dist/lib/things/capabilities/mode.js.map +1 -0
  190. package/dist/lib/things/capabilities/nameable.d.ts +18 -0
  191. package/dist/lib/things/capabilities/nameable.js +28 -0
  192. package/dist/lib/things/capabilities/nameable.js.map +1 -0
  193. package/dist/lib/things/capabilities/power.d.ts +40 -0
  194. package/dist/lib/things/capabilities/power.js +68 -0
  195. package/dist/lib/things/capabilities/power.js.map +1 -0
  196. package/dist/lib/things/capabilities/sensors.d.ts +91 -0
  197. package/dist/lib/things/capabilities/sensors.js +198 -0
  198. package/dist/lib/things/capabilities/sensors.js.map +1 -0
  199. package/dist/lib/things/capabilities/target-humidity.d.ts +36 -0
  200. package/dist/lib/things/capabilities/target-humidity.js +59 -0
  201. package/dist/lib/things/capabilities/target-humidity.js.map +1 -0
  202. package/dist/lib/things/capability.d.ts +24 -0
  203. package/dist/lib/things/capability.js +21 -0
  204. package/dist/lib/things/capability.js.map +1 -0
  205. package/dist/lib/things/color.d.ts +66 -0
  206. package/dist/lib/things/color.js +303 -0
  207. package/dist/lib/things/color.js.map +1 -0
  208. package/dist/lib/things/compose.d.ts +25 -0
  209. package/dist/lib/things/compose.js +105 -0
  210. package/dist/lib/things/compose.js.map +1 -0
  211. package/dist/lib/things/index.d.ts +14 -0
  212. package/dist/lib/things/index.js +39 -0
  213. package/dist/lib/things/index.js.map +1 -0
  214. package/dist/lib/things/registry.d.ts +19 -0
  215. package/dist/lib/things/registry.js +18 -0
  216. package/dist/lib/things/registry.js.map +1 -0
  217. package/dist/lib/things/thing.d.ts +110 -0
  218. package/dist/lib/things/thing.js +325 -0
  219. package/dist/lib/things/thing.js.map +1 -0
  220. package/dist/lib/things/values.d.ts +123 -0
  221. package/dist/lib/things/values.js +258 -0
  222. package/dist/lib/things/values.js.map +1 -0
  223. package/docs/devices/vacuum.md +1 -2
  224. package/package.json +13 -5
  225. package/snapshots/vacuum-specs.json.gz +0 -0
  226. package/dist/lib/devices/gateway/86sw1.d.ts +0 -7
  227. package/dist/lib/devices/gateway/86sw1.js +0 -20
  228. package/dist/lib/devices/gateway/86sw1.js.map +0 -1
  229. package/dist/lib/devices/gateway/86sw2.d.ts +0 -7
  230. package/dist/lib/devices/gateway/86sw2.js +0 -36
  231. package/dist/lib/devices/gateway/86sw2.js.map +0 -1
  232. package/dist/lib/devices/gateway/cube.d.ts +0 -6
  233. package/dist/lib/devices/gateway/cube.js +0 -49
  234. package/dist/lib/devices/gateway/cube.js.map +0 -1
  235. package/dist/lib/devices/gateway/light-mixin.d.ts +0 -2
  236. package/dist/lib/devices/gateway/light-mixin.js +0 -59
  237. package/dist/lib/devices/gateway/light-mixin.js.map +0 -1
  238. package/dist/lib/devices/gateway/magnet.d.ts +0 -6
  239. package/dist/lib/devices/gateway/magnet.js +0 -23
  240. package/dist/lib/devices/gateway/magnet.js.map +0 -1
  241. package/dist/lib/devices/gateway/magnet2.d.ts +0 -5
  242. package/dist/lib/devices/gateway/magnet2.js +0 -9
  243. package/dist/lib/devices/gateway/magnet2.js.map +0 -1
  244. package/dist/lib/devices/gateway/motion.d.ts +0 -6
  245. package/dist/lib/devices/gateway/motion.js +0 -21
  246. package/dist/lib/devices/gateway/motion.js.map +0 -1
  247. package/dist/lib/devices/gateway/motion2.d.ts +0 -6
  248. package/dist/lib/devices/gateway/motion2.js +0 -25
  249. package/dist/lib/devices/gateway/motion2.js.map +0 -1
  250. package/dist/lib/devices/gateway/sensor_ht.d.ts +0 -5
  251. package/dist/lib/devices/gateway/sensor_ht.js +0 -13
  252. package/dist/lib/devices/gateway/sensor_ht.js.map +0 -1
  253. package/dist/lib/devices/gateway/switch.d.ts +0 -6
  254. package/dist/lib/devices/gateway/switch.js +0 -24
  255. package/dist/lib/devices/gateway/switch.js.map +0 -1
  256. package/dist/lib/devices/gateway/switch2.d.ts +0 -6
  257. package/dist/lib/devices/gateway/switch2.js +0 -19
  258. package/dist/lib/devices/gateway/switch2.js.map +0 -1
  259. package/dist/lib/devices/gateway/weather.d.ts +0 -5
  260. package/dist/lib/devices/gateway/weather.js +0 -16
  261. package/dist/lib/devices/gateway/weather.js.map +0 -1
  262. package/dist/types/abstract-things/climate/index.d.ts +0 -431
  263. package/dist/types/abstract-things/electricals/index.d.ts +0 -5
  264. package/dist/types/abstract-things/index.d.ts +0 -206
  265. package/dist/types/abstract-things/lights/index.d.ts +0 -14
  266. package/dist/types/abstract-things/values/index.d.ts +0 -12
@@ -1,70 +1,90 @@
1
- declare const _exports: new (parent?: any, info?: any) => {
2
- miioModel: any;
3
- id: any;
4
- internalId: any;
5
- _properties: {};
6
- _propertiesToMonitor: any[];
7
- _propertyDefinitions: {};
8
- _parent: any;
9
- _report(data: any): void;
10
- management: SubDeviceManagement;
11
- hasCapability(name: any): boolean;
12
- initCallback(): Promise<any>;
13
- destroyCallback(): Promise<any>;
14
- _currentRead: {} | null | undefined;
15
- get properties(): {};
16
- property(key: any): any;
1
+ import type { EventEmitter } from "node:events";
2
+ import { MiioThing } from "../../things/thing";
3
+ import type { CallOptions, Device } from "../../device";
4
+ import type { Protocol } from "../../protocol";
5
+ /** What a sub-device needs from its gateway */
6
+ export interface SubDeviceParent {
7
+ readonly id: string | null;
8
+ /** The local developer API, which reports the properties of the sub-devices */
9
+ devApi?: EventEmitter & {
10
+ read(sid: string): void;
11
+ };
12
+ call: Device["call"];
13
+ }
14
+ export interface SubDeviceInfo {
15
+ id: string;
16
+ model: string;
17
+ }
18
+ interface SubDevicePropertyDefinition {
19
+ name?: string;
20
+ mapper: (value: never) => unknown;
21
+ /** Whether it's polled (default: `true`) */
22
+ poll?: boolean;
23
+ }
24
+ declare class SubDeviceManagement {
25
+ private readonly device;
26
+ readonly parent: SubDeviceParent;
27
+ constructor(device: SubDevice, parent: SubDeviceParent);
28
+ get token(): null;
29
+ get model(): string;
30
+ info(): Promise<{
31
+ id: string | null;
32
+ model: string;
33
+ }>;
34
+ }
35
+ /**
36
+ * A device connected to a gateway (Aqara sensors, switches…). Its properties are reported by the gateway's developer
37
+ * API, and its calls are sent through the gateway (with its `sid`).
38
+ */
39
+ export declare class SubDevice extends MiioThing {
40
+ protected readonly _parent: SubDeviceParent;
41
+ static get types(): string[];
42
+ miioModel: string;
43
+ /** The id without the `miio:` prefix */
44
+ readonly internalId: string;
45
+ readonly management: SubDeviceManagement;
46
+ constructor(_parent: SubDeviceParent, info: SubDeviceInfo);
47
+ initCallback(): Promise<void>;
48
+ destroyCallback(): Promise<void>;
17
49
  /**
18
- * Define a property and how the value should be mapped. All defined
19
- * properties are monitored if #monitor() is called.
50
+ * Handles the properties reported by the developer API.
20
51
  *
21
- * @param {string} name The raw property name
22
- * @param {object} def How the value is mapped
52
+ * @param data The reported properties
23
53
  */
24
- defineProperty(name: string, def: object): void;
25
- setProperty(key: any, value: any): void;
26
- propertyUpdated(_key: any, _value: any, _oldValue: any): void;
27
- getProperties(props?: any[]): {};
54
+ _report(data: Record<string, unknown>): void;
55
+ get properties(): {
56
+ [x: string]: unknown;
57
+ };
58
+ property<T>(key: string): T;
28
59
  /**
29
- * Stub for loadProperties to match full device.
60
+ * Defines a property and how its value is mapped.
30
61
  *
31
- * @param {string[]} props The properties to load
62
+ * @param name The raw property name
63
+ * @param def How the value is mapped
32
64
  */
33
- loadProperties(props: string[]): any;
65
+ defineProperty(name: string, def?: ((value: never) => unknown) | (Partial<SubDevicePropertyDefinition> & {
66
+ mapper?: (value: never) => unknown;
67
+ })): void;
68
+ setProperty(key: string, value: unknown): void;
69
+ propertyUpdated(_key: string, _value: unknown, _oldValue?: unknown): void;
70
+ getProperties(props?: string[]): {
71
+ [k: string]: unknown;
72
+ };
34
73
  /**
35
- * Call a method for this sub device.
74
+ * Reads the properties through the developer API, falling back to a regular call after a second.
36
75
  *
37
- * @param {string} method The method
38
- * @param {Array} args The arguments
39
- * @param {object} options Call options
76
+ * @param props The properties to return
77
+ * @returns The properties
40
78
  */
41
- call(method: string, args: any[], options: object): any;
42
- [util.inspect.custom](depth: any, options: any): string;
43
- metadata: Record<string, unknown> & {
44
- types: string[];
45
- capabilities: string[];
46
- addCapabilities(...capabilities: string[]): void;
47
- };
48
- init(): Promise</*elided*/ any | undefined>;
49
- destroy(): Promise<void>;
50
- debug(...parts: unknown[]): void;
51
- matches(...tags: string[]): boolean;
52
- emitEvent(event: string, data?: unknown, options?: unknown): void;
53
- on(event: string, listener: (...args: never[]) => void): unknown;
54
- off(event: string, listener: (...args: never[]) => void): unknown;
55
- extendWith<T>(...mixins: T[]): T & Thing;
56
- } & Thing;
57
- export = _exports;
58
- declare class SubDeviceManagement {
59
- constructor(device: any, parent: any);
60
- _device: any;
61
- parent: any;
62
- get token(): null;
63
- get model(): any;
64
- info(): Promise<{
65
- id: any;
66
- model: any;
67
- }>;
79
+ loadProperties(props?: string[]): Promise<Record<string, unknown>>;
80
+ /**
81
+ * Calls a method of this sub-device (through the gateway).
82
+ *
83
+ * @param method The method
84
+ * @param args Its arguments
85
+ * @param options The call options
86
+ * @returns The response
87
+ */
88
+ call<Method extends keyof Protocol, Params extends Protocol[Method]["params"], Response extends Protocol[Method]["response"]>(method: Method, args: Params, options?: CallOptions): Promise<Response>;
68
89
  }
69
- import util = require("node:util");
70
- import { Thing } from "abstract-things";
90
+ export {};
@@ -1,162 +1,165 @@
1
1
  "use strict";
2
- const util = require("node:util");
3
- const isDeepEqual = require("deep-equal");
4
- const { Thing } = require("abstract-things");
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.SubDevice = void 0;
7
+ const node_util_1 = __importDefault(require("node:util"));
8
+ const deep_equal_1 = __importDefault(require("deep-equal"));
9
+ const thing_1 = require("../../things/thing");
5
10
  const IDENTITY_MAPPER = (v) => v;
6
11
  class SubDeviceManagement {
12
+ device;
13
+ parent;
7
14
  constructor(device, parent) {
8
- this._device = device;
15
+ this.device = device;
9
16
  this.parent = parent;
10
17
  }
11
18
  get token() {
12
19
  return null;
13
20
  }
14
21
  get model() {
15
- return this._device.miioModel;
22
+ return this.device.miioModel;
16
23
  }
17
24
  info() {
18
- const device = this._device;
19
25
  return Promise.resolve({
20
- id: device.id,
21
- model: device.model,
26
+ id: this.device.id,
27
+ model: this.device.miioModel,
22
28
  });
23
29
  }
24
30
  }
25
- module.exports = Thing.type((Parent) => class SubDevice extends Parent {
31
+ /**
32
+ * A device connected to a gateway (Aqara sensors, switches…). Its properties are reported by the gateway's developer
33
+ * API, and its calls are sent through the gateway (with its `sid`).
34
+ */
35
+ class SubDevice extends thing_1.MiioThing {
36
+ _parent;
26
37
  static get types() {
27
38
  return ["miio", "miio:subdevice"];
28
39
  }
29
- constructor(parent, info) {
40
+ miioModel;
41
+ /** The id without the `miio:` prefix */
42
+ internalId;
43
+ management;
44
+ /** @internal */
45
+ _properties = {};
46
+ /** @internal */
47
+ _propertiesToMonitor = [];
48
+ /** @internal */
49
+ _propertyDefinitions = {};
50
+ /** @internal */
51
+ _currentRead = null;
52
+ constructor(_parent, info) {
30
53
  super();
54
+ this._parent = _parent;
31
55
  this.miioModel = info.model;
32
56
  this.id = info.id;
33
- // Store the internal id by removing the `miio:` prefix
34
57
  this.internalId = info.id.substring(5);
35
- this._properties = {};
36
- this._propertiesToMonitor = [];
37
- this._propertyDefinitions = {};
38
- this._parent = parent;
39
- // Bind the _report function for use with developer API
58
+ this.management = new SubDeviceManagement(this, _parent);
59
+ // Bound, to be used as a listener of the developer API
40
60
  this._report = this._report.bind(this);
41
- this.management = new SubDeviceManagement(this, parent);
42
- }
43
- hasCapability(name) {
44
- return this.capabilities.indexOf(name) >= 0;
61
+ Object.defineProperty(this, node_util_1.default.inspect.custom, {
62
+ value: (depth, options) => {
63
+ const name = options.stylize("MiioDevice", "special");
64
+ if (depth === 0)
65
+ return `${name}[${this.miioModel}]`;
66
+ return (`${name} {\n model=${this.miioModel},\n` +
67
+ ` types=${Array.from(this.metadata.types).join(", ")},\n` +
68
+ ` capabilities=${Array.from(this.metadata.capabilities).join(", ")}\n}`);
69
+ },
70
+ });
45
71
  }
46
- initCallback() {
47
- return super
48
- .initCallback()
49
- .then(() => this._parent.devApi.on("properties:" + this.internalId, this._report))
50
- .then(() => this.loadProperties());
72
+ async initCallback() {
73
+ await super.initCallback();
74
+ this._parent.devApi?.on(`properties:${this.internalId}`, this._report);
75
+ await this.loadProperties();
51
76
  }
52
- destroyCallback() {
53
- return super
54
- .destroyCallback()
55
- .then(() => this._parent.devApi.removeListener("properties:" + this.internalId, this._report));
77
+ async destroyCallback() {
78
+ await super.destroyCallback();
79
+ this._parent.devApi?.removeListener(`properties:${this.internalId}`, this._report);
56
80
  }
81
+ /**
82
+ * Handles the properties reported by the developer API.
83
+ *
84
+ * @param data The reported properties
85
+ */
57
86
  _report(data) {
58
- this._propertiesToMonitor.forEach((key) => {
87
+ for (const key of this._propertiesToMonitor) {
88
+ const value = data[key];
89
+ if (value === undefined)
90
+ continue;
59
91
  const def = this._propertyDefinitions[key];
60
- let name = key;
61
- let value = data[key];
62
- if (typeof value === "undefined")
63
- return;
64
- if (def) {
65
- name = def.name || name;
66
- value = def.mapper(value);
67
- }
68
- this.setProperty(name, value);
69
- });
92
+ this.setProperty(def?.name ?? key, def ? def.mapper(value) : value);
93
+ }
70
94
  if (this._currentRead) {
71
- this._currentRead.resolve();
95
+ this._currentRead.resolve?.();
72
96
  this._currentRead = null;
73
97
  }
74
98
  }
75
99
  get properties() {
76
- return Object.assign({}, this._properties);
100
+ return { ...this._properties };
77
101
  }
78
102
  property(key) {
79
103
  return this._properties[key];
80
104
  }
81
105
  /**
82
- * Define a property and how the value should be mapped. All defined
83
- * properties are monitored if #monitor() is called.
106
+ * Defines a property and how its value is mapped.
84
107
  *
85
- * @param {string} name The raw property name
86
- * @param {object} def How the value is mapped
108
+ * @param name The raw property name
109
+ * @param def How the value is mapped
87
110
  */
88
111
  defineProperty(name, def) {
89
- if (!def || typeof def.poll === "undefined" || def.poll) {
112
+ if (typeof def !== "object" || def.poll === undefined || def.poll) {
90
113
  this._propertiesToMonitor.push(name);
91
114
  }
92
- if (typeof def === "function") {
93
- def = {
94
- mapper: def,
95
- };
96
- }
97
- else if (typeof def === "undefined") {
98
- def = {
99
- mapper: IDENTITY_MAPPER,
100
- };
101
- }
102
- if (!def.mapper) {
103
- def.mapper = IDENTITY_MAPPER;
104
- }
105
- this._propertyDefinitions[name] = def;
115
+ const definition = typeof def === "function"
116
+ ? { mapper: def }
117
+ : { ...def, mapper: def?.mapper ?? IDENTITY_MAPPER };
118
+ this._propertyDefinitions[name] = definition;
106
119
  }
107
120
  setProperty(key, value) {
108
121
  const oldValue = this._properties[key];
109
- if (!isDeepEqual(oldValue, value)) {
122
+ if (!(0, deep_equal_1.default)(oldValue, value)) {
110
123
  this._properties[key] = value;
111
124
  this.debug("Property", key, "changed from", oldValue, "to", value);
112
125
  this.propertyUpdated(key, value, oldValue);
126
+ this.runCapabilityHooksSync("capabilityPropertyUpdated", key, value, oldValue);
113
127
  }
114
128
  }
115
129
  propertyUpdated(_key, _value, _oldValue) { }
116
130
  getProperties(props = []) {
117
- const result = {};
118
- props.forEach((key) => {
119
- result[key] = this._properties[key];
120
- });
121
- return result;
131
+ return Object.fromEntries(props.map((key) => [key, this._properties[key]]));
122
132
  }
123
133
  /**
124
- * Stub for loadProperties to match full device.
134
+ * Reads the properties through the developer API, falling back to a regular call after a second.
125
135
  *
126
- * @param {string[]} props The properties to load
136
+ * @param props The properties to return
137
+ * @returns The properties
127
138
  */
128
139
  loadProperties(props) {
129
- if (this._currentRead) {
140
+ if (this._currentRead?.promise)
130
141
  return this._currentRead.promise;
131
- }
132
- // Store information about the current read promise and how to resolve it
133
- this._currentRead = {};
134
- this._currentRead.promise = new Promise((resolve, reject) => {
135
- // Request the read
136
- this._parent.devApi.read(this.internalId);
137
- // Store the resolve to be used in _report
138
- this._currentRead.resolve = () => {
139
- resolve(this.getProperties(props));
140
- };
141
- /*
142
- * Fallback behavior, use a regular call if properties have not
143
- * been resolved in a second.
144
- */
142
+ const currentRead = {};
143
+ this._currentRead = currentRead;
144
+ currentRead.promise = new Promise((resolve, reject) => {
145
+ currentRead.resolve = () => resolve(this.getProperties(props));
146
+ this._parent.devApi?.read(this.internalId);
147
+ // Fallback: a regular call if the properties haven't been reported in a second
145
148
  setTimeout(async () => {
149
+ if (this._currentRead !== currentRead)
150
+ return;
146
151
  this.debug("Read via DEV timed out, using fallback API");
147
152
  try {
148
- const result = await this._parent.call("get_device_prop_exp", [
153
+ const result = (await this._parent.call("get_device_prop_exp", [
149
154
  ["lumi." + this.internalId, ...this._propertiesToMonitor],
150
- ]);
151
- for (let i = 0; i < result[0].length; i++) {
152
- let name = this._propertiesToMonitor[i];
153
- const def = this._propertyDefinitions[name];
154
- let value = result[0][i];
155
- name = def.name || name;
156
- value = def.mapper(value);
157
- this.setProperty(name, value);
158
- }
159
- this._currentRead.resolve();
155
+ ]));
156
+ result[0].forEach((raw, i) => {
157
+ const key = this._propertiesToMonitor[i];
158
+ const def = this._propertyDefinitions[key];
159
+ this.setProperty(def?.name ?? key, def ? def.mapper(raw) : raw);
160
+ });
161
+ currentRead.resolve?.();
162
+ this._currentRead = null;
160
163
  }
161
164
  catch (err) {
162
165
  this._currentRead = null;
@@ -164,40 +167,22 @@ module.exports = Thing.type((Parent) => class SubDevice extends Parent {
164
167
  }
165
168
  }, 1000);
166
169
  });
167
- return this._currentRead.promise;
170
+ return currentRead.promise;
168
171
  }
169
172
  /**
170
- * Call a method for this sub device.
173
+ * Calls a method of this sub-device (through the gateway).
171
174
  *
172
- * @param {string} method The method
173
- * @param {Array} args The arguments
174
- * @param {object} options Call options
175
+ * @param method The method
176
+ * @param args Its arguments
177
+ * @param options The call options
178
+ * @returns The response
175
179
  */
176
- call(method, args, options) {
177
- if (!options) {
178
- options = {};
179
- }
180
- options.sid = this.internalId;
181
- return this._parent.call(method, args, options);
182
- }
183
- [util.inspect.custom](depth, options) {
184
- if (depth === 0) {
185
- return (options.stylize("MiioDevice", "special") +
186
- "[" +
187
- this.miioModel +
188
- "]");
189
- }
190
- return (options.stylize("MiioDevice", "special") +
191
- " {\n" +
192
- " model=" +
193
- this.miioModel +
194
- ",\n" +
195
- " types=" +
196
- Array.from(this.metadata.types).join(", ") +
197
- ",\n" +
198
- " capabilities=" +
199
- Array.from(this.metadata.capabilities).join(", ") +
200
- "\n}");
201
- }
202
- });
180
+ call(method, args, options = {}) {
181
+ return this._parent.call(method, args, {
182
+ ...options,
183
+ sid: this.internalId,
184
+ });
185
+ }
186
+ }
187
+ exports.SubDevice = SubDevice;
203
188
  //# sourceMappingURL=subdevice.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subdevice.js","sourceRoot":"","sources":["../../../../src/lib/devices/gateway/subdevice.js"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,MAAM,IAAI,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;AAElC,MAAM,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAC1C,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAE7C,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAEjC,MAAM,mBAAmB;IACvB,YAAY,MAAM,EAAE,MAAM;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC;IAChC,CAAC;IAED,IAAI;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAC5B,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,EAAE,EAAE,MAAM,CAAC,EAAE;YACb,KAAK,EAAE,MAAM,CAAC,KAAK;SACpB,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,OAAO,GAAG,KAAK,CAAC,IAAI,CACzB,CAAC,MAAM,EAAE,EAAE,CACT,MAAM,SAAU,SAAQ,MAAM;IAC5B,MAAM,KAAK,KAAK;QACd,OAAO,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;IACpC,CAAC;IAED,YAAY,MAAM,EAAE,IAAI;QACtB,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC;QAC5B,I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OAAO,CAAC;IAC7B,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,CAKF,MAAc,EACd,IAAY,EACZ,UAAuB,EAAE;QAEzB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAA2B,MAAM,EAAE,IAAI,EAAE;YAC/D,GAAG,OAAO;YACV,GAAG,EAAE,IAAI,CAAC,UAAU;SACrB,CAAC,CAAC;IACL,CAAC;CACF;AAhND,8BAgNC"}
@@ -1,49 +1,6 @@
1
- declare const _exports: {
2
- 1: {
3
- new (parent: any, info: any): import("./switch");
4
- };
5
- 2: {
6
- new (parent: any, info: any): import("./motion");
7
- };
8
- 3: {
9
- new (parent: any, info: any): import("./magnet");
10
- };
11
- 7: {
12
- new (parent: any, info: any): import("./ctrl_neutral2");
13
- get type(): string;
14
- };
15
- 8: {
16
- new (parent: any, info: any): import("./cube");
17
- };
18
- 9: {
19
- new (parent: any, info: any): import("./ctrl_neutral1");
20
- get type(): string;
21
- };
22
- 10: {
23
- new (parent: any, info: any): import("./sensor_ht");
24
- };
25
- 11: {
26
- new (parent: any, info: any): import("./plug");
27
- };
28
- 19: {
29
- new (parent: any, info: any): import("./weather");
30
- };
31
- 20: {
32
- new (parent: any, info: any): import("./ctrl_ln1");
33
- get type(): string;
34
- };
35
- 21: {
36
- new (parent: any, info: any): import("./ctrl_ln2");
37
- get type(): string;
38
- };
39
- 51: {
40
- new (parent: any, info: any): import("./switch2");
41
- };
42
- 52: {
43
- new (parent: any, info: any): import("./motion2");
44
- };
45
- 53: {
46
- new (...args: any[]): import("./magnet2");
47
- };
48
- };
49
- export = _exports;
1
+ import { Switch1, Switch2 } from "./controllers";
2
+ import type { SubDevice, SubDeviceInfo, SubDeviceParent } from "./subdevice";
3
+ export type SubDeviceClass = new (parent: SubDeviceParent, info: SubDeviceInfo) => SubDevice;
4
+ /** The sub-device classes, by the type id the gateway reports */
5
+ export declare const subDeviceTypes: Record<string, SubDeviceClass>;
6
+ export { Switch1, Switch2 };
@@ -1,33 +1,45 @@
1
1
  "use strict";
2
- module.exports = {
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Switch2 = exports.Switch1 = exports.subDeviceTypes = void 0;
4
+ const controllers_1 = require("./controllers");
5
+ Object.defineProperty(exports, "Switch1", { enumerable: true, get: function () { return controllers_1.Switch1; } });
6
+ Object.defineProperty(exports, "Switch2", { enumerable: true, get: function () { return controllers_1.Switch2; } });
7
+ const ctrl_ln1_1 = require("./ctrl_ln1");
8
+ const ctrl_ln2_1 = require("./ctrl_ln2");
9
+ const ctrl_neutral1_1 = require("./ctrl_neutral1");
10
+ const ctrl_neutral2_1 = require("./ctrl_neutral2");
11
+ const plug_1 = require("./plug");
12
+ const sensors_1 = require("./sensors");
13
+ /** The sub-device classes, by the type id the gateway reports */
14
+ exports.subDeviceTypes = {
3
15
  // Switch (button) controller
4
- 1: require("./switch"),
16
+ 1: controllers_1.Switch,
5
17
  // Motion sensor
6
- 2: require("./motion"),
18
+ 2: sensors_1.MotionSensor,
7
19
  // Magnet sensor for doors and windows
8
- 3: require("./magnet"),
20
+ 3: sensors_1.Magnet,
9
21
  // TODO: What is 4, 5 and 6? plug, 86sw1 and 86sw2 are left
10
22
  // Light switch with two channels
11
- 7: require("./ctrl_neutral2"),
23
+ 7: ctrl_neutral2_1.CtrlNeutral2,
12
24
  // Cube controller
13
- 8: require("./cube"),
25
+ 8: controllers_1.Cube,
14
26
  // Light switch with one channel
15
- 9: require("./ctrl_neutral1"),
27
+ 9: ctrl_neutral1_1.CtrlNeutral1,
16
28
  // Temperature and Humidity sensor
17
- 10: require("./sensor_ht"),
29
+ 10: sensors_1.SensorHT,
18
30
  // Plug
19
- 11: require("./plug"),
31
+ 11: plug_1.Plug,
20
32
  // Aqara Temperature/Humidity/Pressure sensor
21
- 19: require("./weather"),
33
+ 19: sensors_1.WeatherSensor,
22
34
  // Light switch (live+neutral wire version) with one channel
23
- 20: require("./ctrl_ln1"),
35
+ 20: ctrl_ln1_1.CtrlLN1,
24
36
  // Light switch (live+neutral wire version) with two channels
25
- 21: require("./ctrl_ln2"),
37
+ 21: ctrl_ln2_1.CtrlLN2,
26
38
  // AQ2 switch (square version)
27
- 51: require("./switch2"),
39
+ 51: controllers_1.SwitchV2,
28
40
  // AQ2 motion sensor
29
- 52: require("./motion2"),
41
+ 52: sensors_1.MotionSensorAq2,
30
42
  // AQ2 manget sensor
31
- 53: require("./magnet2"),
43
+ 53: sensors_1.MagnetAq2,
32
44
  };
33
45
  //# sourceMappingURL=subdevices.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"subdevices.js","sourceRoot":"","sources":["../../../../src/lib/devices/gateway/subdevices.js"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,MAAM,CAAC,OAAO,GAAG;IACf,6BAA6B;IAC7B,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC;IACtB,gBAAgB;IAChB,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC;IACtB,sCAAsC;IACtC,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC;IAEtB,2DAA2D;IAE3D,iCAAiC;IACjC,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAC7B,kBAAkB;IAClB,CAAC,EAAE,OAAO,CAAC,QAAQ,CAAC;IACpB,gCAAgC;IAChC,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAC7B,kCAAkC;IAClC,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC;IAC1B,OAAO;IACP,EAAE,EAAE,OAAO,CAAC,QAAQ,CAAC;IAErB,6CAA6C;IAC7C,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC;IACxB,4DAA4D;IAC5D,EAAE,EAAE,OAAO,CAAC,YAAY,CAAC;IACzB,6DAA6D;IAC7D,EAAE,EAAE,OAAO,CAAC,YAAY,CAAC;IAEzB,8BAA8B;IAC9B,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC;IACxB,oBAAoB;IACpB,EAAE,EAAE,OAAO,CAAC,WAAW,CAAC;IACxB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