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,250 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { ChargingState, AutonomousCharging } = require('abstract-things');
|
|
4
|
-
const {
|
|
5
|
-
Vacuum,
|
|
6
|
-
AdjustableFanSpeed,
|
|
7
|
-
AutonomousCleaning,
|
|
8
|
-
SpotCleaning,
|
|
9
|
-
} = require('abstract-things/climate');
|
|
10
|
-
|
|
11
|
-
const MiioApi = require('../../device');
|
|
12
|
-
const BatteryLevel = require('../capabilities/battery-level');
|
|
13
|
-
const checkResult = require('../../checkResult');
|
|
14
|
-
|
|
15
|
-
module.exports = class extends (
|
|
16
|
-
Vacuum.with(
|
|
17
|
-
MiioApi,
|
|
18
|
-
BatteryLevel,
|
|
19
|
-
AutonomousCharging,
|
|
20
|
-
AutonomousCleaning,
|
|
21
|
-
SpotCleaning,
|
|
22
|
-
AdjustableFanSpeed,
|
|
23
|
-
ChargingState
|
|
24
|
-
)
|
|
25
|
-
) {
|
|
26
|
-
static get type() {
|
|
27
|
-
return 'miio:vacuum';
|
|
28
|
-
}
|
|
29
|
-
constructor(options) {
|
|
30
|
-
super(options);
|
|
31
|
-
|
|
32
|
-
this.defineProperty('err_state', {
|
|
33
|
-
name: 'error',
|
|
34
|
-
mapper: (e) => {
|
|
35
|
-
switch (e) {
|
|
36
|
-
case 0:
|
|
37
|
-
return null;
|
|
38
|
-
default:
|
|
39
|
-
return {
|
|
40
|
-
code: e,
|
|
41
|
-
message: 'Unknown error ' + e,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
this.defineProperty('run_state', {
|
|
48
|
-
name: 'state',
|
|
49
|
-
mapper: (s) => {
|
|
50
|
-
switch (s) {
|
|
51
|
-
case 0:
|
|
52
|
-
return 'paused';
|
|
53
|
-
case 1:
|
|
54
|
-
return 'initiating';
|
|
55
|
-
case 2:
|
|
56
|
-
return 'waiting';
|
|
57
|
-
case 3:
|
|
58
|
-
return 'cleaning';
|
|
59
|
-
case 4:
|
|
60
|
-
return 'returning';
|
|
61
|
-
case 5:
|
|
62
|
-
return 'charging';
|
|
63
|
-
case 6:
|
|
64
|
-
return 'cleaning-and-mopping';
|
|
65
|
-
}
|
|
66
|
-
return 'unknown-' + s;
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
// Define the batteryLevel property for monitoring battery
|
|
71
|
-
this.defineProperty('battary_life', {
|
|
72
|
-
name: 'batteryLevel',
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
this.defineProperty('s_time', {
|
|
76
|
-
name: 'cleanTime',
|
|
77
|
-
});
|
|
78
|
-
this.defineProperty('s_area', {
|
|
79
|
-
name: 'cleanArea',
|
|
80
|
-
mapper: (v) => v / 1000000,
|
|
81
|
-
});
|
|
82
|
-
this.defineProperty('suction_grade', {
|
|
83
|
-
name: 'fanSpeed',
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Consumable status - times for brushes and filters
|
|
87
|
-
// From https://github.com/rytilahti/python-miio/issues/550#issuecomment-570808184
|
|
88
|
-
this.defineProperty('main_brush_life', {
|
|
89
|
-
name: 'mainBrushWorkTime',
|
|
90
|
-
});
|
|
91
|
-
this.defineProperty('side_brush_life', {
|
|
92
|
-
name: 'sideBrushWorkTime',
|
|
93
|
-
});
|
|
94
|
-
this.defineProperty('hypa_life', {
|
|
95
|
-
name: 'filterWorkTime',
|
|
96
|
-
});
|
|
97
|
-
this.defineProperty('mop_life', {
|
|
98
|
-
name: 'mopWorkTime',
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// Monitor the property as is
|
|
102
|
-
this.defineProperty('hw_info');
|
|
103
|
-
|
|
104
|
-
this._monitorInterval = 60000;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
propertyUpdated(key, value, oldValue) {
|
|
108
|
-
if (key === 'state') {
|
|
109
|
-
// Update charging state
|
|
110
|
-
this.updateCharging(value === 'charging');
|
|
111
|
-
|
|
112
|
-
switch (value) {
|
|
113
|
-
case 'cleaning':
|
|
114
|
-
case 'spot-cleaning':
|
|
115
|
-
case 'zone-cleaning':
|
|
116
|
-
case 'room-cleaning':
|
|
117
|
-
// The vacuum is cleaning
|
|
118
|
-
this.updateCleaning(true);
|
|
119
|
-
break;
|
|
120
|
-
case 'paused':
|
|
121
|
-
// Cleaning has been paused, do nothing special
|
|
122
|
-
break;
|
|
123
|
-
case 'error':
|
|
124
|
-
// An error has occurred, rely on error mapping
|
|
125
|
-
this.updateError(this.property('error'));
|
|
126
|
-
break;
|
|
127
|
-
case 'charging-error':
|
|
128
|
-
// Charging error, trigger an error
|
|
129
|
-
this.updateError({
|
|
130
|
-
code: 'charging-error',
|
|
131
|
-
message: 'Error during charging',
|
|
132
|
-
});
|
|
133
|
-
break;
|
|
134
|
-
case 'charger-offline':
|
|
135
|
-
// Charger is offline, trigger an error
|
|
136
|
-
this.updateError({
|
|
137
|
-
code: 'charger-offline',
|
|
138
|
-
message: 'Charger is offline',
|
|
139
|
-
});
|
|
140
|
-
break;
|
|
141
|
-
default:
|
|
142
|
-
// The vacuum is not cleaning
|
|
143
|
-
this.updateCleaning(false);
|
|
144
|
-
break;
|
|
145
|
-
}
|
|
146
|
-
} else if (key === 'fanSpeed') {
|
|
147
|
-
this.updateFanSpeed(value);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
super.propertyUpdated(key, value, oldValue);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
getDeviceInfo() {
|
|
154
|
-
return this.call('miIO.info');
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async getSerialNumber() {
|
|
158
|
-
return this.property('hw_info') || 'Unknown'; // We don't know the command to retrieve this bit of info for these models
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
getRoomMap() {
|
|
162
|
-
return this.call('get_room_mapping');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
cleanRooms(listOfRooms) {
|
|
166
|
-
// From https://github.com/rytilahti/python-miio/issues/550#issuecomment-552780952
|
|
167
|
-
return this.call(
|
|
168
|
-
'set_mode_withroom',
|
|
169
|
-
[0, 1, listOfRooms.length].concat(listOfRooms),
|
|
170
|
-
{
|
|
171
|
-
refresh: ['state'],
|
|
172
|
-
refreshDelay: 1000,
|
|
173
|
-
}
|
|
174
|
-
).then(checkResult);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
resumeCleanRooms(listOfRooms) {
|
|
178
|
-
return this.cleanRooms(listOfRooms);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
getTimer() {
|
|
182
|
-
return this.call('get_ordertime');
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Start a cleaning session.
|
|
187
|
-
*/
|
|
188
|
-
activateCleaning() {
|
|
189
|
-
return this.call('set_mode_withroom', [0, 1, 0], {
|
|
190
|
-
refresh: ['state'],
|
|
191
|
-
refreshDelay: 1000,
|
|
192
|
-
}).then(checkResult);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
/**
|
|
196
|
-
* Pause the current cleaning session.
|
|
197
|
-
*/
|
|
198
|
-
pause() {
|
|
199
|
-
return this.call('set_mode_withroom', [0, 2, 0], {
|
|
200
|
-
refresh: ['state'],
|
|
201
|
-
}).then(checkResult);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Stop the current cleaning session.
|
|
206
|
-
*/
|
|
207
|
-
deactivateCleaning() {
|
|
208
|
-
return this.call('set_mode', [0], {
|
|
209
|
-
refresh: ['state'],
|
|
210
|
-
refreshDelay: 1000,
|
|
211
|
-
}).then(checkResult);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Stop the current cleaning session and return to charge.
|
|
216
|
-
*/
|
|
217
|
-
activateCharging() {
|
|
218
|
-
return this.pause()
|
|
219
|
-
.then(() => new Promise((resolve) => setTimeout(resolve, 1000)))
|
|
220
|
-
.then(() =>
|
|
221
|
-
this.call('set_charge', [1], {
|
|
222
|
-
refresh: ['state'],
|
|
223
|
-
refreshDelay: 1000,
|
|
224
|
-
})
|
|
225
|
-
)
|
|
226
|
-
.then(checkResult);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Set the power of the fan.
|
|
231
|
-
* From https://github.com/rytilahti/python-miio/blob/20f915c9589fed55544a5417abe3fd3d9e12d08d/miio/viomivacuum.py#L16-L20
|
|
232
|
-
* class ViomiVacuumSpeed(Enum):
|
|
233
|
-
* Silent = 0
|
|
234
|
-
* Standard = 1
|
|
235
|
-
* Medium = 2
|
|
236
|
-
* Turbo = 3
|
|
237
|
-
*/
|
|
238
|
-
changeFanSpeed(speed) {
|
|
239
|
-
return this.call('set_suction', [speed], {
|
|
240
|
-
refresh: ['fanSpeed'],
|
|
241
|
-
}).then(checkResult);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Activate the find function, will make the device give off a sound.
|
|
246
|
-
*/
|
|
247
|
-
find() {
|
|
248
|
-
return this.call('find_me', ['']).then(() => null);
|
|
249
|
-
}
|
|
250
|
-
};
|
package/lib/devices/yeelight.js
DELETED
|
@@ -1,286 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { Thing, Nameable } = require('abstract-things');
|
|
4
|
-
const { Light, Fading, Colorable, ColorTemperature, ColorFull } = require('abstract-things/lights');
|
|
5
|
-
const { color } = require('abstract-things/values');
|
|
6
|
-
const MiioApi = require('../device');
|
|
7
|
-
|
|
8
|
-
const Power = require('./capabilities/power');
|
|
9
|
-
const Dimmable = require('./capabilities/dimmable');
|
|
10
|
-
|
|
11
|
-
const DEFAULT_EFFECT = 'smooth';
|
|
12
|
-
const DEFAULT_DURATION = 500;
|
|
13
|
-
|
|
14
|
-
const Yeelight = Thing.type(Parent => class Yeelight extends Parent
|
|
15
|
-
.with(Light, Fading, MiioApi, Power, Dimmable, Nameable)
|
|
16
|
-
{
|
|
17
|
-
static get type() {
|
|
18
|
-
return 'miio:yeelight';
|
|
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
|
-
// Used for scheduling turning off after a while
|
|
35
|
-
this.defineProperty('delayoff', {
|
|
36
|
-
name: 'offDelay',
|
|
37
|
-
mapper: parseInt
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
// Query for the color mode
|
|
41
|
-
this.defineProperty('color_mode', {
|
|
42
|
-
name: 'colorMode',
|
|
43
|
-
mapper: v => {
|
|
44
|
-
v = parseInt(v);
|
|
45
|
-
switch(v) {
|
|
46
|
-
case 1:
|
|
47
|
-
return 'rgb';
|
|
48
|
-
case 2:
|
|
49
|
-
return 'colorTemperature';
|
|
50
|
-
case 3:
|
|
51
|
-
return 'hsv';
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
// Read the name of the light
|
|
57
|
-
this.defineProperty('name');
|
|
58
|
-
|
|
59
|
-
/*
|
|
60
|
-
* Set maximum fade time to 30s - seems to work well, longer values
|
|
61
|
-
* sometimes cause jumps on certain models.
|
|
62
|
-
*/
|
|
63
|
-
this.updateMaxChangeTime('30s');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
propertyUpdated(key, value) {
|
|
67
|
-
if(key === 'name') {
|
|
68
|
-
this.metadata.name = value;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
super.propertyUpdated(key, value);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
changePower(power) {
|
|
75
|
-
// TODO: Support for duration
|
|
76
|
-
return this.call(
|
|
77
|
-
'set_power',
|
|
78
|
-
Yeelight.withEffect(power ? 'on' : 'off'),
|
|
79
|
-
{
|
|
80
|
-
refresh: [ 'power']
|
|
81
|
-
}
|
|
82
|
-
).then(MiioApi.checkOk);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Make the current state the default state, meaning the light will restore
|
|
87
|
-
* to this state after power has been cut.
|
|
88
|
-
*/
|
|
89
|
-
setDefault() {
|
|
90
|
-
return this.call('set_default')
|
|
91
|
-
.then(MiioApi.checkOk);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
changeBrightness(brightness, options) {
|
|
95
|
-
if(brightness <= 0) {
|
|
96
|
-
return this.changePower(false);
|
|
97
|
-
} else {
|
|
98
|
-
let promise;
|
|
99
|
-
if(options.powerOn && this.power() === false) {
|
|
100
|
-
// Currently not turned on
|
|
101
|
-
promise = this.changePower(true);
|
|
102
|
-
} else {
|
|
103
|
-
promise = Promise.resolve();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return promise.then(() =>
|
|
107
|
-
this.call(
|
|
108
|
-
'set_bright',
|
|
109
|
-
Yeelight.withEffect(brightness, options.duration), {
|
|
110
|
-
refresh: [ 'brightness' ]
|
|
111
|
-
})
|
|
112
|
-
).then(MiioApi.checkOk);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
changeName(name) {
|
|
117
|
-
return this.call('set_name', [ name ])
|
|
118
|
-
.then(MiioApi.checkOk)
|
|
119
|
-
.then(() => this.metadata.name = name);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Helper method to combine an argument with effect information.
|
|
124
|
-
*/
|
|
125
|
-
static withEffect(arg, duration) {
|
|
126
|
-
const result = Array.isArray(arg) ? arg : [ arg ];
|
|
127
|
-
|
|
128
|
-
if(duration) {
|
|
129
|
-
if(duration.ms > 0) {
|
|
130
|
-
result.push(DEFAULT_EFFECT);
|
|
131
|
-
result.push(duration.ms);
|
|
132
|
-
} else {
|
|
133
|
-
result.push('sudden');
|
|
134
|
-
result.push(0);
|
|
135
|
-
}
|
|
136
|
-
} else {
|
|
137
|
-
result.push(DEFAULT_EFFECT);
|
|
138
|
-
result.push(DEFAULT_DURATION);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return result;
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
module.exports.Yeelight = Yeelight;
|
|
146
|
-
|
|
147
|
-
module.exports.ColorTemperature = Thing.mixin(Parent => class extends Parent
|
|
148
|
-
.with(MiioApi, Colorable, ColorTemperature)
|
|
149
|
-
{
|
|
150
|
-
|
|
151
|
-
constructor(...args) {
|
|
152
|
-
super(...args);
|
|
153
|
-
|
|
154
|
-
// Color temperature
|
|
155
|
-
this.defineProperty('ct', {
|
|
156
|
-
name: 'colorTemperature',
|
|
157
|
-
mapper: parseInt
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
// TODO: Do all Yeelights use the same color range?
|
|
161
|
-
this.updateColorTemperatureRange(2700, 6500);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
propertyUpdated(key, value) {
|
|
165
|
-
if(key === 'colorTemperature') {
|
|
166
|
-
this.updateColor(color.temperature(value));
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
super.propertyUpdated(key, value);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
changeColor(color, options) {
|
|
173
|
-
const range = this.colorTemperatureRange;
|
|
174
|
-
const temperature = Math.min(Math.max(color.temperature.kelvins, range.min), range.max);
|
|
175
|
-
|
|
176
|
-
return this.call('set_ct_abx', Yeelight.withEffect(temperature, options.duration), {
|
|
177
|
-
refresh: [ 'colorTemperature' ]
|
|
178
|
-
}).then(MiioApi.checkOk);
|
|
179
|
-
}
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
module.exports.ColorFull = Thing.mixin(Parent => class extends Parent
|
|
183
|
-
.with(MiioApi, Colorable, ColorTemperature, ColorFull)
|
|
184
|
-
{
|
|
185
|
-
|
|
186
|
-
constructor(...args) {
|
|
187
|
-
super(...args);
|
|
188
|
-
|
|
189
|
-
// Color temperature
|
|
190
|
-
this.defineProperty('ct', {
|
|
191
|
-
name: 'colorTemperature',
|
|
192
|
-
mapper: parseInt
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
this.defineProperty('rgb', {
|
|
196
|
-
name: 'colorRGB',
|
|
197
|
-
mapper: rgb => {
|
|
198
|
-
rgb = parseInt(rgb);
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
red: (rgb >> 16) & 0xff,
|
|
202
|
-
green: (rgb >> 8) & 0xff,
|
|
203
|
-
blue: rgb & 0xff
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
this.defineProperty('hue', {
|
|
209
|
-
name: 'colorHue',
|
|
210
|
-
mapper: parseInt
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
this.defineProperty('sat', {
|
|
214
|
-
name: 'colorSaturation',
|
|
215
|
-
mapper: parseInt
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
this.metadata.addCapabilities('color:temperature', 'color:full');
|
|
219
|
-
|
|
220
|
-
// TODO: Do all Yeelights use the same color range?
|
|
221
|
-
this.updateColorTemperatureRange(2700, 6500);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
propertyUpdated(key, value) {
|
|
225
|
-
if(key === 'colorTemperature' || key === 'colorMode' || key === 'colorRGB' || key === 'colorHue' || key === 'colorSaturation' || key === 'brightness') {
|
|
226
|
-
let currentColor = this.color();
|
|
227
|
-
switch(this.property('colorMode')) {
|
|
228
|
-
case 'colorTemperature':
|
|
229
|
-
// Currently using color temperature mode, parse as temperature
|
|
230
|
-
currentColor = color.temperature(this.property('colorTemperature'));
|
|
231
|
-
break;
|
|
232
|
-
case 'rgb': {
|
|
233
|
-
// Using RGB, parse if we have gotten the RGB value
|
|
234
|
-
let rgb = this.property('colorRGB');
|
|
235
|
-
if(rgb) {
|
|
236
|
-
currentColor = color.rgb(rgb.red, rgb.green, rgb.blue);
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case 'hsv': {
|
|
241
|
-
// Using HSV, parse the hue, saturation and get the brightness to set color
|
|
242
|
-
let hue = this.property('colorHue');
|
|
243
|
-
let saturation = this.property('colorSaturation');
|
|
244
|
-
|
|
245
|
-
if(typeof hue !== 'undefined' && typeof saturation !== 'undefined') {
|
|
246
|
-
currentColor = color.hsv(hue, saturation, this.property('brightness'));
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
this.updateColor(currentColor);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
super.propertyUpdated(key, value);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
changeColor(color, options) {
|
|
258
|
-
if(color.is('temperature')) {
|
|
259
|
-
// The user has request a color via temperature
|
|
260
|
-
|
|
261
|
-
const range = this.colorTemperatureRange;
|
|
262
|
-
const temperature = Math.min(Math.max(color.temperature.kelvins, range.min), range.max);
|
|
263
|
-
|
|
264
|
-
return this.call('set_ct_abx', Yeelight.withEffect(temperature, options.duration), {
|
|
265
|
-
refresh: [ 'colorTemperature', 'colorMode' ]
|
|
266
|
-
}).then(MiioApi.checkOk);
|
|
267
|
-
} else if(color.is('hsl')) {
|
|
268
|
-
/*
|
|
269
|
-
* User has requested hue and saturation
|
|
270
|
-
*/
|
|
271
|
-
return this.call('set_hsv', Yeelight.withEffect([ color.hue, color.saturation ], options.duration), {
|
|
272
|
-
refresh: [ 'colorHue', 'colorSaturation', 'colorMode' ]
|
|
273
|
-
}).then(MiioApi.checkOk);
|
|
274
|
-
} else {
|
|
275
|
-
/*
|
|
276
|
-
* Fallback to applying via RGB.
|
|
277
|
-
*/
|
|
278
|
-
color = color.rgb;
|
|
279
|
-
|
|
280
|
-
const rgb = color.red * 65536 + color.green * 256 + color.blue;
|
|
281
|
-
return this.call('set_rgb', Yeelight.withEffect(rgb, options.duration), {
|
|
282
|
-
refresh: [ 'colorRGB', 'colorMode' ]
|
|
283
|
-
}).then(MiioApi.checkOk);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
});
|