@george.talusan/eufy-robovac-js 0.0.8 → 0.0.10

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/README.md ADDED
@@ -0,0 +1,52 @@
1
+ ## eufy-robovac-js
2
+
3
+ Yet another NodeJS library to control a Eufy RoboVac.
4
+
5
+ ## Install
6
+
7
+ npm install @george.talusan/eufy-robovac-js
8
+
9
+ ## Configuration
10
+
11
+ See https://github.com/gtalusan/eufy-device-id-js for obtaining your Eufy Robovac's device ID and local key.
12
+
13
+ ## How to use
14
+
15
+ ### Create an instance of RoboVac
16
+
17
+ ```
18
+ import { RoboVac } from '@george.talusan/eufy-robovac-js';
19
+
20
+ const vac = new RoboVac({ ip: 'some ip', deviceId: 'your device id', localKey: 'your local key' });
21
+ ```
22
+
23
+ ### Wire up event listeners
24
+
25
+ ```
26
+ vac.on('error', error => console.log(error)); // listen for errors
27
+ vac.on('tuya.connected', fn); // reflected event from TuyAPI
28
+ vac.on('tuya.disconnected', fn); // reflected event from TuyAPI
29
+ vac.on('tuya.data', data => console.log(data)); // reflected event from TuyAPI
30
+ vac.on('tuya.dp-refresh', data => console.log(data)); // reflected event from TuyAPI
31
+
32
+ vac.on('event', ({ command, value }) => console.log(command, value)); // human readable dp-refresh/data events
33
+ vac.on('alert', ({ consumable, duration }) => console.log(consumable, duration)); // alerts when consumables should be replaced
34
+ ```
35
+
36
+ ### Commands
37
+
38
+ Refer to the source code for various functionality. Typical setters/commands are async. Use await appropriately.
39
+
40
+ All getters retrieve values from the output of dp-refresh/data events and are hence cached. Thus, `set(X) == Y` does not mean necessarily `get(X) == Y`. In other words, do not assume setters are idempotent.
41
+
42
+ ## Other projects using this library
43
+
44
+ * Homebridge: https://github.com/gtalusan/homebridge-eufy-robovac
45
+ * Node-RED: https://github.com/gtalusan/node-red-contrib-eufy-robovac
46
+
47
+ ## Credits
48
+
49
+ Inspired by various projects.
50
+
51
+ * https://github.com/apexad/eufy-robovac
52
+ * https://github.com/bmccluskey/robovac
@@ -0,0 +1,8 @@
1
+ import globals from "globals";
2
+ import pluginJs from "@eslint/js";
3
+
4
+ export default [
5
+ {files: ["**/*.js"], languageOptions: {sourceType: "commonjs"}},
6
+ {languageOptions: { globals: globals.browser }},
7
+ pluginJs.configs.recommended,
8
+ ];
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',
@@ -104,7 +105,7 @@ class RoboVac extends EventEmitter
104
105
 
