diff --git a/README.md b/README.md index 38f38d1..39ed41c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # miIO Device Library -This is a small library for controlling Mi Home devices that implement the miIO -protocol, such as the Mi Air Purifier, Mi Robot Vacuum and Mi Smart Socket. +Control Mi Home devices that implement the miIO protocol, such as the +Mi Air Purifier, Mi Robot Vacuum and Mi Smart Socket. This library requires at least Node 6.0.0. @@ -65,6 +65,20 @@ device.on('propertyChanged', e => console.log(e.property, e.oldValue, e.value)); device.on('action', e => console.log('Action performed:', e.id)); ``` +Use capabilities if you want to support different models easily: + +```javascript +if(device.hasCapability('temperature')) { + console.log(device.temperature); +} + +if(device.hasCapability('power')) { + device.setPower(false) + .then(console.log) + .catch(console.error); +} +``` + If you are done with the device call `destroy` to stop all network traffic: ```javascript diff --git a/docs/devices/README.md b/docs/devices/README.md index 9e86f61..5ed5b67 100644 --- a/docs/devices/README.md +++ b/docs/devices/README.md @@ -35,11 +35,11 @@ column can be one of the following: * Good - most of the functionality is available including some more advanced features such as settings * Excellent - as close to complete support as possible -If your device is: +If your device: -* Not in this list, it might still be a miIO-device and at least have generic support. See the next section for details about how to find out if that is the case. +* Is not in this list, it might still be a miIO-device and at least have generic support. See the next section for details about how to find out if that is the case. * 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. -* Marked as Untested you can help by testing the implementation is this library and opening an issue with information about the result +* Is marked as Untested you can help by testing the implementation is this library and opening an issue with information about the result. Name | Type | Auto-token | Support | Note ------------------------------|---------------------------------|------------|-----------|-------- diff --git a/docs/devices/gateway.md b/docs/devices/gateway.md index a147aa4..a24fe6f 100644 --- a/docs/devices/gateway.md +++ b/docs/devices/gateway.md @@ -25,3 +25,17 @@ Emitted when a device is no longer available for access via the gateway. ### `device.devices: Array[SubDevice]` List the current devices that are available. + +### `device.addDevice()` + +Tell the gateway that a new device should be added. The actual Aqara device +needs to be reset, which is a different procedure for each device. The device +has 30 seconds to join the gateway. + +### `device.stopAddDevice()` + +Tell the gateway that you no longer want to add a new device. + +### `device.removeDevice(id)` + +Remove a device from the gateway using its identifier. diff --git a/example.js b/example.js index de1a2a6..e8dc55d 100644 --- a/example.js +++ b/example.js @@ -6,6 +6,8 @@ const miio = require('./lib'); miio.device({ address: '192.168.100.8' }).then(device => { - console.log('power is now', device.power); - return device.setPower(! device.power); + if(device.hasCapability('power')) { + console.log('power is now', device.power); + return device.setPower(! device.power); + } }).catch(console.error); diff --git a/package.json b/package.json index ad56009..9d51010 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,14 @@ "name": "miio", "version": "0.6.0", "license": "MIT", - "description": "Control Mi Home devices implementing the miIO protocol, such as Mi Robot Vacuums, Mi Air Purifiers and more", + "description": "Control Mi Home devices, such as Mi Robot Vacuums, Mi Air Purifiers, Mi Smart Home Gateway (Aqara) and more", "repository": "aholstenson/miio", "main": "lib/index.js", "keywords": [ "xiaomi", "mi", - "miio" + "miio", + "aqara" ], "main": "lib/index.js", "bin": {