node-miio 0.3.0-beta.2 → 0.3.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.
- package/AGENTS.md +117 -0
- package/README.md +41 -2
- package/dist/cli/commands/configure.js +60 -0
- package/dist/cli/commands/configure.js.map +1 -0
- package/dist/cli/commands/control.js +47 -0
- package/dist/cli/commands/control.js.map +1 -0
- package/dist/cli/commands/discover.js +32 -0
- package/dist/cli/commands/discover.js.map +1 -0
- package/dist/cli/commands/inspect.js +183 -0
- package/dist/cli/commands/inspect.js.map +1 -0
- package/dist/cli/commands/miot-spec.js +60 -0
- package/dist/cli/commands/miot-spec.js.map +1 -0
- package/dist/cli/commands/protocol/call.js +59 -0
- package/dist/cli/commands/protocol/call.js.map +1 -0
- package/dist/cli/commands/protocol/json-dump.js +56 -0
- package/dist/cli/commands/protocol/json-dump.js.map +1 -0
- package/dist/cli/commands/protocol/packet.js +30 -0
- package/dist/cli/commands/protocol/packet.js.map +1 -0
- package/dist/cli/commands/protocol.js +49 -0
- package/dist/cli/commands/protocol.js.map +1 -0
- package/dist/cli/commands/tokens/update.js +53 -0
- package/dist/cli/commands/tokens/update.js.map +1 -0
- package/dist/cli/commands/tokens.js +44 -0
- package/dist/cli/commands/tokens.js.map +1 -0
- package/dist/cli/device-finder.js +72 -0
- package/dist/cli/device-finder.js.map +1 -0
- package/dist/cli/index.js +64 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/log.js +69 -0
- package/dist/cli/log.js.map +1 -0
- package/dist/lib/check_result.js +18 -0
- package/dist/lib/check_result.js.map +1 -0
- package/dist/lib/connect_to_device.js +123 -0
- package/dist/lib/connect_to_device.js.map +1 -0
- package/dist/lib/device.js +259 -0
- package/dist/lib/device.js.map +1 -0
- package/dist/lib/device_info.js +297 -0
- package/dist/lib/device_info.js.map +1 -0
- package/dist/lib/devices/air-monitor.js +42 -0
- package/dist/lib/devices/air-monitor.js.map +1 -0
- package/dist/lib/devices/air-purifier.js +144 -0
- package/dist/lib/devices/air-purifier.js.map +1 -0
- package/dist/lib/devices/capabilities/battery-level.js +13 -0
- package/dist/lib/devices/capabilities/battery-level.js.map +1 -0
- package/dist/lib/devices/capabilities/buzzer.js +69 -0
- package/dist/lib/devices/capabilities/buzzer.js.map +1 -0
- package/dist/lib/devices/capabilities/changeable-led-brightness.js +44 -0
- package/dist/lib/devices/capabilities/changeable-led-brightness.js.map +1 -0
- package/dist/lib/devices/capabilities/colorable.js +14 -0
- package/dist/lib/devices/capabilities/colorable.js.map +1 -0
- package/dist/lib/devices/capabilities/dimmable.js +14 -0
- package/dist/lib/devices/capabilities/dimmable.js.map +1 -0
- package/dist/lib/devices/capabilities/mode.js +13 -0
- package/dist/lib/devices/capabilities/mode.js.map +1 -0
- package/dist/lib/devices/capabilities/power.js +13 -0
- package/dist/lib/devices/capabilities/power.js.map +1 -0
- package/dist/lib/devices/capabilities/sensor.js +46 -0
- package/dist/lib/devices/capabilities/sensor.js.map +1 -0
- package/dist/lib/devices/capabilities/switchable-led.js +48 -0
- package/dist/lib/devices/capabilities/switchable-led.js.map +1 -0
- package/dist/lib/devices/chuangmi.plug.v1.js +47 -0
- package/dist/lib/devices/chuangmi.plug.v1.js.map +1 -0
- package/dist/lib/devices/eyecare-lamp2.js +151 -0
- package/dist/lib/devices/eyecare-lamp2.js.map +1 -0
- package/dist/lib/devices/gateway/86sw1.js +20 -0
- package/dist/lib/devices/gateway/86sw1.js.map +1 -0
- package/dist/lib/devices/gateway/86sw2.js +36 -0
- package/dist/lib/devices/gateway/86sw2.js.map +1 -0
- package/dist/lib/devices/gateway/ctrl_ln1.js +37 -0
- package/dist/lib/devices/gateway/ctrl_ln1.js.map +1 -0
- package/dist/lib/devices/gateway/ctrl_ln2.js +45 -0
- package/dist/lib/devices/gateway/ctrl_ln2.js.map +1 -0
- package/dist/lib/devices/gateway/ctrl_neutral1.js +37 -0
- package/dist/lib/devices/gateway/ctrl_neutral1.js.map +1 -0
- package/dist/lib/devices/gateway/ctrl_neutral2.js +45 -0
- package/dist/lib/devices/gateway/ctrl_neutral2.js.map +1 -0
- package/dist/lib/devices/gateway/cube.js +49 -0
- package/dist/lib/devices/gateway/cube.js.map +1 -0
- package/dist/lib/devices/gateway/developer-api.js +104 -0
- package/dist/lib/devices/gateway/developer-api.js.map +1 -0
- package/dist/lib/devices/gateway/light-channel.js +24 -0
- package/dist/lib/devices/gateway/light-channel.js.map +1 -0
- package/dist/lib/devices/gateway/light-mixin.js +59 -0
- package/dist/lib/devices/gateway/light-mixin.js.map +1 -0
- package/dist/lib/devices/gateway/magnet.js +23 -0
- package/dist/lib/devices/gateway/magnet.js.map +1 -0
- package/dist/lib/devices/gateway/magnet2.js +9 -0
- package/dist/lib/devices/gateway/magnet2.js.map +1 -0
- package/dist/lib/devices/gateway/motion.js +21 -0
- package/dist/lib/devices/gateway/motion.js.map +1 -0
- package/dist/lib/devices/gateway/motion2.js +25 -0
- package/dist/lib/devices/gateway/motion2.js.map +1 -0
- package/dist/lib/devices/gateway/plug.js +34 -0
- package/dist/lib/devices/gateway/plug.js.map +1 -0
- package/dist/lib/devices/gateway/sensor_ht.js +13 -0
- package/dist/lib/devices/gateway/sensor_ht.js.map +1 -0
- package/dist/lib/devices/gateway/subdevice.js +203 -0
- package/dist/lib/devices/gateway/subdevice.js.map +1 -0
- package/dist/lib/devices/gateway/subdevices.js +33 -0
- package/dist/lib/devices/gateway/subdevices.js.map +1 -0
- package/dist/lib/devices/gateway/switch.js +24 -0
- package/dist/lib/devices/gateway/switch.js.map +1 -0
- package/dist/lib/devices/gateway/switch2.js +19 -0
- package/dist/lib/devices/gateway/switch2.js.map +1 -0
- package/dist/lib/devices/gateway/voltage.js +21 -0
- package/dist/lib/devices/gateway/voltage.js.map +1 -0
- package/dist/lib/devices/gateway/weather.js +16 -0
- package/dist/lib/devices/gateway/weather.js.map +1 -0
- package/dist/lib/devices/gateway.js +212 -0
- package/dist/lib/devices/gateway.js.map +1 -0
- package/dist/lib/devices/humidifier.js +141 -0
- package/dist/lib/devices/humidifier.js.map +1 -0
- package/dist/lib/devices/philips-light-bulb.js +63 -0
- package/dist/lib/devices/philips-light-bulb.js.map +1 -0
- package/dist/lib/devices/power-plug.js +22 -0
- package/dist/lib/devices/power-plug.js.map +1 -0
- package/dist/lib/devices/power-strip.js +27 -0
- package/dist/lib/devices/power-strip.js.map +1 -0
- package/dist/lib/devices/vacuums/dreamevacuum.js +312 -0
- package/dist/lib/devices/vacuums/dreamevacuum.js.map +1 -0
- package/dist/lib/devices/vacuums/mijiavacuum.js +21 -0
- package/dist/lib/devices/vacuums/mijiavacuum.js.map +1 -0
- package/dist/lib/devices/vacuums/miot-vacuum.js +444 -0
- package/dist/lib/devices/vacuums/miot-vacuum.js.map +1 -0
- package/dist/lib/devices/vacuums/vacuum.js +669 -0
- package/dist/lib/devices/vacuums/vacuum.js.map +1 -0
- package/dist/lib/devices/vacuums/vacuum_modes.js +171 -0
- package/dist/lib/devices/vacuums/vacuum_modes.js.map +1 -0
- package/dist/lib/devices/vacuums/viomivacuum.js +222 -0
- package/dist/lib/devices/vacuums/viomivacuum.js.map +1 -0
- package/dist/lib/devices/yeelight.color.js +5 -0
- package/dist/lib/devices/yeelight.color.js.map +1 -0
- package/dist/lib/devices/yeelight.js +242 -0
- package/dist/lib/devices/yeelight.js.map +1 -0
- package/dist/lib/devices/yeelight.mono.js +5 -0
- package/dist/lib/devices/yeelight.mono.js.map +1 -0
- package/dist/lib/discovery.js +147 -0
- package/dist/lib/discovery.js.map +1 -0
- package/dist/lib/index.js +89 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/info_from_hostname.js +27 -0
- package/dist/lib/info_from_hostname.js.map +1 -0
- package/dist/lib/management.js +101 -0
- package/dist/lib/management.js.map +1 -0
- package/dist/lib/miio_error.js +23 -0
- package/dist/lib/miio_error.js.map +1 -0
- package/dist/lib/miot/miot_api.js +73 -0
- package/dist/lib/miot/miot_api.js.map +1 -0
- package/dist/lib/miot/miot_spec.js +105 -0
- package/dist/lib/miot/miot_spec.js.map +1 -0
- package/dist/lib/miot/spec_client.js +290 -0
- package/dist/lib/miot/spec_client.js.map +1 -0
- package/dist/lib/models.js +69 -0
- package/dist/lib/models.js.map +1 -0
- package/dist/lib/network.js +194 -0
- package/dist/lib/network.js.map +1 -0
- package/dist/lib/packet.js +177 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/placeholder.js +16 -0
- package/dist/lib/placeholder.js.map +1 -0
- package/dist/lib/protocol.js +3 -0
- package/dist/lib/protocol.js.map +1 -0
- package/dist/lib/safeish_json.js +22 -0
- package/dist/lib/safeish_json.js.map +1 -0
- package/dist/lib/tokens.js +30 -0
- package/dist/lib/tokens.js.map +1 -0
- package/docs/devices/vacuum.md +63 -3
- package/example.js +1 -1
- package/package.json +49 -16
- package/snapshots/vacuum-specs.json.gz +0 -0
- package/.editorconfig +0 -26
- package/.eslintrc +0 -32
- package/.github/release.yml +0 -20
- package/.github/workflows/build.yml +0 -50
- package/.github/workflows/codecov.yml +0 -35
- package/.github/workflows/codeql.yml +0 -24
- package/.github/workflows/publish-dev-from-main.yml +0 -92
- package/.github/workflows/publish-release-to-npm.yml +0 -45
- package/cli/commands/configure.js +0 -69
- package/cli/commands/control.js +0 -54
- package/cli/commands/discover.js +0 -36
- package/cli/commands/inspect.js +0 -197
- package/cli/commands/protocol/call.js +0 -66
- package/cli/commands/protocol/json-dump.js +0 -52
- package/cli/commands/protocol/packet.js +0 -29
- package/cli/commands/protocol.js +0 -8
- package/cli/commands/tokens/update.js +0 -58
- package/cli/commands/tokens.js +0 -8
- package/cli/device-finder.js +0 -69
- package/cli/index.js +0 -9
- package/cli/log.js +0 -89
- package/lib/checkResult.js +0 -13
- package/lib/connectToDevice.js +0 -66
- package/lib/device.js +0 -290
- package/lib/device_info.js +0 -329
- package/lib/device_info.test.js +0 -337
- package/lib/devices/air-monitor.js +0 -53
- package/lib/devices/air-purifier.js +0 -162
- package/lib/devices/capabilities/battery-level.js +0 -16
- package/lib/devices/capabilities/buzzer.js +0 -78
- package/lib/devices/capabilities/changeable-led-brightness.js +0 -48
- package/lib/devices/capabilities/colorable.js +0 -14
- package/lib/devices/capabilities/dimmable.js +0 -14
- package/lib/devices/capabilities/mode.js +0 -13
- package/lib/devices/capabilities/power.js +0 -14
- package/lib/devices/capabilities/sensor.js +0 -50
- package/lib/devices/capabilities/switchable-led.js +0 -49
- package/lib/devices/chuangmi.plug.v1.js +0 -61
- package/lib/devices/eyecare-lamp2.js +0 -179
- package/lib/devices/gateway/86sw1.js +0 -28
- package/lib/devices/gateway/86sw2.js +0 -44
- package/lib/devices/gateway/ctrl_ln1.js +0 -44
- package/lib/devices/gateway/ctrl_ln2.js +0 -53
- package/lib/devices/gateway/ctrl_neutral1.js +0 -44
- package/lib/devices/gateway/ctrl_neutral2.js +0 -53
- package/lib/devices/gateway/cube.js +0 -55
- package/lib/devices/gateway/developer-api.js +0 -120
- package/lib/devices/gateway/light-channel.js +0 -32
- package/lib/devices/gateway/light-mixin.js +0 -71
- package/lib/devices/gateway/magnet.js +0 -29
- package/lib/devices/gateway/magnet2.js +0 -13
- package/lib/devices/gateway/motion.js +0 -27
- package/lib/devices/gateway/motion2.js +0 -31
- package/lib/devices/gateway/plug.js +0 -45
- package/lib/devices/gateway/sensor_ht.js +0 -17
- package/lib/devices/gateway/subdevice.js +0 -227
- package/lib/devices/gateway/subdevices.js +0 -37
- package/lib/devices/gateway/switch.js +0 -29
- package/lib/devices/gateway/switch2.js +0 -27
- package/lib/devices/gateway/voltage.js +0 -28
- package/lib/devices/gateway/weather.js +0 -22
- package/lib/devices/gateway.js +0 -244
- package/lib/devices/humidifier.js +0 -162
- package/lib/devices/philips-light-bulb.js +0 -73
- package/lib/devices/power-plug.js +0 -26
- package/lib/devices/power-strip.js +0 -38
- package/lib/devices/vacuums/dreamevacuum.js +0 -350
- package/lib/devices/vacuums/mijiavacuum.js +0 -22
- package/lib/devices/vacuums/vacuum.js +0 -518
- package/lib/devices/vacuums/viomivacuum.js +0 -250
- package/lib/devices/yeelight.color.js +0 -6
- package/lib/devices/yeelight.js +0 -286
- package/lib/devices/yeelight.mono.js +0 -9
- package/lib/discovery.js +0 -192
- package/lib/index.js +0 -40
- package/lib/infoFromHostname.js +0 -24
- package/lib/management.js +0 -102
- package/lib/models.js +0 -76
- package/lib/network.js +0 -234
- package/lib/packet.js +0 -191
- package/lib/placeholder.js +0 -12
- package/lib/safeishJSON.js +0 -14
- package/lib/tokens.js +0 -129
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
// Switch (button) controller
|
|
5
|
-
1: require('./switch'),
|
|
6
|
-
// Motion sensor
|
|
7
|
-
2: require('./motion'),
|
|
8
|
-
// Magnet sensor for doors and windows
|
|
9
|
-
3: require('./magnet'),
|
|
10
|
-
|
|
11
|
-
// TODO: What is 4, 5 and 6? plug, 86sw1 and 86sw2 are left
|
|
12
|
-
|
|
13
|
-
// Light switch with two channels
|
|
14
|
-
7: require('./ctrl_neutral2'),
|
|
15
|
-
// Cube controller
|
|
16
|
-
8: require('./cube'),
|
|
17
|
-
// Light switch with one channel
|
|
18
|
-
9: require('./ctrl_neutral1'),
|
|
19
|
-
// Temperature and Humidity sensor
|
|
20
|
-
10: require('./sensor_ht'),
|
|
21
|
-
// Plug
|
|
22
|
-
11: require('./plug'),
|
|
23
|
-
|
|
24
|
-
// Aqara Temperature/Humidity/Pressure sensor
|
|
25
|
-
19: require('./weather'),
|
|
26
|
-
// Light switch (live+neutral wire version) with one channel
|
|
27
|
-
20: require('./ctrl_ln1'),
|
|
28
|
-
// Light switch (live+neutral wire version) with two channels
|
|
29
|
-
21: require('./ctrl_ln2'),
|
|
30
|
-
|
|
31
|
-
// AQ2 switch (square version)
|
|
32
|
-
51: require('./switch2'),
|
|
33
|
-
// AQ2 motion sensor
|
|
34
|
-
52: require('./motion2'),
|
|
35
|
-
// AQ2 manget sensor
|
|
36
|
-
53: require('./magnet2')
|
|
37
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const SubDevice = require('./subdevice');
|
|
4
|
-
const { Button, Actions } = require('abstract-things/controllers');
|
|
5
|
-
const Voltage = require('./voltage');
|
|
6
|
-
|
|
7
|
-
module.exports = class Switch extends SubDevice.with(Button, Actions, Voltage) {
|
|
8
|
-
constructor(parent, info) {
|
|
9
|
-
super(parent, info);
|
|
10
|
-
|
|
11
|
-
this.miioModel = 'lumi.switch';
|
|
12
|
-
|
|
13
|
-
this.updateActions([
|
|
14
|
-
'click',
|
|
15
|
-
'double_click',
|
|
16
|
-
'long_click_press',
|
|
17
|
-
'long_click_release'
|
|
18
|
-
]);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_report(data) {
|
|
22
|
-
super._report(data);
|
|
23
|
-
|
|
24
|
-
if(typeof data.status !== 'undefined') {
|
|
25
|
-
this.debug('Action performed:', data.status);
|
|
26
|
-
this.emitAction(data.status);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const SubDevice = require('./subdevice');
|
|
4
|
-
const { Button, Actions } = require('abstract-things/controllers');
|
|
5
|
-
const Voltage = require('./voltage');
|
|
6
|
-
|
|
7
|
-
module.exports = class Switch extends SubDevice.with(Button, Actions, Voltage) {
|
|
8
|
-
constructor(parent, info) {
|
|
9
|
-
super(parent, info);
|
|
10
|
-
|
|
11
|
-
this.miioModel = 'lumi.switch.v2';
|
|
12
|
-
|
|
13
|
-
this.updateActions([
|
|
14
|
-
'click',
|
|
15
|
-
'double_click'
|
|
16
|
-
]);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
_report(data) {
|
|
20
|
-
super._report(data);
|
|
21
|
-
|
|
22
|
-
if(typeof data.status !== 'undefined') {
|
|
23
|
-
this.debug('Action performed:', data.status);
|
|
24
|
-
this.emitAction(data.status);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { Thing, BatteryLevel } = require('abstract-things');
|
|
4
|
-
|
|
5
|
-
const VOLTAGE_MIN = 2800;
|
|
6
|
-
const VOLTAGE_MAX = 3300;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Mixin for subdevices that support reporting voltage and that can be
|
|
10
|
-
* transformed into a battery level.
|
|
11
|
-
*/
|
|
12
|
-
module.exports = Thing.mixin(Parent => class extends Parent.with(BatteryLevel) {
|
|
13
|
-
|
|
14
|
-
constructor(...args) {
|
|
15
|
-
super(...args);
|
|
16
|
-
|
|
17
|
-
this.defineProperty('voltage');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
propertyUpdated(key, value, oldValue) {
|
|
21
|
-
if(key === 'voltage' && value) {
|
|
22
|
-
this.updateBatteryLevel(Number((value - VOLTAGE_MIN) / (VOLTAGE_MAX - VOLTAGE_MIN) * 100).toFixed(2));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
super.propertyUpdated(key, value, oldValue);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
});
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const SubDevice = require('./subdevice');
|
|
5
|
-
const { Temperature, Humidity, AtmosphericPressure } = require('../capabilities/sensor');
|
|
6
|
-
const Voltage = require('./voltage');
|
|
7
|
-
|
|
8
|
-
module.exports = class WeatherSensor extends SubDevice
|
|
9
|
-
.with(Temperature, Humidity, AtmosphericPressure, Voltage)
|
|
10
|
-
{
|
|
11
|
-
constructor(parent, info) {
|
|
12
|
-
super(parent, info);
|
|
13
|
-
|
|
14
|
-
this.miioModel = 'lumi.weather';
|
|
15
|
-
|
|
16
|
-
this.defineProperty('temperature', v => v / 100.0);
|
|
17
|
-
this.defineProperty('humidity', v => v / 100.0);
|
|
18
|
-
this.defineProperty('pressure', {
|
|
19
|
-
name: 'atmosphericPressure'
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
};
|
package/lib/devices/gateway.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { Thing, Children } = require('abstract-things');
|
|
4
|
-
const { ChildSyncer } = require('abstract-things/children');
|
|
5
|
-
|
|
6
|
-
const MiioApi = require('../device');
|
|
7
|
-
const { Illuminance } = require('./capabilities/sensor');
|
|
8
|
-
|
|
9
|
-
const DeveloperApi = require('./gateway/developer-api');
|
|
10
|
-
const CHARS = '0123456789abcdefghijklmnopqrstuvwxyz';
|
|
11
|
-
|
|
12
|
-
const LightMixin = require('./gateway/light-mixin');
|
|
13
|
-
const SubDevice = require('./gateway/subdevice');
|
|
14
|
-
const types = require('./gateway/subdevices');
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Generate a key for use with the local developer API. This does not generate
|
|
18
|
-
* a secure key, but the Mi Home app does not seem to do that either.
|
|
19
|
-
*/
|
|
20
|
-
function generateKey() {
|
|
21
|
-
let result = '';
|
|
22
|
-
for(let i=0; i<16; i++) {
|
|
23
|
-
let idx = Math.floor(Math.random() * CHARS.length);
|
|
24
|
-
result += CHARS[idx];
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Abstraction over a Mi Smart Home Gateway.
|
|
31
|
-
*
|
|
32
|
-
* This device is very different from most other miIO-devices in that it has
|
|
33
|
-
* devices on its own. There seems to be a way to talk to these devices by
|
|
34
|
-
* setting `sid` in the requests, which means we can poll them. The problem
|
|
35
|
-
* is that certain devices also send events, but these seem to only be
|
|
36
|
-
* accessible over a local developer connection.
|
|
37
|
-
*
|
|
38
|
-
* So to work around this we activate the local developer connection and use
|
|
39
|
-
* that together with the regular calls for changing things on the gateway.
|
|
40
|
-
*/
|
|
41
|
-
const Gateway = Thing.type(Parent => class Gateway extends Parent.with(MiioApi, Children) {
|
|
42
|
-
static get type() {
|
|
43
|
-
return 'miio:gateway';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static get SubDevice() { return SubDevice; }
|
|
47
|
-
|
|
48
|
-
static registerSubDevice(id, deviceClass) {
|
|
49
|
-
types[id] = deviceClass;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static availableAPI(builder) {
|
|
53
|
-
builder.action('addDevice')
|
|
54
|
-
.done();
|
|
55
|
-
|
|
56
|
-
builder.action('stopAddDevice')
|
|
57
|
-
.done();
|
|
58
|
-
|
|
59
|
-
builder.action('removeDevice')
|
|
60
|
-
.done();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
constructor(options) {
|
|
64
|
-
super(options);
|
|
65
|
-
|
|
66
|
-
this.defineProperty('illumination', {
|
|
67
|
-
name: 'illuminance'
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
this.defineProperty('rgb', {
|
|
71
|
-
handler: (result, rgba) => {
|
|
72
|
-
result['rgb'] = {
|
|
73
|
-
red: 0xff & (rgba >> 16),
|
|
74
|
-
green: 0xff & (rgba >> 8),
|
|
75
|
-
blue: 0xff & rgba
|
|
76
|
-
};
|
|
77
|
-
result['brightness'] = Math.round(0xff & (rgba >> 24));
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
this.extraChildren = [];
|
|
82
|
-
|
|
83
|
-
// Monitor every minute right now
|
|
84
|
-
this._monitorInterval = 60 * 1000;
|
|
85
|
-
|
|
86
|
-
this.syncer = new ChildSyncer(this, (def, current) => {
|
|
87
|
-
// Shortcut to detect extra child
|
|
88
|
-
if(def.metadata && def.id) return def;
|
|
89
|
-
|
|
90
|
-
if(! def.online) return;
|
|
91
|
-
if(current) return current;
|
|
92
|
-
|
|
93
|
-
const type = types[def.type] || SubDevice;
|
|
94
|
-
const device = new type(this, {
|
|
95
|
-
id: def.id,
|
|
96
|
-
model: 'lumi.generic.' + def.type
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
return device;
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
_report(properties) {
|
|
104
|
-
Object.keys(properties).forEach(key => {
|
|
105
|
-
this.setRawProperty(key, properties[key]);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
initCallback() {
|
|
110
|
-
return super.initCallback()
|
|
111
|
-
.then(() => this._findDeveloperKey())
|
|
112
|
-
.then(() => this._updateDeviceList())
|
|
113
|
-
.then(() => {
|
|
114
|
-
// Update devices once every half an hour
|
|
115
|
-
this._deviceListTimer = setInterval(this._updateDeviceList.bind(this), 30 * 60 * 1000);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
destroyCallback() {
|
|
120
|
-
return super.destroyCallback()
|
|
121
|
-
.then(() => {
|
|
122
|
-
|
|
123
|
-
if(this.devApi) {
|
|
124
|
-
this.devApi.destroy();
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
clearInterval(this._deviceListTimer);
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
addExtraChild(child) {
|
|
132
|
-
this.extraChildren.push(child);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
_updateDeviceList() {
|
|
136
|
-
function stripLumiFromId(id) {
|
|
137
|
-
if(id.indexOf('lumi.') === 0) {
|
|
138
|
-
return id.substring(5);
|
|
139
|
-
}
|
|
140
|
-
return id;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return this.call('get_device_prop', [ 'lumi.0', 'device_list' ])
|
|
144
|
-
.then(list => {
|
|
145
|
-
const defs = [ ...this.extraChildren ];
|
|
146
|
-
for(let i=0; i<list.length; i+=5) {
|
|
147
|
-
const id = stripLumiFromId(list[i]);
|
|
148
|
-
const type = list[i+1];
|
|
149
|
-
const online = list[i+2] === 1;
|
|
150
|
-
|
|
151
|
-
// Sanity check, skip gateway if found
|
|
152
|
-
if(id === '0') continue;
|
|
153
|
-
|
|
154
|
-
defs.push({
|
|
155
|
-
id: 'miio:' + id,
|
|
156
|
-
type: type,
|
|
157
|
-
online: online
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return this.syncer.update(defs);
|
|
162
|
-
});
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Either resolve the developer key or setup a new one.
|
|
167
|
-
*/
|
|
168
|
-
_findDeveloperKey() {
|
|
169
|
-
// We already have a developer key
|
|
170
|
-
if(this._developerKey) return Promise.resolve(this._developerKey);
|
|
171
|
-
|
|
172
|
-
// Call and fetch the key or set a new key
|
|
173
|
-
return this.call('get_lumi_dpf_aes_key')
|
|
174
|
-
.then(result => {
|
|
175
|
-
let key = result[0];
|
|
176
|
-
if(key && key.length === 16) {
|
|
177
|
-
// This is a valid key, store it
|
|
178
|
-
return key;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
key = generateKey();
|
|
182
|
-
return this.call('set_lumi_dpf_aes_key', [ key ]);
|
|
183
|
-
})
|
|
184
|
-
.then(key => this._setDeveloperKey(key));
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Set the developer key and start listenting for events from the gateway.
|
|
189
|
-
*/
|
|
190
|
-
_setDeveloperKey(key) {
|
|
191
|
-
this._developerKey = key;
|
|
192
|
-
|
|
193
|
-
// If we are already connected to the Developer API skip init
|
|
194
|
-
if(this.devApi) return Promise.resolve();
|
|
195
|
-
|
|
196
|
-
return new Promise((resolve, reject) => {
|
|
197
|
-
this.devApi = new DeveloperApi(this, this.management.address);
|
|
198
|
-
|
|
199
|
-
this.devApi.on('propertiesChanged', e => {
|
|
200
|
-
if(e.id === '0') {
|
|
201
|
-
// Data for the local gateway
|
|
202
|
-
this._report(e.data);
|
|
203
|
-
}
|
|
204
|
-
});
|
|
205
|
-
this.devApi.on('ready', resolve);
|
|
206
|
-
|
|
207
|
-
setTimeout(reject, 10000);
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Start the process of adding a device. Allows Zigbee devices to join for
|
|
213
|
-
* 30 seconds.
|
|
214
|
-
*/
|
|
215
|
-
addDevice() {
|
|
216
|
-
return this.call('start_zigbee_join', [ 30 ])
|
|
217
|
-
.then(MiioApi.checkOk)
|
|
218
|
-
.then(() => setTimeout(this._updateDeviceList.bind(this), 30000))
|
|
219
|
-
.then(() => undefined);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Stop allowing devices to join.
|
|
224
|
-
*/
|
|
225
|
-
stopAddDevice() {
|
|
226
|
-
return this.call('start_zigbee_join', [ 0 ])
|
|
227
|
-
.then(MiioApi.checkOk)
|
|
228
|
-
.then(() => undefined);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Remove a device from the gateway using the identifier of the device.
|
|
233
|
-
*/
|
|
234
|
-
removeDevice(id) {
|
|
235
|
-
return this.call('remove_device', [ id ])
|
|
236
|
-
.then(MiioApi.checkOk)
|
|
237
|
-
.then(this._updateDeviceList.bind(this))
|
|
238
|
-
.then(() => undefined);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
module.exports.Basic = Gateway;
|
|
244
|
-
module.exports.WithLightAndSensor = Gateway.with(LightMixin, Illuminance);
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { SwitchableMode } = require('abstract-things');
|
|
4
|
-
const { Humidifier, AdjustableTargetHumidity } = require('abstract-things/climate');
|
|
5
|
-
|
|
6
|
-
const MiioApi = require('../device');
|
|
7
|
-
|
|
8
|
-
const Power = require('./capabilities/power');
|
|
9
|
-
const Buzzer = require('./capabilities/buzzer');
|
|
10
|
-
const LEDBrightness = require('./capabilities/changeable-led-brightness');
|
|
11
|
-
const { Temperature, Humidity } = require('./capabilities/sensor');
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Abstraction over a Mi Humidifier.
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
module.exports = class extends Humidifier
|
|
18
|
-
.with(MiioApi, Power, SwitchableMode,
|
|
19
|
-
AdjustableTargetHumidity, Temperature, Humidity,
|
|
20
|
-
Buzzer, LEDBrightness)
|
|
21
|
-
{
|
|
22
|
-
static get type() {
|
|
23
|
-
return 'miio:humidifier';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
constructor(options) {
|
|
27
|
-
super(options);
|
|
28
|
-
|
|
29
|
-
this.defineProperty('power', v => v === 'on');
|
|
30
|
-
|
|
31
|
-
// Set the mode property and supported modes
|
|
32
|
-
this.defineProperty('mode');
|
|
33
|
-
this.updateModes([
|
|
34
|
-
'idle',
|
|
35
|
-
'silent',
|
|
36
|
-
'medium',
|
|
37
|
-
'high'
|
|
38
|
-
]);
|
|
39
|
-
|
|
40
|
-
// Humidity limit
|
|
41
|
-
this.defineProperty('limit_hum', {
|
|
42
|
-
name: 'targetHumidity',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Sensor values reported by the device
|
|
46
|
-
this.defineProperty('temp_dec', {
|
|
47
|
-
name: 'temperature',
|
|
48
|
-
mapper: v => v / 10.0
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
this.defineProperty('humidity');
|
|
52
|
-
|
|
53
|
-
// Buzzer and beeping
|
|
54
|
-
this.defineProperty('buzzer', {
|
|
55
|
-
mapper: v => v === 'on'
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
this.defineProperty('led_b', {
|
|
59
|
-
name: 'ledBrightness',
|
|
60
|
-
mapper: v => {
|
|
61
|
-
switch(v) {
|
|
62
|
-
case 0:
|
|
63
|
-
return 'bright';
|
|
64
|
-
case 1:
|
|
65
|
-
return 'dim';
|
|
66
|
-
case 2:
|
|
67
|
-
return 'off';
|
|
68
|
-
default:
|
|
69
|
-
return 'unknown';
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
propertyUpdated(key, value) {
|
|
76
|
-
/*
|
|
77
|
-
* Emulate that the humidifier has an idle mode.
|
|
78
|
-
*/
|
|
79
|
-
if(key === 'power') {
|
|
80
|
-
if(value) {
|
|
81
|
-
const mode = this.property('mode');
|
|
82
|
-
this.updateMode(mode);
|
|
83
|
-
} else {
|
|
84
|
-
this.updateMode('idle');
|
|
85
|
-
}
|
|
86
|
-
} else if(key === 'mode') {
|
|
87
|
-
const power = this.property('power');
|
|
88
|
-
if(power) {
|
|
89
|
-
this.updateMode(value);
|
|
90
|
-
} else {
|
|
91
|
-
this.updateMode('idle');
|
|
92
|
-
}
|
|
93
|
-
} else if(key === 'targetHumidity') {
|
|
94
|
-
this.updateTargetHumidity(value);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
super.propertyUpdated(key, value);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
changePower(power) {
|
|
101
|
-
return this.call('set_power', [ power ? 'on' : 'off' ], {
|
|
102
|
-
refresh: [ 'power', 'mode' ],
|
|
103
|
-
refreshDelay: 200
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Set the mode of this device.
|
|
109
|
-
*/
|
|
110
|
-
changeMode(mode) {
|
|
111
|
-
let promise;
|
|
112
|
-
if(mode === 'idle') {
|
|
113
|
-
return this.setPower(false);
|
|
114
|
-
} else {
|
|
115
|
-
if(this.power()) {
|
|
116
|
-
// Already powered on, do nothing
|
|
117
|
-
promise = Promise.resolve();
|
|
118
|
-
} else {
|
|
119
|
-
// Not powered on, power on
|
|
120
|
-
promise = this.setPower(true);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return promise.then(() => {
|
|
125
|
-
return this.call('set_mode', [ mode ], {
|
|
126
|
-
refresh: [ 'power', 'mode' ],
|
|
127
|
-
refreshDelay: 200
|
|
128
|
-
})
|
|
129
|
-
.then(MiioApi.checkOk)
|
|
130
|
-
.catch(err => {
|
|
131
|
-
throw err.code === -5001 ? new Error('Mode `' + mode + '` not supported') : err;
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
changeTargetHumidity(humidity) {
|
|
137
|
-
return this.call('set_limit_hum', [ humidity ], {
|
|
138
|
-
refresh: [ 'targetHumidity' ]
|
|
139
|
-
}).then(MiioApi.checkOk);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Set the LED brightness to either `bright`, `dim` or `off`.
|
|
144
|
-
*/
|
|
145
|
-
changeLEDBrightness(level) {
|
|
146
|
-
switch(level) {
|
|
147
|
-
case 'bright':
|
|
148
|
-
level = 0;
|
|
149
|
-
break;
|
|
150
|
-
case 'dim':
|
|
151
|
-
level = 1;
|
|
152
|
-
break;
|
|
153
|
-
case 'off':
|
|
154
|
-
level = 2;
|
|
155
|
-
break;
|
|
156
|
-
default:
|
|
157
|
-
return Promise.reject(new Error('Invalid LED brigthness: ' + level));
|
|
158
|
-
}
|
|
159
|
-
return this.call('set_led_b', [ level ], { refresh: [ 'ledBrightness' ] })
|
|
160
|
-
.then(() => null);
|
|
161
|
-
}
|
|
162
|
-
};
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { LightBulb, ColorTemperature } = require('abstract-things/lights');
|
|
4
|
-
const { color } = require('abstract-things/values');
|
|
5
|
-
const MiioApi = require('../device');
|
|
6
|
-
|
|
7
|
-
const Power = require('./capabilities/power');
|
|
8
|
-
const Dimmable = require('./capabilities/dimmable');
|
|
9
|
-
const Colorable = require('./capabilities/colorable');
|
|
10
|
-
|
|
11
|
-
const MIN_TEMP = 3000;
|
|
12
|
-
const MAX_TEMP = 5700;
|
|
13
|
-
|
|
14
|
-
module.exports = class BallLamp extends LightBulb
|
|
15
|
-
.with(MiioApi, Power, Dimmable, Colorable, ColorTemperature)
|
|
16
|
-
{
|
|
17
|
-
static get type() {
|
|
18
|
-
return 'miio:philiphs-ball-lamp';
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
constructor(options) {
|
|
22
|
-
super(options);
|
|
23
|
-
|
|
24
|
-
this.defineProperty('power', {
|
|
25
|
-
name: 'power',
|
|
26
|
-
mapper: v => v === 'on'
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
this.defineProperty('bright', {
|
|
30
|
-
name: 'brightness',
|
|
31
|
-
mapper: parseInt
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
this.defineProperty('cct', {
|
|
35
|
-
name: 'color',
|
|
36
|
-
mapper: v => {
|
|
37
|
-
v = parseInt(v);
|
|
38
|
-
return color.temperature(MIN_TEMP + (v / 100) * (MAX_TEMP - MIN_TEMP));
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
this.updateColorTemperatureRange(MIN_TEMP, MAX_TEMP);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
changePower(power) {
|
|
46
|
-
return this.call('set_power', [ power ? 'on' : 'off' ], {
|
|
47
|
-
refresh: [ 'power' ]
|
|
48
|
-
}).then(MiioApi.checkOk);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
changeBrightness(brightness) {
|
|
52
|
-
return this.call('set_bright', [ brightness ], {
|
|
53
|
-
refresh: [ 'brightness' ]
|
|
54
|
-
}).then(MiioApi.checkOk);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
changeColor(color) {
|
|
58
|
-
const kelvins = color.temperature.kelvins;
|
|
59
|
-
let temp;
|
|
60
|
-
if(kelvins <= MIN_TEMP) {
|
|
61
|
-
temp = 1;
|
|
62
|
-
} else if(kelvins >= MAX_TEMP) {
|
|
63
|
-
temp = 100;
|
|
64
|
-
} else {
|
|
65
|
-
temp = Math.round((kelvins - MIN_TEMP) / (MAX_TEMP - MIN_TEMP) * 100);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return this.call('set_cct', [ temp ], {
|
|
69
|
-
refresh: [ 'color']
|
|
70
|
-
}).then(MiioApi.checkOk);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { Thing } = require('abstract-things');
|
|
4
|
-
const { PowerPlug, PowerOutlet } = require('abstract-things/electrical');
|
|
5
|
-
const MiioApi = require('../device');
|
|
6
|
-
const Power = require('./capabilities/power');
|
|
7
|
-
|
|
8
|
-
module.exports = class extends Thing
|
|
9
|
-
.with(PowerPlug, PowerOutlet, MiioApi, Power)
|
|
10
|
-
{
|
|
11
|
-
static get type() {
|
|
12
|
-
return 'miio:power-plug';
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
constructor(options) {
|
|
16
|
-
super(options);
|
|
17
|
-
|
|
18
|
-
this.defineProperty('power', {
|
|
19
|
-
mapper: v => v === 'on'
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
changePower(power) {
|
|
24
|
-
return this.call('set_power', [ power ? 'on' : 'off' ], { refresh: [ 'power' ] });
|
|
25
|
-
}
|
|
26
|
-
};
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { PowerStrip } = require('abstract-things/electrical');
|
|
4
|
-
|
|
5
|
-
const MiioApi = require('../device');
|
|
6
|
-
const Power = require('./capabilities/power');
|
|
7
|
-
const Mode = require('./capabilities/mode');
|
|
8
|
-
|
|
9
|
-
module.exports = class extends PowerStrip
|
|
10
|
-
.with(MiioApi, Power, Mode)
|
|
11
|
-
{
|
|
12
|
-
static get type() {
|
|
13
|
-
return 'miio:power-strip';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super(options);
|
|
18
|
-
|
|
19
|
-
this.defineProperty('power', {
|
|
20
|
-
mapper: v => v === 'n'
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
this.updateModes([
|
|
24
|
-
'green',
|
|
25
|
-
'normal'
|
|
26
|
-
]);
|
|
27
|
-
|
|
28
|
-
this.defineProperty('mode');
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
changePower(power) {
|
|
32
|
-
return this.call('set_power', [ power ? 'on' : 'off' ], { refresh: [ 'power' ] });
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
changeMode(mode) {
|
|
36
|
-
return this.call('set_power_mode', [ mode ]);
|
|
37
|
-
}
|
|
38
|
-
};
|