node-miio 0.0.0-dev-20250810-f1674d0

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 (104) hide show
  1. package/.editorconfig +21 -0
  2. package/.eslintrc +32 -0
  3. package/.github/workflows/build.yml +50 -0
  4. package/.github/workflows/codecov.yml +35 -0
  5. package/.github/workflows/codeql.yml +24 -0
  6. package/.github/workflows/publish-dev-from-main.yml +92 -0
  7. package/.github/workflows/publish-release-to-npm.yml +48 -0
  8. package/CONTRIBUTING.md +104 -0
  9. package/LICENSE.md +20 -0
  10. package/README.md +216 -0
  11. package/cli/commands/configure.js +69 -0
  12. package/cli/commands/control.js +54 -0
  13. package/cli/commands/discover.js +36 -0
  14. package/cli/commands/inspect.js +197 -0
  15. package/cli/commands/protocol/call.js +66 -0
  16. package/cli/commands/protocol/json-dump.js +52 -0
  17. package/cli/commands/protocol/packet.js +29 -0
  18. package/cli/commands/protocol.js +8 -0
  19. package/cli/commands/tokens/update.js +58 -0
  20. package/cli/commands/tokens.js +8 -0
  21. package/cli/device-finder.js +66 -0
  22. package/cli/index.js +9 -0
  23. package/cli/log.js +89 -0
  24. package/docs/advanced-api.md +103 -0
  25. package/docs/devices/README.md +111 -0
  26. package/docs/devices/air-purifier.md +142 -0
  27. package/docs/devices/controller.md +89 -0
  28. package/docs/devices/gateway.md +41 -0
  29. package/docs/devices/humidifier.md +136 -0
  30. package/docs/devices/light.md +141 -0
  31. package/docs/devices/power-outlet.md +56 -0
  32. package/docs/devices/power-plug.md +69 -0
  33. package/docs/devices/power-strip.md +73 -0
  34. package/docs/devices/sensor.md +74 -0
  35. package/docs/devices/vacuum.md +80 -0
  36. package/docs/devices/wall-switch.md +62 -0
  37. package/docs/management.md +109 -0
  38. package/docs/missing-devices.md +48 -0
  39. package/docs/protocol.md +77 -0
  40. package/docs/reporting-issues.md +47 -0
  41. package/example.js +11 -0
  42. package/lib/checkResult.js +13 -0
  43. package/lib/connectToDevice.js +62 -0
  44. package/lib/device.js +290 -0
  45. package/lib/device_info.js +329 -0
  46. package/lib/device_info.test.js +337 -0
  47. package/lib/devices/air-monitor.js +53 -0
  48. package/lib/devices/air-purifier.js +162 -0
  49. package/lib/devices/capabilities/battery-level.js +16 -0
  50. package/lib/devices/capabilities/buzzer.js +78 -0
  51. package/lib/devices/capabilities/changeable-led-brightness.js +48 -0
  52. package/lib/devices/capabilities/colorable.js +14 -0
  53. package/lib/devices/capabilities/dimmable.js +14 -0
  54. package/lib/devices/capabilities/mode.js +13 -0
  55. package/lib/devices/capabilities/power.js +14 -0
  56. package/lib/devices/capabilities/sensor.js +50 -0
  57. package/lib/devices/capabilities/switchable-led.js +49 -0
  58. package/lib/devices/chuangmi.plug.v1.js +61 -0
  59. package/lib/devices/eyecare-lamp2.js +179 -0
  60. package/lib/devices/gateway/86sw1.js +28 -0
  61. package/lib/devices/gateway/86sw2.js +44 -0
  62. package/lib/devices/gateway/ctrl_ln1.js +44 -0
  63. package/lib/devices/gateway/ctrl_ln2.js +53 -0
  64. package/lib/devices/gateway/ctrl_neutral1.js +44 -0
  65. package/lib/devices/gateway/ctrl_neutral2.js +53 -0
  66. package/lib/devices/gateway/cube.js +55 -0
  67. package/lib/devices/gateway/developer-api.js +120 -0
  68. package/lib/devices/gateway/light-channel.js +32 -0
  69. package/lib/devices/gateway/light-mixin.js +71 -0
  70. package/lib/devices/gateway/magnet.js +29 -0
  71. package/lib/devices/gateway/magnet2.js +13 -0
  72. package/lib/devices/gateway/motion.js +27 -0
  73. package/lib/devices/gateway/motion2.js +31 -0
  74. package/lib/devices/gateway/plug.js +45 -0
  75. package/lib/devices/gateway/sensor_ht.js +17 -0
  76. package/lib/devices/gateway/subdevice.js +227 -0
  77. package/lib/devices/gateway/subdevices.js +37 -0
  78. package/lib/devices/gateway/switch.js +29 -0
  79. package/lib/devices/gateway/switch2.js +27 -0
  80. package/lib/devices/gateway/voltage.js +28 -0
  81. package/lib/devices/gateway/weather.js +22 -0
  82. package/lib/devices/gateway.js +244 -0
  83. package/lib/devices/humidifier.js +162 -0
  84. package/lib/devices/mijiavacuum.js +22 -0
  85. package/lib/devices/philips-light-bulb.js +73 -0
  86. package/lib/devices/power-plug.js +26 -0
  87. package/lib/devices/power-strip.js +38 -0
  88. package/lib/devices/vacuum.js +412 -0
  89. package/lib/devices/viomivacuum.js +250 -0
  90. package/lib/devices/yeelight.color.js +6 -0
  91. package/lib/devices/yeelight.js +286 -0
  92. package/lib/devices/yeelight.mono.js +9 -0
  93. package/lib/discovery.js +192 -0
  94. package/lib/index.js +40 -0
  95. package/lib/infoFromHostname.js +24 -0
  96. package/lib/management.js +102 -0
  97. package/lib/models.js +77 -0
  98. package/lib/network.js +234 -0
  99. package/lib/packet.js +191 -0
  100. package/lib/placeholder.js +12 -0
  101. package/lib/safeishJSON.js +14 -0
  102. package/lib/tokens.js +129 -0
  103. package/npm-shrinkwrap.json +853 -0
  104. package/package.json +40 -0
