node-miio 0.2.1 → 0.3.0-beta.1
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/.editorconfig +5 -0
- package/.github/release.yml +20 -0
- package/lib/connectToDevice.js +7 -3
- package/lib/devices/vacuums/dreamevacuum.js +349 -0
- package/lib/devices/{mijiavacuum.js → vacuums/mijiavacuum.js} +1 -1
- package/lib/devices/{vacuum.js → vacuums/vacuum.js} +19 -4
- package/lib/devices/{viomivacuum.js → vacuums/viomivacuum.js} +3 -3
- package/lib/models.js +3 -4
- package/package.json +1 -1
package/.editorconfig
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
changelog:
|
|
2
|
+
exclude:
|
|
3
|
+
labels:
|
|
4
|
+
- release
|
|
5
|
+
categories:
|
|
6
|
+
- title: 🏕 New Features
|
|
7
|
+
labels:
|
|
8
|
+
- enhancement
|
|
9
|
+
- title: 🐛 Bug Fixes
|
|
10
|
+
labels:
|
|
11
|
+
- bug
|
|
12
|
+
- title: ⚙️ Other Changes
|
|
13
|
+
labels:
|
|
14
|
+
- '*'
|
|
15
|
+
exclude:
|
|
16
|
+
labels:
|
|
17
|
+
- dependencies
|
|
18
|
+
- title: 👒 Dependencies
|
|
19
|
+
labels:
|
|
20
|
+
- dependencies
|
package/lib/connectToDevice.js
CHANGED
|
@@ -6,8 +6,9 @@ const Device = require('./device');
|
|
|
6
6
|
const Placeholder = require('./placeholder');
|
|
7
7
|
const models = require('./models');
|
|
8
8
|
|
|
9
|
-
const Vacuum = require('./devices/vacuum');
|
|
10
|
-
const ViomiVacuum = require('./devices/viomivacuum');
|
|
9
|
+
const Vacuum = require('./devices/vacuums/vacuum');
|
|
10
|
+
const ViomiVacuum = require('./devices/vacuums/viomivacuum');
|
|
11
|
+
const DreameVacuum = require('./devices/vacuums/dreamevacuum');
|
|
11
12
|
|
|
12
13
|
module.exports = function(options) {
|
|
13
14
|
let handle = network.ref();
|
|
@@ -26,9 +27,12 @@ module.exports = function(options) {
|
|
|
26
27
|
// Hack to accept any vacuum in the form of 'WORD.vacuum.*'
|
|
27
28
|
if (!d && device.model.match(/^\w+\.vacuum\./)) {
|
|
28
29
|
d = Vacuum;
|
|
29
|
-
if (device.model.startsWith('viomi')) {
|
|
30
|
+
if (device.model.startsWith('viomi.')) {
|
|
30
31
|
d = ViomiVacuum;
|
|
31
32
|
}
|
|
33
|
+
if (device.model.startsWith('dreame.')) {
|
|
34
|
+
d = DreameVacuum;
|
|
35
|
+
}
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
if(! d) {
|
|
@@ -0,0 +1,349 @@
|
|
|
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
|
+
/**
|
|
16
|
+
* Implementation of the interface used by the Dreame Vacuum. This device
|
|
17
|
+
* doesn't use properties via get_prop but instead has a get_properties.
|
|
18
|
+
*/
|
|
19
|
+
module.exports = class extends (
|
|
20
|
+
Vacuum.with(
|
|
21
|
+
MiioApi,
|
|
22
|
+
BatteryLevel,
|
|
23
|
+
AutonomousCharging,
|
|
24
|
+
AutonomousCleaning,
|
|
25
|
+
SpotCleaning,
|
|
26
|
+
AdjustableFanSpeed,
|
|
27
|
+
ChargingState
|
|
28
|
+
)
|
|
29
|
+
) {
|
|
30
|
+
static get type() {
|
|
31
|
+
return 'miio:vacuum';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
constructor(options) {
|
|
35
|
+
super(options);
|
|
36
|
+
|
|
37
|
+
this.defineProperty('device_fault', {
|
|
38
|
+
name: 'error',
|
|
39
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 3 : 2,
|
|
40
|
+
piid: this.miioModel === 'dreame.vacuum.mc1808' ? 1 : 2,
|
|
41
|
+
mapper: (e) => {
|
|
42
|
+
let message;
|
|
43
|
+
switch (e) {
|
|
44
|
+
// https://python-miio.readthedocs.io/en/latest/api/miio.integrations.dreame.vacuum.dreamevacuum_miot.html#miio.integrations.dreame.vacuum.dreamevacuum_miot.FaultStatus
|
|
45
|
+
case 0:
|
|
46
|
+
return null;
|
|
47
|
+
default:
|
|
48
|
+
message = 'Unknown error ' + e;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
code: e,
|
|
52
|
+
message,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
this.defineProperty('device_status', {
|
|
58
|
+
name: 'state',
|
|
59
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 3 : 2,
|
|
60
|
+
piid: this.miioModel === 'dreame.vacuum.mc1808' ? 2 : 1,
|
|
61
|
+
mapper: (s) => {
|
|
62
|
+
// https://python-miio.readthedocs.io/en/latest/api/miio.integrations.dreame.vacuum.dreamevacuum_miot.html#miio.integrations.dreame.vacuum.dreamevacuum_miot.DeviceStatus
|
|
63
|
+
switch (s) {
|
|
64
|
+
case 1:
|
|
65
|
+
return 'sweeping';
|
|
66
|
+
case 2:
|
|
67
|
+
return 'idle';
|
|
68
|
+
case 3:
|
|
69
|
+
return 'paused';
|
|
70
|
+
case 4:
|
|
71
|
+
return 'error';
|
|
72
|
+
case 5:
|
|
73
|
+
return 'returning';
|
|
74
|
+
case 6:
|
|
75
|
+
return 'charging';
|
|
76
|
+
case 7:
|
|
77
|
+
return 'mopping';
|
|
78
|
+
case 8:
|
|
79
|
+
return 'drying';
|
|
80
|
+
case 9:
|
|
81
|
+
return 'washing';
|
|
82
|
+
case 10:
|
|
83
|
+
return 'returning-washing';
|
|
84
|
+
case 11:
|
|
85
|
+
return 'building';
|
|
86
|
+
case 12:
|
|
87
|
+
return 'sweeping-and-mopping';
|
|
88
|
+
case 13:
|
|
89
|
+
return 'fully-charged';
|
|
90
|
+
case 14:
|
|
91
|
+
return 'updating';
|
|
92
|
+
}
|
|
93
|
+
return 'unknown-' + s;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Define the batteryLevel property for monitoring battery
|
|
98
|
+
this.defineProperty('battery_level', {
|
|
99
|
+
name: 'batteryLevel',
|
|
100
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 2 : 3,
|
|
101
|
+
piid: 1,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
this.defineProperty('charging_state', {
|
|
105
|
+
name: 'charging',
|
|
106
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 2 : 3,
|
|
107
|
+
piid: 2,
|
|
108
|
+
mapper: (s) => {
|
|
109
|
+
switch (s) {
|
|
110
|
+
case 1: // charging
|
|
111
|
+
return true;
|
|
112
|
+
case 2: // discharging
|
|
113
|
+
return false;
|
|
114
|
+
case 4: // charging2
|
|
115
|
+
return true;
|
|
116
|
+
case 5: // go-charging
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
this.defineProperty('cleaning_mode', {
|
|
123
|
+
name: 'fanSpeed',
|
|
124
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 18 : 4,
|
|
125
|
+
piid: this.miioModel === 'dreame.vacuum.mc1808' ? 6 : 4,
|
|
126
|
+
});
|
|
127
|
+
this.defineProperty('operating_mode', {
|
|
128
|
+
name: 'cleaningMode',
|
|
129
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 18 : 4,
|
|
130
|
+
piid: 1,
|
|
131
|
+
mapper: (v) => {
|
|
132
|
+
switch (v) {
|
|
133
|
+
case 1:
|
|
134
|
+
return 'paused';
|
|
135
|
+
case 2:
|
|
136
|
+
return 'cleaning';
|
|
137
|
+
case 3:
|
|
138
|
+
return 'returning';
|
|
139
|
+
case 6:
|
|
140
|
+
return 'charging';
|
|
141
|
+
case 13:
|
|
142
|
+
return 'manual-cleaning';
|
|
143
|
+
case 14:
|
|
144
|
+
return 'idle';
|
|
145
|
+
case 17:
|
|
146
|
+
return 'manual-paused';
|
|
147
|
+
case 19:
|
|
148
|
+
return 'zone-cleaning';
|
|
149
|
+
}
|
|
150
|
+
return 'unknown-' + v;
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
this.defineProperty('water_flow', {
|
|
155
|
+
name: 'waterBoxMode',
|
|
156
|
+
siid: 4,
|
|
157
|
+
piid: 5,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
this._monitorInterval = 60000;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
propertyUpdated(key, value, oldValue) {
|
|
164
|
+
if (key === 'state') {
|
|
165
|
+
// Update charging state
|
|
166
|
+
this.updateCharging(value === 'charging');
|
|
167
|
+
|
|
168
|
+
switch (value) {
|
|
169
|
+
case 'cleaning':
|
|
170
|
+
case 'spot-cleaning':
|
|
171
|
+
case 'zone-cleaning':
|
|
172
|
+
case 'room-cleaning':
|
|
173
|
+
// The vacuum is cleaning
|
|
174
|
+
this.updateCleaning(true);
|
|
175
|
+
break;
|
|
176
|
+
case 'paused':
|
|
177
|
+
// Cleaning has been paused, do nothing special
|
|
178
|
+
break;
|
|
179
|
+
case 'error':
|
|
180
|
+
// An error has occurred, rely on error mapping
|
|
181
|
+
this.updateError(this.property('error'));
|
|
182
|
+
break;
|
|
183
|
+
case 'charging-error':
|
|
184
|
+
// Charging error, trigger an error
|
|
185
|
+
this.updateError({
|
|
186
|
+
code: 'charging-error',
|
|
187
|
+
message: 'Error during charging',
|
|
188
|
+
});
|
|
189
|
+
break;
|
|
190
|
+
case 'charger-offline':
|
|
191
|
+
// Charger is offline, trigger an error
|
|
192
|
+
this.updateError({
|
|
193
|
+
code: 'charger-offline',
|
|
194
|
+
message: 'Charger is offline',
|
|
195
|
+
});
|
|
196
|
+
break;
|
|
197
|
+
default:
|
|
198
|
+
// The vacuum is not cleaning
|
|
199
|
+
this.updateCleaning(false);
|
|
200
|
+
break;
|
|
201
|
+
}
|
|
202
|
+
} else if (key === 'fanSpeed') {
|
|
203
|
+
this.updateFanSpeed(value);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
super.propertyUpdated(key, value, oldValue);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
getDeviceInfo() {
|
|
210
|
+
return this.call('miIO.info');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
async getSerialNumber() {
|
|
214
|
+
return 'unknown';
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getRoomMap() {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
getTimer() {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Start a cleaning session.
|
|
227
|
+
*/
|
|
228
|
+
activateCleaning() {
|
|
229
|
+
return this.call('action', {
|
|
230
|
+
did: 'start_clean',
|
|
231
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 3 : 4,
|
|
232
|
+
aiid: 1,
|
|
233
|
+
in: []
|
|
234
|
+
}, {
|
|
235
|
+
refresh: ['state'],
|
|
236
|
+
refreshDelay: 1000,
|
|
237
|
+
}).then(checkResult);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Pause the current cleaning session.
|
|
242
|
+
*/
|
|
243
|
+
pause() {
|
|
244
|
+
return this.deactivateCleaning();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Stop the current cleaning session.
|
|
249
|
+
*/
|
|
250
|
+
deactivateCleaning() {
|
|
251
|
+
return this.call('action', {
|
|
252
|
+
did: 'stop_clean',
|
|
253
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 3 : 4,
|
|
254
|
+
aiid: 2,
|
|
255
|
+
in: []
|
|
256
|
+
}, {
|
|
257
|
+
refresh: ['state'],
|
|
258
|
+
refreshDelay: 1000,
|
|
259
|
+
}).then(checkResult);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Stop the current cleaning session and return to charge.
|
|
264
|
+
*/
|
|
265
|
+
activateCharging() {
|
|
266
|
+
return (
|
|
267
|
+
this.pause()
|
|
268
|
+
.catch(() => this.deactivateCleaning())
|
|
269
|
+
// Wait 1 second
|
|
270
|
+
.then(() => new Promise((resolve) => setTimeout(resolve, 1000)))
|
|
271
|
+
.then(() =>
|
|
272
|
+
this.call('action', {
|
|
273
|
+
did: 'home',
|
|
274
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 2 : 3,
|
|
275
|
+
aiid: 1,
|
|
276
|
+
in: []
|
|
277
|
+
}, {
|
|
278
|
+
refresh: ['state'],
|
|
279
|
+
refreshDelay: 1000,
|
|
280
|
+
})
|
|
281
|
+
)
|
|
282
|
+
.then(checkResult)
|
|
283
|
+
);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Set the power of the fan. Usually 38, 60 or 77.
|
|
288
|
+
*/
|
|
289
|
+
changeFanSpeed(speed) {
|
|
290
|
+
return this.call('set_properties', [{
|
|
291
|
+
did: 'cleaning_mode',
|
|
292
|
+
siid: 18,
|
|
293
|
+
piid: 6,
|
|
294
|
+
value: speed,
|
|
295
|
+
}], {
|
|
296
|
+
refresh: ['fanSpeed'],
|
|
297
|
+
}).then(checkResult);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
setWaterBoxMode(mode) {
|
|
301
|
+
// From https://github.com/marcelrv/XiaomiRobotVacuumProtocol/blob/master/water_box_custom_mode.md
|
|
302
|
+
return this.call('set_properties', [{
|
|
303
|
+
did: 'water_flow',
|
|
304
|
+
siid: 4,
|
|
305
|
+
piid: 5,
|
|
306
|
+
value: mode,
|
|
307
|
+
}], {
|
|
308
|
+
refresh: ['waterBoxMode'],
|
|
309
|
+
}).then(checkResult);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Activate the find function, will make the device give off a sound.
|
|
314
|
+
*/
|
|
315
|
+
find() {
|
|
316
|
+
return this.call('action', {
|
|
317
|
+
did: 'locate',
|
|
318
|
+
siid: this.miioModel === 'dreame.vacuum.mc1808' ? 17 : 7,
|
|
319
|
+
aiid: 1,
|
|
320
|
+
in: []
|
|
321
|
+
}).then(() => null);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
loadProperties(props) {
|
|
325
|
+
// We override loadProperties to use get_properties
|
|
326
|
+
props = props.map((key) => this._reversePropertyDefinitions[key] || key);
|
|
327
|
+
|
|
328
|
+
const properties = props.map((prop) => {
|
|
329
|
+
const definition = this._propertyDefinitions[prop];
|
|
330
|
+
if (definition) {
|
|
331
|
+
return {
|
|
332
|
+
did: prop,
|
|
333
|
+
siid: definition.siid,
|
|
334
|
+
piid: definition.piid,
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}).filter(Boolean);
|
|
338
|
+
|
|
339
|
+
return this.call('get_properties', properties)
|
|
340
|
+
.then((result) => {
|
|
341
|
+
const mapped = {};
|
|
342
|
+
props.forEach((prop) => {
|
|
343
|
+
let value = result[prop];
|
|
344
|
+
this._pushProperty(mapped, prop, value);
|
|
345
|
+
});
|
|
346
|
+
return mapped;
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
};
|
|
@@ -8,9 +8,9 @@ const {
|
|
|
8
8
|
SpotCleaning,
|
|
9
9
|
} = require('abstract-things/climate');
|
|
10
10
|
|
|
11
|
-
const MiioApi = require('
|
|
12
|
-
const BatteryLevel = require('
|
|
13
|
-
const checkResult = require('
|
|
11
|
+
const MiioApi = require('../../device');
|
|
12
|
+
const BatteryLevel = require('../capabilities/battery-level');
|
|
13
|
+
const checkResult = require('../../checkResult');
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Implementation of the interface used by the Mi Robot Vacuum. This device
|
|
@@ -197,7 +197,22 @@ module.exports = class extends (
|
|
|
197
197
|
this.defineProperty('fan_power', {
|
|
198
198
|
name: 'fanSpeed',
|
|
199
199
|
});
|
|
200
|
-
this.defineProperty('in_cleaning'
|
|
200
|
+
this.defineProperty('in_cleaning', {
|
|
201
|
+
name: 'cleaningMode',
|
|
202
|
+
mapper: (v) => {
|
|
203
|
+
switch (v) {
|
|
204
|
+
case 0:
|
|
205
|
+
return 'idle';
|
|
206
|
+
case 1:
|
|
207
|
+
return 'cleaning';
|
|
208
|
+
case 2:
|
|
209
|
+
return 'zone-cleaning';
|
|
210
|
+
case 3:
|
|
211
|
+
return 'room-cleaning';
|
|
212
|
+
}
|
|
213
|
+
return 'unknown-' + v;
|
|
214
|
+
},
|
|
215
|
+
});
|
|
201
216
|
|
|
202
217
|
this.defineProperty('in_returning');
|
|
203
218
|
|
|
@@ -8,9 +8,9 @@ const {
|
|
|
8
8
|
SpotCleaning,
|
|
9
9
|
} = require('abstract-things/climate');
|
|
10
10
|
|
|
11
|
-
const MiioApi = require('
|
|
12
|
-
const BatteryLevel = require('
|
|
13
|
-
const checkResult = require('
|
|
11
|
+
const MiioApi = require('../../device');
|
|
12
|
+
const BatteryLevel = require('../capabilities/battery-level');
|
|
13
|
+
const checkResult = require('../../checkResult');
|
|
14
14
|
|
|
15
15
|
module.exports = class extends (
|
|
16
16
|
Vacuum.with(
|
package/lib/models.js
CHANGED
|
@@ -7,9 +7,9 @@ const AirMonitor = require('./devices/air-monitor');
|
|
|
7
7
|
const AirPurifier = require('./devices/air-purifier');
|
|
8
8
|
const Gateway = require('./devices/gateway');
|
|
9
9
|
|
|
10
|
-
const Vacuum = require('./devices/vacuum');
|
|
11
|
-
const MijiaVacuum = require('./devices/mijiavacuum');
|
|
12
|
-
const ViomiVacuum = require('./devices/viomivacuum');
|
|
10
|
+
const Vacuum = require('./devices/vacuums/vacuum');
|
|
11
|
+
const MijiaVacuum = require('./devices/vacuums/mijiavacuum');
|
|
12
|
+
const ViomiVacuum = require('./devices/vacuums/viomivacuum');
|
|
13
13
|
|
|
14
14
|
const PowerPlug = require('./devices/power-plug');
|
|
15
15
|
const PowerStrip = require('./devices/power-strip');
|
|
@@ -53,7 +53,6 @@ module.exports = {
|
|
|
53
53
|
|
|
54
54
|
'roborock.vacuum.m1s': MijiaVacuum,
|
|
55
55
|
|
|
56
|
-
'dreame.vacuum.mc1808': ViomiVacuum,
|
|
57
56
|
'viomi.vacuum.v7': ViomiVacuum,
|
|
58
57
|
'viomi.vacuum.v8': ViomiVacuum,
|
|
59
58
|
|
package/package.json
CHANGED