@george.talusan/eufy-robovac-js 0.0.7 → 0.0.9
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/eslint.config.mjs +8 -0
- package/lib/RoboVac.js +52 -19
- package/package.json +9 -5
package/lib/RoboVac.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const debug = require('debug');
|
|
2
2
|
const api = require('tuyapi');
|
|
3
3
|
const { EventEmitter } = require('events');
|
|
4
|
+
const { Buffer } = require('buffer');
|
|
4
5
|
|
|
5
6
|
const COMMAND = {
|
|
6
7
|
playPause: '2',
|
|
@@ -15,6 +16,7 @@ const COMMAND = {
|
|
|
15
16
|
volume: '111',
|
|
16
17
|
consumables: '116',
|
|
17
18
|
multimaps: '117',
|
|
19
|
+
rooms: '124',
|
|
18
20
|
voice: '125',
|
|
19
21
|
hello: '126',
|
|
20
22
|
autoReturn: '135',
|
|
@@ -103,7 +105,7 @@ class RoboVac extends EventEmitter
|
|
|
103
105
|
|
|
104
106
|
Object.keys(data.dps).forEach(command => {
|
|
105
107
|
const value = data.dps[command];
|
|
106
|
-
if (command === COMMAND.
|
|
108
|
+
if (command === COMMAND.playPause) {
|
|
107
109
|
this.emit('event', { command: 'playPause', value });
|
|
108
110
|
}
|
|
109
111
|
else if (command === COMMAND.workMode) {
|
|
@@ -163,6 +165,9 @@ class RoboVac extends EventEmitter
|
|
|
163
165
|
else if (command === COMMAND.multimaps) {
|
|
164
166
|
this.emit('event', { command: 'multimaps', value: this.multimaps() });
|
|
165
167
|
}
|
|
168
|
+
else if (command === COMMAND.rooms) {
|
|
169
|
+
this.emit('event', { command: 'rooms', value: this.rooms() });
|
|
170
|
+
}
|
|
166
171
|
else if (command === COMMAND.voice) {
|
|
167
172
|
this.emit('event', { command: 'voice', value: this.voice() });
|
|
168
173
|
}
|
|
@@ -189,6 +194,23 @@ class RoboVac extends EventEmitter
|
|
|
189
194
|
return this.set({ [COMMAND.workMode]: 'auto' });
|
|
190
195
|
}
|
|
191
196
|
|
|
197
|
+
async cleanRooms(rooms) {
|
|
198
|
+
if (!this.dps) {
|
|
199
|
+
debug('no data points available yet');
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
const fn = {
|
|
203
|
+
method: 'selectRoomsClean',
|
|
204
|
+
data: {
|
|
205
|
+
roomIds: rooms || [ 1 ],
|
|
206
|
+
cleanTimes: 1
|
|
207
|
+
},
|
|
208
|
+
timestamp: Date.now()
|
|
209
|
+
};
|
|
210
|
+
const value = Buffer.from(JSON.stringify(fn)).toString('base64');
|
|
211
|
+
return this.set({ [COMMAND.rooms]: value });
|
|
212
|
+
}
|
|
213
|
+
|
|
192
214
|
async resume() {
|
|
193
215
|
if (!this.dps) {
|
|
194
216
|
debug('no data points available yet');
|
|
@@ -210,7 +232,7 @@ class RoboVac extends EventEmitter
|
|
|
210
232
|
debug('no data points available yet');
|
|
211
233
|
return 'unknown';
|
|
212
234
|
}
|
|
213
|
-
if (!this.dps
|
|
235
|
+
if (!Object.hasOwn(this.dps, COMMAND.workMode)) {
|
|
214
236
|
throw new Error('RoboVac does not support this command');
|
|
215
237
|
}
|
|
216
238
|
return this.dps[COMMAND.workMode];
|
|
@@ -221,7 +243,7 @@ class RoboVac extends EventEmitter
|
|
|
221
243
|
debug('no data points available yet');
|
|
222
244
|
return 'unknown';
|
|
223
245
|
}
|
|
224
|
-
if (!this.dps
|
|
246
|
+
if (!Object.hasOwn(this.dps, COMMAND.activity)) {
|
|
225
247
|
throw new Error('RoboVac does not support this command');
|
|
226
248
|
}
|
|
227
249
|
return this.dps[COMMAND.activity];
|
|
@@ -232,7 +254,7 @@ class RoboVac extends EventEmitter
|
|
|
232
254
|
debug('no data points available yet');
|
|
233
255
|
return -1;
|
|
234
256
|
}
|
|
235
|
-
if (!this.dps
|
|
257
|
+
if (!Object.hasOwn(this.dps, COMMAND.battery)) {
|
|
236
258
|
throw new Error('RoboVac does not support this command');
|
|
237
259
|
}
|
|
238
260
|
return this.dps[COMMAND.battery];
|
|
@@ -254,7 +276,7 @@ class RoboVac extends EventEmitter
|
|
|
254
276
|
debug('no data points available yet');
|
|
255
277
|
return -1;
|
|
256
278
|
}
|
|
257
|
-
if (!this.dps
|
|
279
|
+
if (!Object.hasOwn(this.dps, COMMAND.cleaningRuntime)) {
|
|
258
280
|
throw new Error('RoboVac does not support this command');
|
|
259
281
|
}
|
|
260
282
|
return this.dps[COMMAND.cleaningRuntime];
|
|
@@ -265,7 +287,7 @@ class RoboVac extends EventEmitter
|
|
|
265
287
|
debug('no data points available yet');
|
|
266
288
|
return -1;
|
|
267
289
|
}
|
|
268
|
-
if (!this.dps
|
|
290
|
+
if (!Object.hasOwn(this.dps, COMMAND.cleaningCoverage)) {
|
|
269
291
|
throw new Error('RoboVac does not support this command');
|
|
270
292
|
}
|
|
271
293
|
return this.dps[COMMAND.cleaningCoverage];
|
|
@@ -276,7 +298,7 @@ class RoboVac extends EventEmitter
|
|
|
276
298
|
debug('no data points available yet');
|
|
277
299
|
return ''
|
|
278
300
|
}
|
|
279
|
-
if (!this.dps
|
|
301
|
+
if (!Object.hasOwn(this.dps, COMMAND.consumables)) {
|
|
280
302
|
throw new Error('RoboVac does not support this command');
|
|
281
303
|
}
|
|
282
304
|
const json = Buffer.from(this.dps[COMMAND.consumables], 'base64');
|
|
@@ -288,7 +310,7 @@ class RoboVac extends EventEmitter
|
|
|
288
310
|
debug('no data points available yet');
|
|
289
311
|
return ''
|
|
290
312
|
}
|
|
291
|
-
if (!this.dps
|
|
313
|
+
if (!Object.hasOwn(this.dps, COMMAND.status)) {
|
|
292
314
|
throw new Error('RoboVac does not support this command');
|
|
293
315
|
}
|
|
294
316
|
const json = Buffer.from(this.dps[COMMAND.status], 'base64');
|
|
@@ -331,7 +353,7 @@ class RoboVac extends EventEmitter
|
|
|
331
353
|
if (!this.dps) {
|
|
332
354
|
throw new Error('no data points available yet');
|
|
333
355
|
}
|
|
334
|
-
if (!this.dps
|
|
356
|
+
if (!Object.hasOwn(this.dps, COMMAND.findMyRobot)) {
|
|
335
357
|
throw new Error('RoboVac does not support this command');
|
|
336
358
|
}
|
|
337
359
|
if (this.docked()) {
|
|
@@ -351,7 +373,7 @@ class RoboVac extends EventEmitter
|
|
|
351
373
|
if (this.docked()) {
|
|
352
374
|
throw new Error('RoboVac is already home');
|
|
353
375
|
}
|
|
354
|
-
if (!this.dps
|
|
376
|
+
if (!Object.hasOwn(this.dps, COMMAND.goHome)) {
|
|
355
377
|
throw new Error('RoboVac does not support this command');
|
|
356
378
|
}
|
|
357
379
|
const b = this.dps[COMMAND.goHome];
|
|
@@ -365,7 +387,7 @@ class RoboVac extends EventEmitter
|
|
|
365
387
|
if (!this.dps) {
|
|
366
388
|
throw new Error('no data points available yet');
|
|
367
389
|
}
|
|
368
|
-
if (!this.dps
|
|
390
|
+
if (!Object.hasOwn(this.dps, COMMAND.goHome)) {
|
|
369
391
|
throw new Error('RoboVac does not support this command');
|
|
370
392
|
}
|
|
371
393
|
return this.dps[COMMAND.goHome];
|
|
@@ -375,17 +397,17 @@ class RoboVac extends EventEmitter
|
|
|
375
397
|
if (!this.dps) {
|
|
376
398
|
throw new Error('no data points available yet');
|
|
377
399
|
}
|
|
378
|
-
if (!this.dps
|
|
400
|
+
if (!Object.hasOwn(this.dps, COMMAND.volume)) {
|
|
379
401
|
throw new Error('RoboVac does not support this command');
|
|
380
402
|
}
|
|
381
403
|
return this.dps[COMMAND.volume];
|
|
382
404
|
}
|
|
383
405
|
|
|
384
406
|
async setVolume(value) {
|
|
385
|
-
if (!this.dps
|
|
407
|
+
if (!Object.hasOwn(this.dps, COMMAND.volume)) {
|
|
386
408
|
throw new Error('RoboVac does not support this command');
|
|
387
409
|
}
|
|
388
|
-
if (value < 0 ||
|
|
410
|
+
if (value < 0 || value > 100) {
|
|
389
411
|
throw new Error('expecting value between 0 to 100');
|
|
390
412
|
}
|
|
391
413
|
return this.set({ [COMMAND.volume]: value });
|
|
@@ -395,18 +417,29 @@ class RoboVac extends EventEmitter
|
|
|
395
417
|
if (!this.dps) {
|
|
396
418
|
throw new Error('no data points available yet');
|
|
397
419
|
}
|
|
398
|
-
if (!this.dps
|
|
420
|
+
if (!Object.hasOwn(this.dps, COMMAND.multimaps)) {
|
|
399
421
|
throw new Error('RoboVac does not support this command');
|
|
400
422
|
}
|
|
401
423
|
const json = Buffer.from(this.dps[COMMAND.multimaps], 'base64');
|
|
402
424
|
return JSON.parse(json);
|
|
403
425
|
}
|
|
404
426
|
|
|
427
|
+
rooms() {
|
|
428
|
+
if (!this.dps) {
|
|
429
|
+
throw new Error('no data points available yet');
|
|
430
|
+
}
|
|
431
|
+
if (!Object.hasOwn(this.dps, COMMAND.rooms)) {
|
|
432
|
+
throw new Error('RoboVac does not support this command');
|
|
433
|
+
}
|
|
434
|
+
const json = Buffer.from(this.dps[COMMAND.rooms], 'base64');
|
|
435
|
+
return JSON.parse(json);
|
|
436
|
+
}
|
|
437
|
+
|
|
405
438
|
voice() {
|
|
406
439
|
if (!this.dps) {
|
|
407
440
|
throw new Error('no data points available yet');
|
|
408
441
|
}
|
|
409
|
-
if (!this.dps
|
|
442
|
+
if (!Object.hasOwn(this.dps, COMMAND.voice)) {
|
|
410
443
|
throw new Error('RoboVac does not support this command');
|
|
411
444
|
}
|
|
412
445
|
const json = Buffer.from(this.dps[COMMAND.voice], 'base64');
|
|
@@ -417,7 +450,7 @@ class RoboVac extends EventEmitter
|
|
|
417
450
|
if (!this.dps) {
|
|
418
451
|
throw new Error('no data points available yet');
|
|
419
452
|
}
|
|
420
|
-
if (!this.dps
|
|
453
|
+
if (!Object.hasOwn(this.dps, COMMAND.hello)) {
|
|
421
454
|
throw new Error('RoboVac does not support this command');
|
|
422
455
|
}
|
|
423
456
|
const json = Buffer.from(this.dps[COMMAND.hello], 'base64');
|
|
@@ -428,14 +461,14 @@ class RoboVac extends EventEmitter
|
|
|
428
461
|
if (!this.dps) {
|
|
429
462
|
throw new Error('no data points available yet');
|
|
430
463
|
}
|
|
431
|
-
if (!this.dps
|
|
464
|
+
if (!Object.hasOwn(this.dps, COMMAND.autoReturn)) {
|
|
432
465
|
throw new Error('RoboVac does not support this command');
|
|
433
466
|
}
|
|
434
467
|
return this.dps[COMMAND.autoReturn];
|
|
435
468
|
}
|
|
436
469
|
|
|
437
470
|
async setAutoReturn(flag) {
|
|
438
|
-
if (!this.dps
|
|
471
|
+
if (!Object.hasOwn(this.dps, COMMAND.autoReturn)) {
|
|
439
472
|
throw new Error('RoboVac does not support this command');
|
|
440
473
|
}
|
|
441
474
|
return this.set({ [COMMAND.autoReturn]: flag });
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@george.talusan/eufy-robovac-js",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "0.0.9",
|
|
4
|
+
"main": "./lib/RoboVac.js",
|
|
5
5
|
"scripts": {
|
|
6
|
+
"lint": "eslint lib",
|
|
6
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
8
|
},
|
|
8
9
|
"author": "",
|
|
9
10
|
"license": "ISC",
|
|
10
|
-
"main": "./lib/RoboVac.js",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"debug": "^4.3.5",
|
|
13
13
|
"tuyapi": "github:codetheweb/tuyapi"
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
"directories": {
|
|
16
16
|
"lib": "lib"
|
|
17
17
|
},
|
|
18
|
-
"
|
|
19
|
-
"
|
|
18
|
+
"description": "",
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@eslint/js": "^9.9.1",
|
|
21
|
+
"eslint": "^9.9.1",
|
|
22
|
+
"globals": "^15.9.0"
|
|
23
|
+
}
|
|
20
24
|
}
|