package/cli/log.js ADDED
@@ -0,0 +1,89 @@
1
+ 'use strict';
2
+
3
+ /* eslint no-console: 0 */
4
+
5
+ const chalk = require('chalk');
6
+
7
+ module.exports = {
8
+ indent: '',
9
+
10
+ info(...args) {
11
+ console.log(this.indent + chalk.bgWhite.black(' INFO '), args.join(' '));
12
+ },
13
+
14
+ error(...args) {
15
+ console.log(this.indent + chalk.bgRed.white(' ERROR '), args.join(' '));
16
+ },
17
+
18
+ warn(...args) {
19
+ console.log(
20
+ this.indent + chalk.bgYellow.black(' WARNING '),
21
+ args.join(' ')
22
+ );
23
+ },
24
+
25
+ plain(...args) {
26
+ console.log(this.indent + args.join(' '));
27
+ },
28
+
29
+ group(g) {
30
+ let indent = this.indent;
31
+ this.indent += ' ';
32
+ try {
33
+ g();
34
+ } finally {
35
+ this.indent = indent;
36
+ }
37
+ },
38
+
39
+ device(device, detailed = false) {
40
+ const mgmt = device.management;
41
+
42
+ const types = Array.from(device.metadata.types);
43
+ const filteredTypes = types.filter((t) => t.indexOf('miio:') === 0);
44
+ const caps = Array.from(device.metadata.capabilities);
45
+
46
+ this.plain(chalk.bold('Device ID:'), device.id.replace(/^miio:/, ''));
47
+ this.plain(chalk.bold('Model info:'), mgmt.model || 'Unknown');
48
+
49
+ if (mgmt.address) {
50
+ this.plain(chalk.bold('Address:'), mgmt.address);
51
+ } else if (mgmt.parent) {
52
+ this.plain(chalk.bold('Address:'), 'Owned by', mgmt.parent.id);
53
+ }
54
+
55
+ if (mgmt.token) {
56
+ this.plain(
57
+ chalk.bold('Token:'),
58
+ mgmt.token,
59
+ mgmt.autoToken
60
+ ? chalk.green('via auto-token')
61
+ : chalk.yellow('via stored token')
62
+ );
63
+ } else if (!mgmt.parent) {
64
+ this.plain(chalk.bold('Token:'), '???');
65
+ } else {
66
+ this.plain(
67
+ chalk.bold('Token:'),
68
+ chalk.green('Automatic via parent device')
69
+ );
70
+ }
71
+
72
+ this.plain(
73
+ chalk.bold('Support:'),
74
+ mgmt.model
75
+ ? filteredTypes.length > 0
76
+ ? chalk.green('At least basic')
77
+ : chalk.yellow('At least generic')
78
+ : chalk.yellow('Unknown')
79
+ );
80
+
81
+ if (detailed) {
82
+ this.plain();
83
+ this.plain(chalk.bold('Type info:'), types.join(', '));
84
+ this.plain(chalk.bold('Capabilities:'), caps.join(', '));
85
+ }
86
+
87
+ this.plain();
88
+ },
89
+ };
@@ -0,0 +1,103 @@
1
+ # Advanced API
2
+
3
+ ## `miio.browse()`
4
+
5
+ `miio.browse()` can be used to discover devices on the local network.
6
+
7
+ ```javascript
8
+ const browser = miio.browse({
9
+ cacheTime: 300 // 5 minutes. Default is 1800 seconds (30 minutes)
10
+ });
11
+
12
+ const devices = {};
13
+ browser.on('available', reg => {
14
+ if(! reg.token) {
15
+ console.log(reg.id, 'hides its token');
16
+ return;
17
+ }
18
+
19
+ // Directly connect to the device anyways - so use miio.devices() if you just do this
20
+ reg.connect()
21
+ .then(device => {
22
+ devices[reg.id] = device;
23
+
24
+ // Do something useful with the device
25
+ })
26
+ .catch(handleErrorProperlyHere);
27
+ });
28
+
29
+ browser.on('unavailable', reg => {
30
+ const device = devices[reg.id];
31
+ if(! device) return;
32
+
33
+ device.destroy();
34
+ delete devices[reg.id];
35
+ })
36
+ ```
37
+
38
+ You can also use mDNS for discovery, but this library does not contain a mDNS
39
+ implementation. You can choose a mDNS-implementation suitable for your
40
+ needs. Devices announce themselves via `_miio._udp` and should work for most
41
+ devices, in certain cases you might need to restart your device to make it
42
+ announce itself.
43
+
44
+ ## `device.call(method, args)` - Raw API-usage and calling the Xiaomi miIO-method directly
45
+
46
+ It's possible to call any method directly on a device without using the
47
+ top-level API. This is useful if some aspect of your device is not yet
48
+ supported by the library.
49
+
50
+ ```javascript
51
+ // Call any method via call
52
+ device.call('set_mode', [ 'silent' ])
53
+ .then(console.log)
54
+ .catch(console.error);
55
+ ```
56
+
57
+ **Important**: `call` is advanced usage, the library does very little for you
58
+ when using it directly. If you find yourself needing to use it, please open
59
+ and issue and describe your use case so better support can be added.
60
+
61
+ ## Define custom properties
62
+
63
+ If you want to define some custom properties to fetch for a device or if your
64
+ device is not yet supported you can easily do so:
65
+
66
+ ```javascript
67
+ // Define a property that should be monitored
68
+ device.defineProperty('mode');
69
+
70
+ // Define that a certain property should be run through a custom conversion
71
+ device.defineProperty('temp_dec', v => v / 10.0);
72
+
73
+ // Fetch the last value of a monitored property
74
+ const value = device.property('temp_dec');
75
+ ```
76
+
77
+ ## Device management
78
+
79
+ Get information and update the wireless settings of devices via the management
80
+ API.
81
+
82
+ Discover the token of a device:
83
+ ```javascript
84
+ device.discover()
85
+ .then(info => console.log(info.token));
86
+ ```
87
+
88
+ Get internal information about the device:
89
+ ```javascript
90
+ device.management.info()
91
+ .then(console.log);
92
+ ```
93
+
94
+ Update the wireless settings:
95
+ ```javascript
96
+ device.management.updateWireless({
97
+ ssid: 'SSID of network',
98
+ passwd: 'Password of network'
99
+ }).then(console.log);
100
+ ```
101
+
102
+ Warning: The device will either connect to the new network or it will get stuck
103
+ without being able to connect. If that happens the device needs to be reset.
@@ -0,0 +1,111 @@
1
+ # Device types and capabilities
2
+
3
+ To make it easier to work with different devices this library normalizes
4
+ different models into types. These device types have their own API to match
5
+ what the actual device can actually do. In addition each device also has a
6
+ set of capabilities, that are used to flag that a device can do something
7
+ extra on top of its type API.
8
+
9
+ ## Types
10
+
11
+ Name | Description | Devices
12
+ ----------------------|------------------------------------------------------------|---------------------
13
+ [Power strips](power-strip.md) | Power strip with one or more power channels. | Mi Smart Power Strip
14
+ [Power plugs](power-plug.md) | Switchable power plug with one or more power channels | Mi Smart Socket Plug, Aqara Plug
15
+ [Power outlets](power-outlet.md) | Wall mounted outlet | None yet
16
+ [Wall switches](wall-switch.md) | Wall mounted switch with one or more individual power channels. | Aqara Light Control
17
+ [Controllers](controller.md) | Devices that are primarily used to control something else. | Aqara Button, Aqara Cube, Aqara Light Switch
18
+ [Gateways](gateway.md) | Mi Smart Home Gateway that pulls in sub devices of the Aqara type | Mi Smart Home Gateway 2, Mi Smart Home Gateway 3
19
+ [Air purifiers](air-purifier.md) | Air purifiers and air filtering devices. | Mi Air Purifier, Mi Air Purifier 2 and Mi Air Purifier Pro
20
+ [Humidifiers](humidifier.md) | Humidifier. | Mi Humidifier
21
+ [Vacuum](vacuum.md) | Robot vacuums. | Mi Robot Vacuum
22
+ [Lights](light.md) | For any type of lights. | Mi Yeelights
23
+
24
+ ## Models
25
+
26
+ The tables below indicates how well different devices are supported. The support
27
+ column can be one of the following:
28
+
29
+ * ❓ Unknown - support for this device is unknown, you can help test it if you have access to it
30
+ * ❌ None - this device is not a miIO-device or has some quirk making it unusable
31
+ * ⚠️ Generic - this device is supported via the generic API but does not have a high-level API
32
+ * ⚠️ Untested - this device has an implementation but needs testing with a real device
33
+ * ✅ Basic - the basic functionality of the device is implemented, but more advanced features are missing
34
+ * ✅ Good - most of the functionality is available including some more advanced features such as settings
35
+ * ✅ Excellent - as close to complete support as possible
36
+
37
+ If your device:
38
+
39
+ * Is not in this list, it might still be a miIO-device and at least have generic support. See [Missing devices](../missing-devices.md) for information about how to find out.
40
+ * Needs a manual token and the table says it should not, something has probably changed in the firmware, please open an issue so the table can be adjusted.
41
+ * Is marked as Untested you can help by testing the implementation is this library and opening an issue with information about the result.
42
+
43
+ ### Models by name
44
+
45
+ Name | Type | Auto-token | Support | Note
46
+ ------------------------------|---------------|------------|-------------|--------
47
+ Mi Air Purifier 1 | Air purifier | Yes | ⚠️ Untested |
48
+ Mi Air Purifier 2 | Air purifier | Yes | ✅ Good |
49
+ Mi Air Purifier Pro | Air purifier | Yes | ✅ Basic | Some of the new features and sensors are not supported.
50
+ Mi Flora | - | - | ❌ None | Communicates using Bluetooth.
51
+ Mi Lunar Smart Sleep Sensor | Generic | Yes | ⚠️ Generic |
52
+ Mi Robot Vacuum | Vacuum | No | ✅ Basic | DND, timers and mapping features are not supported.
53
+ Mi Smart Socket Plug | Power plug | Yes | ✅ Good |
54
+ Mi Smart Socket Plug 2 | Power plug | Yes | ✅ Good |
55
+ Mi Smart Home Gateway 1 | - | Yes | ⚠️ Generic | API used to access sub devices not supported.
56
+ Mi Smart Home Gateway 2 | Gateway | Yes | ✅ Basic | Light, sound and music features not supported.
57
+ Mi Smart Home Gateway 3 | Gateway | Yes | ✅ Basic | Light, sound and music features not supported.
58
+ Mi Smart Home Cube | Controller | Yes | ✅ Excellent | Aqara device via Smart Home Gateway
59
+ Mi Smart Home Light Switch | Controller | Yes | ⚠️ Untested | Aqara device via Smart Home Gateway.
60
+ Mi Smart Home Light Control | Wall switch | Yes | ⚠️ Untested | Aqara device via Smart Home Gateway. Controls power to one or two lights.
61
+ Mi Smart Home Temperature and Humidity Sensor | Sensor | Yes | Excellent | Aqara device via Smart Home Gateway.
62
+ Mi Smart Home Wireless Switch | Controller | Yes | ✅ Excellent | Aqara device via Smart Home Gateway.
63
+ Mi Smart Home Door / Window Sensor | Sensor | Yes | ⚠️ Untested | Aqara device via Smart Home Gateway.
64
+ Mi Smart Home Occupancy Sensor | Sensor | Yes | ⚠️ Untested | Aqara device via Smart Home Gateway.
65
+ Mi Smart Home Aqara Plug | Power plug | Yes | ⚠️ Untested | Aqara device via Smart Home Gateway.
66
+ Mi Smart Home Smoke Sensor | - | Yes | ❓ Unknown | Aqara device - unknown support
67
+ Mi Smart Home Gas Sensor | - | Yes | ❓ Unknown | Aqara device - unknown support
68
+ Mi Smart Home Outlet | - | Yes | ❓ Unknown | Aqara device - unknown support
69
+ Mi Smart Power Strip 1 | Power strip | Unknown | ✅ Basic | Setting power and mode is untested.
70
+ Mi Smart Power Strip 2 | Power strip | Unknown | ✅ Basic | Setting power and mode is untested.
71
+ Mi Rice Cooker | - | Unknown | ❓ Unknown |
72
+ Mi Humidifier | Humidifier | Yes | ✅ Good |
73
+ Mi Smart Fan | Generic | Unknown | ⚠️ Generic |
74
+ Mi Air Quality Monitor (PM2.5)| Sensor | Unknown | ✅ Good |
75
+ Yeelight Desk Lamp | Light | No | ✅ Good |
76
+ Yeelight Color Bulb | Light | No | ✅ Good |
77
+ Yeelight White Bulb | Light | No | ✅ Good |
78
+ Yeelight LED Strip | Light | No | ⚠️ Untested |
79
+ Yeelight Ceiling Lamp | - | - | ❓ Unknown |
80
+ Yeelight Bedside Lamp | - | - | ❓ Unknown |
81
+ Mi Washing Machine | - | - | ❓ Unknown |
82
+ Mi IR Remote | - | - | ❓ Unknown |
83
+
84
+ ### Models by identifier
85
+
86
+ __Note:__ This table does not include Aqara (Smart Home Gateway) devices as their model identifier is set based on the type of the device.
87
+
88
+ Id | Type | Auto-token | Support | Note
89
+ --------------------------|-------------------|------------|--------------|------
90
+ `zhimi.airpurifier.m1` | Air Purifier | Yes | ✅ Good |
91
+ `zhimi.airpurifier.v1` | Air Purifier` | Yes | ✅ Good |
92
+ `zhimi.airpurifier.v2` | Air Purifier | Yes | ✅ Good |
93
+ `zhimi.airpurifier.v3` | Air Purifier | Unknown | ⚠️ Untested |
94
+ `zhimi.airpurifier.v4` | - | Unknown | ⚠️ Generic | Testing needed to check compatibility.
95
+ `zhimi.airpurifier.v5` | - | Unknown | ⚠️ Generic | Testing needed to check compatibility.
96
+ `zhimi.airpurifier.v6` | Air Purifier | Yes | ✅ Basic |
97
+ `zhimi.humidifier.v1` | Humidifier | Unknown | ⚠️ Untested |
98
+ `chuangmi.plug.m1` | Power plug | Yes | ✅ Good |
99
+ `chuangmi.plug.v1` | Power plug | Yes | ✅ Good |
100
+ `chuangmi.plug.v2` | Power plug | Yes | ✅ Good |
101
+ `qmi.powerstrip.v1` | Power strip | Yes | ⚠️ Untested |
102
+ `zimi.powerstrip.v2` | Power strip | Yes | ⚠️ Untested |
103
+ `rockrobo.vaccum.v1` | Vacuum | No | ✅ Basic | DND, timers and mapping features are not supported.
104
+ `rockrobo.vaccum.s5` | Vacuum | No | ✅ Basic | DND, timers and mapping features are not supported.
105
+ `lumi.gateway.v1` | Generic | Yes | ⚠️ Generic | API used to access sub devices not supported.
106
+ `lumi.gateway.v2` | Gateway | Yes | ✅ Basic |
107
+ `lumi.gateway.v3` | Gateway | Yes | ✅ Basic |
108
+ `yeelink.light.lamp1` | Light | No | ✅ Good |
109
+ `yeelink.light.mono1` | Light | No | ✅ Good |
110
+ `yeelink.light.color1` | Light | No | ✅ Good |
111
+ `yeelink.light.strip1` | Light | No | ⚠️ Untested | Support added, verification with real device needed.
@@ -0,0 +1,142 @@
1
+ # Air Purifier
2
+
3
+ * **Devices**: Mi Air Purifier 1 & 2, Pro
4
+ * **Model identifiers**: `zhimi.airpurifier.m1`, `zhimi.airpurifier.v1`, `zhimi.airpurifier.v2`, `zhimi.airpurifier.v3`, `zhimi.airpurifier.v6`
5
+
6
+ Air purifiers are turned into devices of type [air-purifier][air-purifier]
7
+ and by default support [power switching][switchable-power] and [setting their mode][switchable-mode]. The Mi Air
8
+ Purifiers are also [sensors][sensor] and can report the [PM2.5 (air quality index)][pm2.5],
9
+ [temperature][temp] and [relative humidity][humidity] where they are placed.
10
+
11
+ ## Examples
12
+
13
+ ### Check if device is an air purifier
14
+
15
+ ```javascript
16
+ if(device.matches('type:air-purifier')) {
17
+ /*
18
+ * This device is an air purifier.
19
+ */
20
+ }
21
+ ```
22
+
23
+ ### Check if powered on
24
+
25
+ ```javascript
26
+ // Get if the air purifier is on
27
+ device.power()
28
+ .then(isOn => console.log('Air purifier on:', isOn))
29
+ .catch(...);
30
+
31
+ // Using async/await
32
+ console.log('Air purifier on:', await device.power());
33
+ ```
34
+
35
+ ### Power on device
36
+
37
+ ```javascript
38
+ // Switch the air purifier on
39
+ device.setPower(true)
40
+ .then(...)
41
+ .catch(...)
42
+
43
+ // Switch on via async/await
44
+ await device.power(true);
45
+ ```
46
+
47
+ ### Read temperature
48
+
49
+ ```javascript
50
+ // Read the temperature
51
+ device.temperature()
52
+ .then(temp => console.log('Temperature:', temp.celsius))
53
+ .catch(...);
54
+
55
+ // Using async/await
56
+ const temp = await device.temperature();
57
+ console.log('Temperature:', temp.celsius);
58
+ ```
59
+
60
+ ### Read humidity
61
+
62
+ ```javascript
63
+ // Read the relative humidity
64
+ device.relativeHumidity()
65
+ .then(rh => console.log('Relative humidity:', rh))
66
+ .catch(...);
67
+
68
+ // Using async/await
69
+ const rh = await device.relativeHumidity();
70
+ console.log('Relative humidity:', rh);
71
+ ```
72
+
73
+ ## API
74
+
75
+ ### Power - [`cap:power`][power] and [`cap:switchable-power`][switchable-power]
76
+
77
+ * `device.power()` - get if the air purifier is currently active
78
+ * `device.power(boolean)` - switch the air purifier on, returns a promise
79
+ * `device.setPower(boolean)` - change the power state of the device, returns a promise
80
+ * `device.on(power, isOn => ...)` - listen for power changes
81
+
82
+ ### Mode - [`cap:mode`][mode] and [`cap:switchable-mode`][switchable-mode]
83
+
84
+ The air purifiers have different modes that controls their speed.
85
+
86
+ * `device.mode()` - get the current mode
87
+ * `device.mode(string)` - set the current mode of the device, returns a promise
88
+ * `device.setMode(string)` - set the current mode of the device, returns a promise
89
+ * `device.modes()` - read-only array indicating the modes supports by the device
90
+ * `device.on('modeChanged', mode => ...)` - listen for changes to the current mode
91
+
92
+ The modes supported change between different models, but most devices support:
93
+
94
+ * `idle`, turn the device off
95
+ * `auto`, set the device to automatic mode where it controls the speed itself
96
+ * `silent`, lowest speed, for silent operation or night time
97
+ * `favorite`, favorite level
98
+
99
+ ### Sensor - [`type:sensor`][sensor]
100
+
101
+ * `device.temperature()` - get the current temperature, see [`cap:temperature`][temp] for details
102
+ * `device.on('temperature', temp => ...)` - listen to changes to the read temperature
103
+ * `device.relativeHumidity()` - get the current relative humidity, see [`cap:relative-humidity`][humidity] for details
104
+ * `device.on('relativeHumidityChanged', rh => ...)` - listen to changes to the relative humidity
105
+ * `device.pm2_5` - get the current PM2.5 (Air Quality Index), see [`cap:pm2.5`][pm2.5] for details
106
+ * `device.on('pm2.5Changed', pm2_5 => ...)` - listen to changes to the PM2.5 value
107
+
108
+ ### Buzzer settings - `cap:miio:buzzer`
109
+
110
+ * `device.buzzer()` - boolean indicating if the buzzer (beep) is active
111
+ * `device.buzzer(boolean)` - switch the buzzer on or off
112
+ * `device.setBuzzer(boolean)` - switch the buzzer on or off
113
+
114
+ ### LED settings - `cap:miio:switchable-led`
115
+
116
+ Turn the LED indicator on the device on or off.
117
+
118
+ * `device.led()` - if the LED is on or off
119
+ * `device.led(boolean)` - switch the LED on or off
120
+
121
+ ### LED brightness - `cap:miio:led-brightness`
122
+
123
+ Change the brightness of the LED on the device.
124
+
125
+ * `device.ledBrightness()` - the LED brightness, `bright`, `dim` or `off`
126
+ * `device.ledBrightness(string)` - set the brightness of the LED
127
+
128
+ ### Other
129
+
130
+ * `device.favoriteLevel()` - get the speed the device should run at when mode is `favorite`. Between 0 and 16.
131
+ * `device.favoriteLevel(level)` - set the speed the device should run at when mode is `favorite`. Between 0 and 16.
132
+ * `device.setFavoriteLevel(number)` - set the speed for mode `favorite`
133
+
134
+ [air-purifier]: http://abstract-things.readthedocs.io/en/latest/climate/air-purifiers.html
135
+ [sensor]: http://abstract-things.readthedocs.io/en/latest/sensors/index.html
136
+ [power]: http://abstract-things.readthedocs.io/en/latest/common/power.html
137
+ [switchable-power]: http://abstract-things.readthedocs.io/en/latest/common/switchable-power.html
138
+ [mode]: http://abstract-things.readthedocs.io/en/latest/common/mode.html
139
+ [switchable-mode]: http://abstract-things.readthedocs.io/en/latest/common/switchable-mode.html
140
+ [pm2.5]: http://abstract-things.readthedocs.io/en/latest/sensors/pm2.5.html
141
+ [temp]: http://abstract-things.readthedocs.io/en/latest/sensors/temperature.html
142
+ [humidity]: http://abstract-things.readthedocs.io/en/latest/sensors/relative-humidity.html
@@ -0,0 +1,89 @@
1
+ # Controllers
2
+
3
+ * **Devices**: Aqara Switch (round and square), Aqara Light Switch, Aqara Dual Light Switch
4
+ * **Model identifiers**: `lumi.switch`, `lumi.switch.aq2`, `lumi.86sw1`, `lumi.86sw2`
5
+
6
+ Controllers are devices whose primary function is to control something else.
7
+ These devices will have the capability [`actions`][actions] and their primary
8
+ function will be emitting events. Single button switches will be of the type
9
+ [`button`][button] and other switches are translated into the type
10
+ [`wall-controller`][wall-controller]. Controllers may also have the capability
11
+ [`battery-level`][battery-level] if they can report their battery level.
12
+
13
+ ## Examples
14
+
15
+ ### Check if device supports actions
16
+
17
+ ```javascript
18
+ if(device.matches('cap:actions')) {
19
+ /*
20
+ * This device is a controller of some sort.
21
+ */
22
+ }
23
+ ```
24
+
25
+ ### Listen for actions
26
+
27
+ ```javascript
28
+ device.on('action', event => console.log('Action', event.action, 'with data', event.data));
29
+
30
+ device.on('action:idOfAction', data => ...);
31
+ ```
32
+
33
+ ### List available actions
34
+
35
+ ```javascript
36
+ // Get the available actions
37
+ device.actions()
38
+ .then(actions => ...)
39
+ .catch(...);
40
+
41
+ // Using async/await
42
+ const actions = await device.actions();
43
+ ```
44
+
45
+ ## API
46
+
47
+ ### Actions - [`cap:actions`][actions]
48
+
49
+ * `device.actions()` - get all of the available actions
50
+ * `device.on('action', event => ...)` - listen for all actions
51
+ * `device.on('action:<id>', data => ...)` - listen for action with name `<id>`
52
+
53
+ ## Models
54
+
55
+ ### Aqara Button V1 - `lumi.switch`
56
+
57
+ Round button connected to a Mi Gateway. Supports the actions `click`,
58
+ `double_click`, `long_click_press` and `long_click_release`.
59
+
60
+ ### Aqara Button V2 - `lumi.switch.v2`
61
+
62
+ Square button connected to a Mi Gateway. Supports the actions `click`
63
+ and `double_click`.
64
+
65
+ ### Aqara Cube - `lumi.cube`
66
+
67
+ Cube connected to a Mi Gateway. Supports the actions `alert`, `flip90`,
68
+ `flip180`, `move`, `tap_twice`, `shake_air`, `free_fall` and `rotate`.
69
+
70
+ When the action is `rotate` the data in the event will be an object including
71
+ the key `amount`. Example use:
72
+
73
+ ```javascript
74
+ device.on('action:rotate', data => console.log('Rotation amount:', data.amount));
75
+ ```
76
+
77
+ ### Aqara Wall Switch, one button - `lumi.86sw1`
78
+
79
+ Wall Switch with one button. Supports the actions: `click` and `double_click`
80
+
81
+ ### Aqara Wall Switch, two buttons - `lumi.86sw2`
82
+
83
+ Wall Switch with two buttons. Suppors the actions `btn0-click`,
84
+ `btn0-double_click`, `btn1-click`, `btn1-double_click` and `both_click`.
85
+
86
+ [actions]: http://abstract-things.readthedocs.io/en/latest/controllers/actions.html
87
+ [button]: http://abstract-things.readthedocs.io/en/latest/controllers/buttons.html
88
+ [wall-controller]: http://abstract-things.readthedocs.io/en/latest/controllers/wall-controllers.html
89
+ [battery-level]: http://abstract-things.readthedocs.io/en/latest/common/battery-level.html
@@ -0,0 +1,41 @@
1
+ # Gateways
2
+
3
+ * **Devices**: Mi Smart Home Gateway 2 and 3
4
+ * **Model identifiers**: `lumi.gateway.v2`, `lumi.gateway.v3`
5
+
6
+ Support for the Mi Smart Home Gateway that provides access to a set of smaller
7
+ devices such as switches, motion detection and temperature and humidity sensors.
8
+
9
+ **Note** To fully support the gateway this library will automatically enable
10
+ the Local Developer API of the gateway. If it is already enabled the existing
11
+ key is used but if not a new key is generated and set for the API.
12
+
13
+ ## Examples
14
+
15
+ ### Check if the device is a gateway
16
+
17
+ ```javascript
18
+ if(device.matches('type:miio:gateway')) {
19
+ /*
20
+ * This device is a Mi Gateway.
21
+ */
22
+ }
23
+ ```
24
+
25
+ ### Get child devices
26
+
27
+ ```javascript
28
+ const children = device.children();
29
+ for(const child of children) {
30
+ // Do something with each child
31
+ }
32
+ ```
33
+
34
+ ## API
35
+
36
+ ### Children - [`cap:children`][children]
37
+
38
+ * `device.children()` - get the children of the gateway. Returns an iterable without going via a promise.
39
+ * `device.child(id)` - get a child via its identifier
40
+
41
+ [children]: http://abstract-things.readthedocs.io/en/latest/common/children.html