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,55 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const SubDevice = require('./subdevice');
|
|
4
|
-
const { Controller, Actions } = require('abstract-things/controllers');
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Cube device, emits `action` with an object when someone interacts with
|
|
8
|
-
* the cube.
|
|
9
|
-
*
|
|
10
|
-
* Supports the actions:
|
|
11
|
-
* * `alert` - when the cube has been idle for a while and it wakes up
|
|
12
|
-
* * `flip90` - when the cube is flipped 90 degrees in any direction
|
|
13
|
-
* * `flip180` - when the cube is flipped 180 degress in any direction
|
|
14
|
-
* * `move` - when the cube is moved on its current surface (slide)
|
|
15
|
-
* * `shake_air` - when the cube is shaken in the air
|
|
16
|
-
* * `free_fall` - when the cube is dropped in a free fall
|
|
17
|
-
* * `swing` - when the cube is held in hand and the fake thrown
|
|
18
|
-
*/
|
|
19
|
-
module.exports = class Cube extends SubDevice.with(Controller, Actions) {
|
|
20
|
-
constructor(parent, info) {
|
|
21
|
-
super(parent, info);
|
|
22
|
-
|
|
23
|
-
this.miioModel = 'lumi.cube';
|
|
24
|
-
|
|
25
|
-
this.updateActions([
|
|
26
|
-
'alert',
|
|
27
|
-
'flip90',
|
|
28
|
-
'flip180',
|
|
29
|
-
'move',
|
|
30
|
-
'tap_twice',
|
|
31
|
-
'shake_air',
|
|
32
|
-
'free_fall',
|
|
33
|
-
'rotate'
|
|
34
|
-
]);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
_report(data) {
|
|
38
|
-
super._report(data);
|
|
39
|
-
|
|
40
|
-
if(typeof data.status !== 'undefined') {
|
|
41
|
-
this.debug('Action performed:', data.status);
|
|
42
|
-
this.emitAction(data.status);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if(typeof data.rotate !== 'undefined') {
|
|
46
|
-
const r = data.rotate;
|
|
47
|
-
const idx = r.indexOf(',');
|
|
48
|
-
const amount = parseInt(r.substring(0, idx));
|
|
49
|
-
this.debug('Action performed:', 'rotate', amount);
|
|
50
|
-
this.emitAction('rotate', {
|
|
51
|
-
amount: amount
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const EventEmitter = require('events');
|
|
4
|
-
const dgram = require('dgram');
|
|
5
|
-
const os = require('os');
|
|
6
|
-
|
|
7
|
-
const MULTICAST_ADDRESS = '224.0.0.50';
|
|
8
|
-
const MULTICAST_PORT = 4321;
|
|
9
|
-
|
|
10
|
-
const SERVER_PORT = 9898;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Local Developer API for the gateway. Used to read data from the gateway
|
|
14
|
-
* and connected devices.
|
|
15
|
-
*
|
|
16
|
-
* TODO: Retries for discovery
|
|
17
|
-
*/
|
|
18
|
-
module.exports = class DeveloperApi extends EventEmitter {
|
|
19
|
-
constructor(parent, address) {
|
|
20
|
-
super();
|
|
21
|
-
|
|
22
|
-
this.address = address;
|
|
23
|
-
this.port = SERVER_PORT;
|
|
24
|
-
|
|
25
|
-
// Bind a custom function instead of using directly to skip resolving debug before id is set
|
|
26
|
-
this.debug = function() { parent.debug.apply(parent, arguments); };
|
|
27
|
-
|
|
28
|
-
this.socket = dgram.createSocket({
|
|
29
|
-
type: 'udp4',
|
|
30
|
-
reuseAddr: true
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
this.socket.on('message', this._onMessage.bind(this));
|
|
34
|
-
this.socket.on('listening', () => {
|
|
35
|
-
// Add membership to the multicast addresss for all network interfaces
|
|
36
|
-
const interfaces = os.networkInterfaces();
|
|
37
|
-
for(const name of Object.keys(interfaces)) {
|
|
38
|
-
const addresses = interfaces[name];
|
|
39
|
-
|
|
40
|
-
for(const addr of addresses) {
|
|
41
|
-
if(addr.family === 'IPv4') {
|
|
42
|
-
this.socket.addMembership(MULTICAST_ADDRESS, addr.address);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Broadcast a whois to find all gateways
|
|
48
|
-
const json = JSON.stringify({
|
|
49
|
-
cmd: 'whois'
|
|
50
|
-
});
|
|
51
|
-
this.debug('DEV BROADCAST ->', json);
|
|
52
|
-
this.socket.send(json, 0, json.length, MULTICAST_PORT, MULTICAST_ADDRESS);
|
|
53
|
-
|
|
54
|
-
// Give us one second to discover the gateway
|
|
55
|
-
setTimeout(() => {
|
|
56
|
-
this.debug('DEV <- Timeout for whois');
|
|
57
|
-
this.emit('ready');
|
|
58
|
-
}, 1000);
|
|
59
|
-
});
|
|
60
|
-
this.socket.bind({
|
|
61
|
-
port: SERVER_PORT,
|
|
62
|
-
exclusive: true
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
destroy() {
|
|
67
|
-
this.socket.close();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
send(data) {
|
|
71
|
-
const json = JSON.stringify(data);
|
|
72
|
-
this.debug('DEV ->', json);
|
|
73
|
-
|
|
74
|
-
this.socket.send(json, 0, json.length, this.port, this.address);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
read(sid) {
|
|
78
|
-
this.send({
|
|
79
|
-
cmd: 'read',
|
|
80
|
-
sid: sid
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
_onMessage(msg) {
|
|
85
|
-
let data;
|
|
86
|
-
try {
|
|
87
|
-
this.debug('DEV <-', msg.toString());
|
|
88
|
-
data = JSON.parse(msg.toString());
|
|
89
|
-
} catch(ex) {
|
|
90
|
-
this.emit('error', ex);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
switch(data.cmd) {
|
|
95
|
-
case 'iam':
|
|
96
|
-
if(data.ip === this.address) {
|
|
97
|
-
this.port = data.port;
|
|
98
|
-
this.sid = data.sid;
|
|
99
|
-
|
|
100
|
-
this.emit('ready');
|
|
101
|
-
}
|
|
102
|
-
break;
|
|
103
|
-
case 'read_ack':
|
|
104
|
-
case 'heartbeat':
|
|
105
|
-
case 'report': {
|
|
106
|
-
if(! this.sid && data.model === 'gateway') {
|
|
107
|
-
this.sid = data.sid;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const parsed = JSON.parse(data.data);
|
|
111
|
-
this.emit('propertiesChanged', {
|
|
112
|
-
id: this.sid === data.sid ? '0' : data.sid,
|
|
113
|
-
data: parsed
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
this.emit('properties:' + data.sid, parsed);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { Light, SwitchablePower } = require('abstract-things/lights');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Representation of a power channel.
|
|
7
|
-
*/
|
|
8
|
-
module.exports = class LightChannel extends Light.with(SwitchablePower) {
|
|
9
|
-
static get types() {
|
|
10
|
-
return [ 'miio:subdevice', 'miio:power-channel', 'miio:light' ];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
constructor(parent, channel) {
|
|
14
|
-
super();
|
|
15
|
-
|
|
16
|
-
this.id = parent.id + ':' + channel;
|
|
17
|
-
|
|
18
|
-
this.parent = parent;
|
|
19
|
-
this.channel = channel;
|
|
20
|
-
|
|
21
|
-
this.updateName();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
updateName() {
|
|
25
|
-
this.metadata.name = this.parent.name + ' - ' + this.channel;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
changePower(power) {
|
|
29
|
-
return this.parent.changePowerChannel(this.channel, power);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
};
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { Thing } = require('abstract-things');
|
|
4
|
-
const { Light, SwitchablePower, Dimmable, Colorable } = require('abstract-things/lights');
|
|
5
|
-
const { color } = require('abstract-things/values');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Capability that register the
|
|
9
|
-
*/
|
|
10
|
-
module.exports = Thing.mixin(Appliance => class extends Appliance {
|
|
11
|
-
initCallback() {
|
|
12
|
-
this.addExtraChild(new GatewayLight(this));
|
|
13
|
-
|
|
14
|
-
return super.initCallback();
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Capability that is mixed in if a gateway is also a light.
|
|
20
|
-
*/
|
|
21
|
-
const GatewayLight = class extends Light.with(SwitchablePower, Dimmable, Colorable) {
|
|
22
|
-
static get types() {
|
|
23
|
-
return [ 'miio:subdevice', 'miio:gateway-light' ];
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
constructor(gateway) {
|
|
27
|
-
super();
|
|
28
|
-
|
|
29
|
-
this.model = gateway.miioModel + '.light';
|
|
30
|
-
this.internalId = gateway.id.substring(5) + ':light';
|
|
31
|
-
this.id = gateway.id + ':light';
|
|
32
|
-
this.gateway = gateway;
|
|
33
|
-
|
|
34
|
-
// Hijack the property updated event to make control easier
|
|
35
|
-
const propertyUpdated = this.gateway.propertyUpdated;
|
|
36
|
-
this.gateway.propertyUpdated = (key, value, oldValue) => {
|
|
37
|
-
propertyUpdated.call(this.gateway, key, value, oldValue);
|
|
38
|
-
|
|
39
|
-
this.propertyUpdated(key, value);
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
changePower(power) {
|
|
44
|
-
return this.changeBrightness(power ? 50 : 0);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
changeBrightness(brightness, options) {
|
|
48
|
-
const color = this.gateway.property('rgb');
|
|
49
|
-
const rgb = brightness << 24 | (color.red << 16) | (color.green << 8) | color.blue;
|
|
50
|
-
|
|
51
|
-
return this.gateway.call('set_rgb', [ rgb >>> 0 ], { refresh: [ 'rgb' ] });
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
changeColor(color, options) {
|
|
55
|
-
color = color.rgb;
|
|
56
|
-
const a = this.gateway.property('brightness');
|
|
57
|
-
const rgb = a << 24 | (color.red << 16) | (color.green << 8) | color.blue;
|
|
58
|
-
|
|
59
|
-
return this.gateway.call('set_rgb', [ rgb >>> 0 ], { refresh: [ 'rgb' ] });
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
propertyUpdated(key, value) {
|
|
63
|
-
if(key === 'rgb') {
|
|
64
|
-
this.updateColor(color.rgb(value.red, value.green, value.blue));
|
|
65
|
-
} else if(key === 'brightness') {
|
|
66
|
-
//this.updateBrightness(Math.round(value / 255 * 100));
|
|
67
|
-
this.updateBrightness(value);
|
|
68
|
-
this.updatePower(value > 0);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const SubDevice = require('./subdevice');
|
|
5
|
-
const { Contact } = require('abstract-things/sensors');
|
|
6
|
-
const Voltage = require('./voltage');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Magnet device, emits events `open` and `close` if the state changes.
|
|
10
|
-
*/
|
|
11
|
-
module.exports = class Magnet extends SubDevice.with(Contact, Voltage) {
|
|
12
|
-
constructor(parent, info) {
|
|
13
|
-
super(parent, info);
|
|
14
|
-
|
|
15
|
-
this.miioModel = 'lumi.magnet';
|
|
16
|
-
|
|
17
|
-
this.defineProperty('status');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
propertyUpdated(key, value, oldValue) {
|
|
21
|
-
if(key === 'status') {
|
|
22
|
-
// Change the contact state
|
|
23
|
-
const isContact = value === 'close';
|
|
24
|
-
this.updateContact(isContact);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
super.propertyUpdated(key, value, oldValue);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const SubDevice = require('./subdevice');
|
|
4
|
-
const { Motion } = require('abstract-things/sensors');
|
|
5
|
-
const Voltage = require('./voltage');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Motion sensing device, emits the event `motion` whenever motion is detected.
|
|
9
|
-
*/
|
|
10
|
-
module.exports = class extends SubDevice.with(Motion, Voltage) {
|
|
11
|
-
constructor(parent, info) {
|
|
12
|
-
super(parent, info);
|
|
13
|
-
|
|
14
|
-
this.miioModel = 'lumi.motion';
|
|
15
|
-
|
|
16
|
-
this.updateMotion(false);
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_report(data) {
|
|
21
|
-
super._report(data);
|
|
22
|
-
|
|
23
|
-
if(typeof data.status !== 'undefined' && data.status === 'motion') {
|
|
24
|
-
this.updateMotion(true, '1m');
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const SubDevice = require('./subdevice');
|
|
4
|
-
const { Motion } = require('abstract-things/sensors');
|
|
5
|
-
const { Illuminance } = require('../capabilities/sensor');
|
|
6
|
-
const Voltage = require('./voltage');
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Motion sensing device, emits the event `motion` whenever motion is detected.
|
|
10
|
-
*/
|
|
11
|
-
module.exports = class extends SubDevice.with(Motion, Illuminance, Voltage) {
|
|
12
|
-
constructor(parent, info) {
|
|
13
|
-
super(parent, info);
|
|
14
|
-
|
|
15
|
-
this.miioModel = 'lumi.motion.aq2';
|
|
16
|
-
|
|
17
|
-
this.defineProperty('status');
|
|
18
|
-
|
|
19
|
-
this.defineProperty('lux', {
|
|
20
|
-
name: 'illuminance'
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
_report(data) {
|
|
25
|
-
super._report(data);
|
|
26
|
-
|
|
27
|
-
if(typeof data.status !== 'undefined' && data.status === 'motion') {
|
|
28
|
-
this.updateMotion(true, '1m');
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { PowerPlug, PowerOutlet } = require('abstract-things/electrical');
|
|
5
|
-
|
|
6
|
-
const SubDevice = require('./subdevice');
|
|
7
|
-
const Power = require('../capabilities/power');
|
|
8
|
-
const { PowerLoad, PowerConsumed } = require('../capabilities/sensor');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Wall plug. Can be turned on or off.
|
|
12
|
-
*/
|
|
13
|
-
module.exports = class Plug extends SubDevice
|
|
14
|
-
.with(PowerPlug, PowerOutlet, Power, PowerLoad, PowerConsumed)
|
|
15
|
-
{
|
|
16
|
-
|
|
17
|
-
constructor(parent, info) {
|
|
18
|
-
super(parent, info);
|
|
19
|
-
|
|
20
|
-
this.miioModel = 'lumi.plug';
|
|
21
|
-
|
|
22
|
-
this.defineProperty('status', {
|
|
23
|
-
name: 'power',
|
|
24
|
-
mapper: v => (v === '') ? undefined : (v === 'on')
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
this.defineProperty('load_voltage', {
|
|
28
|
-
name: 'loadVoltage',
|
|
29
|
-
mapper: parseInt
|
|
30
|
-
});
|
|
31
|
-
this.defineProperty('load_power', {
|
|
32
|
-
name: 'powerLoad',
|
|
33
|
-
mapper: parseInt
|
|
34
|
-
});
|
|
35
|
-
this.defineProperty('power_consumed', {
|
|
36
|
-
name: 'powerConsumed',
|
|
37
|
-
mapper: parseFloat
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
changePower(power) {
|
|
42
|
-
return this.call('toggle_plug', [ 'neutral_0', power ? 'on' : 'off' ]);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const SubDevice = require('./subdevice');
|
|
5
|
-
const { Temperature, Humidity } = require('../capabilities/sensor');
|
|
6
|
-
const Voltage = require('./voltage');
|
|
7
|
-
|
|
8
|
-
module.exports = class SensorHT extends SubDevice.with(Temperature, Humidity, Voltage) {
|
|
9
|
-
constructor(parent, info) {
|
|
10
|
-
super(parent, info);
|
|
11
|
-
|
|
12
|
-
this.miioModel = 'lumi.sensor_ht';
|
|
13
|
-
|
|
14
|
-
this.defineProperty('temperature', v => v / 100.0);
|
|
15
|
-
this.defineProperty('humidity', v => v / 100.0);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const util = require('util');
|
|
4
|
-
const isDeepEqual = require('deep-equal');
|
|
5
|
-
const { Thing } = require('abstract-things');
|
|
6
|
-
|
|
7
|
-
const IDENTITY_MAPPER = v => v;
|
|
8
|
-
|
|
9
|
-
class SubDeviceManagement {
|
|
10
|
-
constructor(device, parent) {
|
|
11
|
-
this._device = device;
|
|
12
|
-
this.parent = parent;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
get token() {
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get model() {
|
|
20
|
-
return this._device.miioModel;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
info() {
|
|
24
|
-
const device = this._device;
|
|
25
|
-
return Promise.resolve({
|
|
26
|
-
id: device.id,
|
|
27
|
-
model: device.model
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
module.exports = Thing.type(Parent => class SubDevice extends Parent {
|
|
33
|
-
static get types() {
|
|
34
|
-
return [ 'miio', 'miio:subdevice' ];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
constructor(parent, info) {
|
|
38
|
-
super();
|
|
39
|
-
|
|
40
|
-
this.miioModel = info.model;
|
|
41
|
-
this.id = info.id;
|
|
42
|
-
|
|
43
|
-
// Store the internal id by removing the `miio:` prefix
|
|
44
|
-
this.internalId = info.id.substring(5);
|
|
45
|
-
|
|
46
|
-
this._properties = {};
|
|
47
|
-
this._propertiesToMonitor = [];
|
|
48
|
-
this._propertyDefinitions = {};
|
|
49
|
-
|
|
50
|
-
this._parent = parent;
|
|
51
|
-
|
|
52
|
-
// Bind the _report function for use with developer API
|
|
53
|
-
this._report = this._report.bind(this);
|
|
54
|
-
|
|
55
|
-
this.management = new SubDeviceManagement(this, parent);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
hasCapability(name) {
|
|
59
|
-
return this.capabilities.indexOf(name) >= 0;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
initCallback() {
|
|
63
|
-
return super.initCallback()
|
|
64
|
-
.then(() => this._parent.devApi.on('properties:' + this.internalId, this._report))
|
|
65
|
-
.then(() => this.loadProperties());
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
destroyCallback() {
|
|
69
|
-
return super.destroyCallback()
|
|
70
|
-
.then(() => this._parent.devApi.removeListener('properties:' + this.internalId, this._report));
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
_report(data) {
|
|
74
|
-
this._propertiesToMonitor.forEach(key => {
|
|
75
|
-
const def = this._propertyDefinitions[key];
|
|
76
|
-
let name = key;
|
|
77
|
-
let value = data[key];
|
|
78
|
-
if(typeof value === 'undefined') return;
|
|
79
|
-
|
|
80
|
-
if(def) {
|
|
81
|
-
name = def.name || name;
|
|
82
|
-
value = def.mapper(value);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.setProperty(name, value);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if(this._currentRead) {
|
|
89
|
-
this._currentRead.resolve();
|
|
90
|
-
this._currentRead = null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get properties() {
|
|
95
|
-
return Object.assign({}, this._properties);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
property(key) {
|
|
99
|
-
return this._properties[key];
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Define a property and how the value should be mapped. All defined
|
|
104
|
-
* properties are monitored if #monitor() is called.
|
|
105
|
-
*/
|
|
106
|
-
defineProperty(name, def) {
|
|
107
|
-
if(! def || typeof def.poll === 'undefined' || def.poll) {
|
|
108
|
-
this._propertiesToMonitor.push(name);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if(typeof def === 'function') {
|
|
112
|
-
def = {
|
|
113
|
-
mapper: def
|
|
114
|
-
};
|
|
115
|
-
} else if(typeof def === 'undefined') {
|
|
116
|
-
def = {
|
|
117
|
-
mapper: IDENTITY_MAPPER
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if(! def.mapper) {
|
|
122
|
-
def.mapper = IDENTITY_MAPPER;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this._propertyDefinitions[name] = def;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
setProperty(key, value) {
|
|
129
|
-
const oldValue = this._properties[key];
|
|
130
|
-
|
|
131
|
-
if(! isDeepEqual(oldValue, value)) {
|
|
132
|
-
this._properties[key] = value;
|
|
133
|
-
this.debug('Property', key, 'changed from', oldValue, 'to', value);
|
|
134
|
-
|
|
135
|
-
this.propertyUpdated(key, value, oldValue);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
propertyUpdated(key, value, oldValue) {
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
getProperties(props=[]) {
|
|
143
|
-
const result = {};
|
|
144
|
-
props.forEach(key => {
|
|
145
|
-
result[key] = this._properties[key];
|
|
146
|
-
});
|
|
147
|
-
return result;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Stub for loadProperties to match full device.
|
|
152
|
-
*/
|
|
153
|
-
loadProperties(props) {
|
|
154
|
-
if(this._propertiesToMonitor.length === 0) Promise.resolve();
|
|
155
|
-
|
|
156
|
-
if(this._currentRead) {
|
|
157
|
-
return this._currentRead.promise;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Store information about the current read promise and how to resolve it
|
|
161
|
-
this._currentRead = {};
|
|
162
|
-
this._currentRead.promise = new Promise((resolve, reject) => {
|
|
163
|
-
// Request the read
|
|
164
|
-
this._parent.devApi.read(this.internalId);
|
|
165
|
-
|
|
166
|
-
// Store the resolve to be used in _report
|
|
167
|
-
this._currentRead.resolve = () => {
|
|
168
|
-
resolve(this.getProperties(props));
|
|
169
|
-
};
|
|
170
|
-
|
|
171
|
-
/*
|
|
172
|
-
* Fallback behavior, use a regular call if properties have not
|
|
173
|
-
* been resolved in a second.
|
|
174
|
-
*/
|
|
175
|
-
setTimeout(() => {
|
|
176
|
-
this.debug('Read via DEV timed out, using fallback API');
|
|
177
|
-
this._parent.call('get_device_prop_exp', [ [ 'lumi.' + this.internalId, ...this._propertiesToMonitor ]])
|
|
178
|
-
.then(result => {
|
|
179
|
-
for(let i=0; i<result[0].length; i++) {
|
|
180
|
-
let name = this._propertiesToMonitor[i];
|
|
181
|
-
const def = this._propertyDefinitions[name];
|
|
182
|
-
let value = result[0][i];
|
|
183
|
-
|
|
184
|
-
name = def.name || name;
|
|
185
|
-
value = def.mapper(value);
|
|
186
|
-
|
|
187
|
-
this.setProperty(name, value);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
this._currentRead.resolve();
|
|
191
|
-
})
|
|
192
|
-
.catch(err => {
|
|
193
|
-
this._currentRead = null;
|
|
194
|
-
reject(err);
|
|
195
|
-
});
|
|
196
|
-
}, 1000);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
return this._currentRead.promise;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* Call a method for this sub device.
|
|
204
|
-
*/
|
|
205
|
-
call(method, args, options) {
|
|
206
|
-
if(! options) {
|
|
207
|
-
options = {};
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
options.sid = this.internalId;
|
|
211
|
-
return this._parent.call(method, args, options);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
[util.inspect.custom](depth, options) {
|
|
215
|
-
if(depth === 0) {
|
|
216
|
-
return options.stylize('MiioDevice', 'special')
|
|
217
|
-
+ '[' + this.miioModel + ']';
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
return options.stylize('MiioDevice', 'special')
|
|
221
|
-
+ ' {\n'
|
|
222
|
-
+ ' model=' + this.miioModel + ',\n'
|
|
223
|
-
+ ' types=' + Array.from(this.metadata.types).join(', ') + ',\n'
|
|
224
|
-
+ ' capabilities=' + Array.from(this.metadata.capabilities).join(', ')
|
|
225
|
-
+ '\n}';
|
|
226
|
-
}
|
|
227
|
-
});
|