105
106
  Object.keys(data.dps).forEach(command => {
106
107
  const value = data.dps[command];
107
- if (command === COMMAND.workMode) {
108
+ if (command === COMMAND.playPause) {
108
109
  this.emit('event', { command: 'playPause', value });
109
110
  }
110
111
  else if (command === COMMAND.workMode) {
@@ -165,7 +166,7 @@ class RoboVac extends EventEmitter
165
166
  this.emit('event', { command: 'multimaps', value: this.multimaps() });
166
167
  }
167
168
  else if (command === COMMAND.rooms) {
168
- this.emit('event', { command: 'rooms', this.rooms() });
169
+ this.emit('event', { command: 'rooms', value: this.rooms() });
169
170
  }
170
171
  else if (command === COMMAND.voice) {
171
172
  this.emit('event', { command: 'voice', value: this.voice() });
@@ -231,7 +232,7 @@ class RoboVac extends EventEmitter
231
232
  debug('no data points available yet');
232
233
  return 'unknown';
233
234
  }
234
- if (!this.dps.hasOwnProperty(COMMAND.workMode)) {
235
+ if (!Object.hasOwn(this.dps, COMMAND.workMode)) {
235
236
  throw new Error('RoboVac does not support this command');
236
237
  }
237
238
  return this.dps[COMMAND.workMode];
@@ -242,7 +243,7 @@ class RoboVac extends EventEmitter
242
243
  debug('no data points available yet');
243
244
  return 'unknown';
244
245
  }
245
- if (!this.dps.hasOwnProperty(COMMAND.activity)) {
246
+ if (!Object.hasOwn(this.dps, COMMAND.activity)) {
246
247
  throw new Error('RoboVac does not support this command');
247
248
  }
248
249
  return this.dps[COMMAND.activity];
@@ -253,7 +254,7 @@ class RoboVac extends EventEmitter
253
254
  debug('no data points available yet');
254
255
  return -1;
255
256
  }
256
- if (!this.dps.hasOwnProperty(COMMAND.battery)) {
257
+ if (!Object.hasOwn(this.dps, COMMAND.battery)) {
257
258
  throw new Error('RoboVac does not support this command');
258
259
  }
259
260
  return this.dps[COMMAND.battery];
@@ -275,7 +276,7 @@ class RoboVac extends EventEmitter
275
276
  debug('no data points available yet');
276
277
  return -1;
277
278
  }
278
- if (!this.dps.hasOwnProperty(COMMAND.cleaningRuntime)) {
279
+ if (!Object.hasOwn(this.dps, COMMAND.cleaningRuntime)) {
279
280
  throw new Error('RoboVac does not support this command');
280
281
  }
281
282
  return this.dps[COMMAND.cleaningRuntime];
@@ -286,7 +287,7 @@ class RoboVac extends EventEmitter
286
287
  debug('no data points available yet');
287
288
  return -1;
288
289
  }
289
- if (!this.dps.hasOwnProperty(COMMAND.cleaningCoverage)) {
290
+ if (!Object.hasOwn(this.dps, COMMAND.cleaningCoverage)) {
290
291
  throw new Error('RoboVac does not support this command');
291
292
  }
292
293
  return this.dps[COMMAND.cleaningCoverage];
@@ -297,7 +298,7 @@ class RoboVac extends EventEmitter
297
298
  debug('no data points available yet');
298
299
  return ''
299
300
  }
300
- if (!this.dps.hasOwnProperty(COMMAND.consumables)) {
301
+ if (!Object.hasOwn(this.dps, COMMAND.consumables)) {
301
302
  throw new Error('RoboVac does not support this command');
302
303
  }
303
304
  const json = Buffer.from(this.dps[COMMAND.consumables], 'base64');
@@ -309,7 +310,7 @@ class RoboVac extends EventEmitter
309
310
  debug('no data points available yet');
310
311
  return ''
311
312
  }
312
- if (!this.dps.hasOwnProperty(COMMAND.status)) {
313
+ if (!Object.hasOwn(this.dps, COMMAND.status)) {
313
314
  throw new Error('RoboVac does not support this command');
314
315
  }
315
316
  const json = Buffer.from(this.dps[COMMAND.status], 'base64');
@@ -352,7 +353,7 @@ class RoboVac extends EventEmitter
352
353
  if (!this.dps) {
353
354
  throw new Error('no data points available yet');
354
355
  }
355
- if (!this.dps.hasOwnProperty(COMMAND.findMyRobot)) {
356
+ if (!Object.hasOwn(this.dps, COMMAND.findMyRobot)) {
356
357
  throw new Error('RoboVac does not support this command');
357
358
  }
358
359
  if (this.docked()) {
@@ -372,7 +373,7 @@ class RoboVac extends EventEmitter
372
373
  if (this.docked()) {
373
374
  throw new Error('RoboVac is already home');
374
375
  }
375
- if (!this.dps.hasOwnProperty(COMMAND.goHome)) {
376
+ if (!Object.hasOwn(this.dps, COMMAND.goHome)) {
376
377
  throw new Error('RoboVac does not support this command');
377
378
  }
378
379
  const b = this.dps[COMMAND.goHome];
@@ -386,7 +387,7 @@ class RoboVac extends EventEmitter
386
387
  if (!this.dps) {
387
388
  throw new Error('no data points available yet');
388
389
  }
389
- if (!this.dps.hasOwnProperty(COMMAND.goHome)) {
390
+ if (!Object.hasOwn(this.dps, COMMAND.goHome)) {
390
391
  throw new Error('RoboVac does not support this command');
391
392
  }
392
393
  return this.dps[COMMAND.goHome];
@@ -396,17 +397,17 @@ class RoboVac extends EventEmitter
396
397
  if (!this.dps) {
397
398
  throw new Error('no data points available yet');
398
399
  }
399
- if (!this.dps.hasOwnProperty(COMMAND.volume)) {
400
+ if (!Object.hasOwn(this.dps, COMMAND.volume)) {
400
401
  throw new Error('RoboVac does not support this command');
401
402
  }
402
403
  return this.dps[COMMAND.volume];
403
404
  }
404
405
 
405
406
  async setVolume(value) {
406
- if (!this.dps.hasOwnProperty(COMMAND.volume)) {
407
+ if (!Object.hasOwn(this.dps, COMMAND.volume)) {
407
408
  throw new Error('RoboVac does not support this command');
408
409
  }
409
- if (value < 0 || volume > 100) {
410
+ if (value < 0 || value > 100) {
410
411
  throw new Error('expecting value between 0 to 100');
411
412
  }
412
413
  return this.set({ [COMMAND.volume]: value });
@@ -416,7 +417,7 @@ class RoboVac extends EventEmitter
416
417
  if (!this.dps) {
417
418
  throw new Error('no data points available yet');
418
419
  }
419
- if (!this.dps.hasOwnProperty(COMMAND.multimaps)) {
420
+ if (!Object.hasOwn(this.dps, COMMAND.multimaps)) {
420
421
  throw new Error('RoboVac does not support this command');
421
422
  }
422
423
  const json = Buffer.from(this.dps[COMMAND.multimaps], 'base64');
@@ -427,7 +428,7 @@ class RoboVac extends EventEmitter
427
428
  if (!this.dps) {
428
429
  throw new Error('no data points available yet');
429
430
  }
430
- if (!this.dps.hasOwnProperty(COMMAND.rooms)) {
431
+ if (!Object.hasOwn(this.dps, COMMAND.rooms)) {
431
432
  throw new Error('RoboVac does not support this command');
432
433
  }
433
434
  const json = Buffer.from(this.dps[COMMAND.rooms], 'base64');
@@ -438,7 +439,7 @@ class RoboVac extends EventEmitter
438
439
  if (!this.dps) {
439
440
  throw new Error('no data points available yet');
440
441
  }
441
- if (!this.dps.hasOwnProperty(COMMAND.voice)) {
442
+ if (!Object.hasOwn(this.dps, COMMAND.voice)) {
442
443
  throw new Error('RoboVac does not support this command');
443
444
  }
444
445
  const json = Buffer.from(this.dps[COMMAND.voice], 'base64');
@@ -449,7 +450,7 @@ class RoboVac extends EventEmitter
449
450
  if (!this.dps) {
450
451
  throw new Error('no data points available yet');
451
452
  }
452
- if (!this.dps.hasOwnProperty(COMMAND.hello)) {
453
+ if (!Object.hasOwn(this.dps, COMMAND.hello)) {
453
454
  throw new Error('RoboVac does not support this command');
454
455
  }
455
456
  const json = Buffer.from(this.dps[COMMAND.hello], 'base64');
@@ -460,14 +461,14 @@ class RoboVac extends EventEmitter
460
461
  if (!this.dps) {
461
462
  throw new Error('no data points available yet');
462
463
  }
463
- if (!this.dps.hasOwnProperty(COMMAND.autoReturn)) {
464
+ if (!Object.hasOwn(this.dps, COMMAND.autoReturn)) {
464
465
  throw new Error('RoboVac does not support this command');
465
466
  }
466
467
  return this.dps[COMMAND.autoReturn];
467
468
  }
468
469
 
469
470
  async setAutoReturn(flag) {
470
- if (!this.dps.hasOwnProperty(COMMAND.autoReturn)) {
471
+ if (!Object.hasOwn(this.dps, COMMAND.autoReturn)) {
471
472
  throw new Error('RoboVac does not support this command');
472
473
  }
473
474
  return this.set({ [COMMAND.autoReturn]: flag });
package/package.json CHANGED
@@ -1,20 +1,25 @@
1
1
  {
2
2
  "name": "@george.talusan/eufy-robovac-js",
3
- "version": "0.0.8",
4
- "main": "index.js",
3
+ "version": "0.0.10",
4
+ "main": "./lib/RoboVac.js",
5
5
  "scripts": {
6
+ "lint": "eslint lib",
7
+ "prepack": "npm run lint",
6
8
  "test": "echo \"Error: no test specified\" && exit 1"
7
9
  },
8
10
  "author": "",
9
11
  "license": "ISC",
10
- "main": "./lib/RoboVac.js",
11
12
  "dependencies": {
12
13
  "debug": "^4.3.5",
13
- "tuyapi": "github:codetheweb/tuyapi"
14
+ "tuyapi": "^7.7.1"
14
15
  },
15
16
  "directories": {
16
17
  "lib": "lib"
17
18
  },
18
- "devDependencies": {},
19
- "description": ""
19
+ "description": "",
20
+ "devDependencies": {
21
+ "@eslint/js": "^9.9.1",
22
+ "eslint": "^9.9.1",
23
+ "globals": "^15.9.0"
24
+ }
20
25
  }