@george.talusan/eufy-robovac-js 0.0.2
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/.github/workflows/npm-publish.yml +33 -0
- package/lib/RoboVac.js +403 -0
- package/package.json +20 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created
|
|
2
|
+
# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: publish eufy-robovac-js
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: actions/setup-node@v4
|
|
16
|
+
with:
|
|
17
|
+
node-version: 20
|
|
18
|
+
- run: npm ci
|
|
19
|
+
- run: npm test
|
|
20
|
+
|
|
21
|
+
publish-npm:
|
|
22
|
+
needs: build
|
|
23
|
+
runs-on: ubuntu-latest
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v4
|
|
26
|
+
- uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: 20
|
|
29
|
+
registry-url: https://registry.npmjs.org/
|
|
30
|
+
- run: npm ci
|
|
31
|
+
- run: npm publish
|
|
32
|
+
env:
|
|
33
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/lib/RoboVac.js
ADDED
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
const ping = require('net-ping').createSession({ retries: 10 });
|
|
2
|
+
const debug = require('debug');
|
|
3
|
+
const api = require('tuyapi');
|
|
4
|
+
const { EventEmitter } = require('events');
|
|
5
|
+
|
|
6
|
+
const COMMAND = {
|
|
7
|
+
activity: '15',
|
|
8
|
+
goHome: '101',
|
|
9
|
+
findMyRobot: '103',
|
|
10
|
+
battery: '104',
|
|
11
|
+
error: '106',
|
|
12
|
+
cleaningRuntime: '109',
|
|
13
|
+
cleaningCoverage: '110',
|
|
14
|
+
volume: '111',
|
|
15
|
+
consumables: '116',
|
|
16
|
+
multimaps: '117',
|
|
17
|
+
voice: '125',
|
|
18
|
+
hello: '126',
|
|
19
|
+
autoReturn: '135',
|
|
20
|
+
status: '142',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const ERRORS = {
|
|
24
|
+
0: 'no error',
|
|
25
|
+
1: 'front bumper stuck',
|
|
26
|
+
2: 'wheel stuck',
|
|
27
|
+
3: 'side brush',
|
|
28
|
+
4: 'rolling brush bar stuck',
|
|
29
|
+
5: 'device trapped',
|
|
30
|
+
6: 'device trapped',
|
|
31
|
+
7: 'wheel suspended',
|
|
32
|
+
8: 'low battery',
|
|
33
|
+
9: 'magnetic boundary',
|
|
34
|
+
12: 'right wall sensor',
|
|
35
|
+
13: 'device tilted',
|
|
36
|
+
14: 'insert dust collector',
|
|
37
|
+
17: 'restricted area detected',
|
|
38
|
+
18: 'laser cover stuck',
|
|
39
|
+
19: 'laser sensor stuck',
|
|
40
|
+
20: 'laser sensor blocked',
|
|
41
|
+
21: 'base blocked',
|
|
42
|
+
S1: 'battery',
|
|
43
|
+
S2: 'wheel module',
|
|
44
|
+
S3: 'side brush',
|
|
45
|
+
S4: 'suction fan',
|
|
46
|
+
S5: 'rolling brush',
|
|
47
|
+
S8: 'path tracking sensor',
|
|
48
|
+
Wheel_stuck: 'wheel stuck',
|
|
49
|
+
R_brush_stuck: 'rolling brush stuck',
|
|
50
|
+
Crash_bar_stuck: 'front bumper stuck',
|
|
51
|
+
sensor_dirty: 'sensor dirty',
|
|
52
|
+
N_enough_pow: 'low battery',
|
|
53
|
+
Stuck_5_min: 'device trapped',
|
|
54
|
+
Fan_stuck: 'fan stuck',
|
|
55
|
+
S_brush_stuck: 'side brush stuck',
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
class RoboVac extends EventEmitter
|
|
59
|
+
{
|
|
60
|
+
dps = {};
|
|
61
|
+
|
|
62
|
+
constructor({ ip, deviceId, localKey }) {
|
|
63
|
+
super();
|
|
64
|
+
this.ip = ip;
|
|
65
|
+
this.deviceId = deviceId;
|
|
66
|
+
this.localKey = localKey;
|
|
67
|
+
this.dps = {};
|
|
68
|
+
this.connected = false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
ping() {
|
|
72
|
+
ping.pingHost(this.ip, (error, target) => {
|
|
73
|
+
if (error) {
|
|
74
|
+
debug(`${target}: ${error.toString()}`);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async initialize() {
|
|
80
|
+
this.ping();
|
|
81
|
+
|
|
82
|
+
this.device = new api({
|
|
83
|
+
id: this.deviceId,
|
|
84
|
+
key: this.localKey,
|
|
85
|
+
ip: this.ip,
|
|
86
|
+
version: '3.3',
|
|
87
|
+
issueRefreshOnConnect: true,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
this.device.on('connected', () => {
|
|
91
|
+
this.connected = true;
|
|
92
|
+
this.emit('tuya.connected');
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
this.device.on('disconnected', () => {
|
|
96
|
+
this.connected = false;
|
|
97
|
+
this.emit('tuya.disconnected');
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
this.device.on('error', error => {
|
|
101
|
+
this.emit('tuya.error', error);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
this.device.on('data', data => {
|
|
105
|
+
this.dps = { ...this.dps, ...data.dps };
|
|
106
|
+
this.emit('tuya.data', data);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
this.device.on('dp-refresh', data => {
|
|
110
|
+
this.dps = { ...this.dps, ...data.dps };
|
|
111
|
+
this.emit('tuya.dp-refresh', data);
|
|
112
|
+
|
|
113
|
+
Object.keys(data.dps).forEach(command => {
|
|
114
|
+
const value = data.dps[command];
|
|
115
|
+
if (command === COMMAND.activity) {
|
|
116
|
+
this.emit('event', { command: 'activity', value });
|
|
117
|
+
}
|
|
118
|
+
else if (command === COMMAND.goHome) {
|
|
119
|
+
this.emit('event', { command: 'goHome', value });
|
|
120
|
+
}
|
|
121
|
+
else if (command === COMMAND.findMyRobot) {
|
|
122
|
+
this.emit('event', { command: 'locate', value });
|
|
123
|
+
}
|
|
124
|
+
else if (command === COMMAND.battery) {
|
|
125
|
+
this.emit('event', { command: 'battery', value });
|
|
126
|
+
}
|
|
127
|
+
else if (command === COMMAND.error) {
|
|
128
|
+
this.emit('error', this.error());
|
|
129
|
+
}
|
|
130
|
+
else if (command === COMMAND.cleaningRuntime) {
|
|
131
|
+
this.emit('event', { command: 'runtime', value });
|
|
132
|
+
}
|
|
133
|
+
else if (command === COMMAND.cleaningCoverage) {
|
|
134
|
+
this.emit('event', { command: 'coverage', value });
|
|
135
|
+
}
|
|
136
|
+
else if (command === COMMAND.volume) {
|
|
137
|
+
this.emit('event', { command: 'volume', value });
|
|
138
|
+
}
|
|
139
|
+
else if (command === COMMAND.consumables) {
|
|
140
|
+
const consumables = this.consumables();
|
|
141
|
+
this.emit('event', { command: 'consumables', value: consumables });
|
|
142
|
+
if (consumables.consumable?.duration?.SB >= 250) {
|
|
143
|
+
this.emit('alert', { consumable: 'side_brush', duration: consumables.consumable?.duration?.SB });
|
|
144
|
+
}
|
|
145
|
+
if (consumables.consumable?.duration?.RB >= 450) {
|
|
146
|
+
this.emit('alert', { consumable: 'rolling_brush', duration: consumables.consumable?.duration?.RB });
|
|
147
|
+
}
|
|
148
|
+
if (consumables.consumable?.duration?.FM >= 200) {
|
|
149
|
+
this.emit('alert', { consumable: 'filter', duration: consumables.consumable?.duration?.FM });
|
|
150
|
+
}
|
|
151
|
+
if (consumables.consumable?.duration?.SS >= 35) {
|
|
152
|
+
this.emit('alert', { consumable: 'sensors', duration: consumables.consumable?.duration?.SS });
|
|
153
|
+
}
|
|
154
|
+
/* unknown!!!!!!!!
|
|
155
|
+
if (consumables.consumable?.duration?.SP >= 35) {
|
|
156
|
+
this.emit('alert', { consumable: 'sensors', duration: consumables.consumable?.duration?.SP });
|
|
157
|
+
}
|
|
158
|
+
if (consumables.consumable?.duration?.TR >= 35) {
|
|
159
|
+
this.emit('alert', { consumable: 'sensors', duration: consumables.consumable?.duration?.TR });
|
|
160
|
+
}
|
|
161
|
+
*/
|
|
162
|
+
if (consumables.consumable?.duration?.BatteryStatus !== 1) {
|
|
163
|
+
this.emit('alert', { consumable: 'battery', duration: consumables.consumable?.duration?.BatteryStatus });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (command === COMMAND.multimaps) {
|
|
167
|
+
this.emit('event', { command: 'multimaps', value: this.multimaps() });
|
|
168
|
+
}
|
|
169
|
+
else if (command === COMMAND.voice) {
|
|
170
|
+
this.emit('event', { command: 'voice', value: this.voice() });
|
|
171
|
+
}
|
|
172
|
+
else if (command === COMMAND.hello) {
|
|
173
|
+
this.emit('event', { command: 'hello', value: this.hello() });
|
|
174
|
+
}
|
|
175
|
+
else if (command === COMMAND.autoReturn) {
|
|
176
|
+
this.emit('event', { command: 'autoReturn', value });
|
|
177
|
+
}
|
|
178
|
+
else if (command === COMMAND.status) {
|
|
179
|
+
this.emit('event', { command: 'status', value: this.status() });
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
return this.connect();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
activity() {
|
|
188
|
+
if (!this.dps) {
|
|
189
|
+
debug('no data points available yet');
|
|
190
|
+
return 'unknown';
|
|
191
|
+
}
|
|
192
|
+
if (!this.dps.hasOwnProperty(COMMAND.activity)) {
|
|
193
|
+
throw new Error('RoboVac does not support this command');
|
|
194
|
+
}
|
|
195
|
+
return this.dps[COMMAND.activity];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
batteryLevel() {
|
|
199
|
+
if (!this.dps) {
|
|
200
|
+
debug('no data points available yet');
|
|
201
|
+
return -1;
|
|
202
|
+
}
|
|
203
|
+
if (!this.dps.hasOwnProperty(COMMAND.battery)) {
|
|
204
|
+
throw new Error('RoboVac does not support this command');
|
|
205
|
+
}
|
|
206
|
+
return this.dps[COMMAND.battery];
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
error() {
|
|
210
|
+
if (!this.dps) {
|
|
211
|
+
debug('no data points available yet');
|
|
212
|
+
return ERRORS[0];
|
|
213
|
+
}
|
|
214
|
+
if (this.dps[COMMAND.error] in ERRORS) {
|
|
215
|
+
return ERRORS[this.dps[COMMAND.error]];
|
|
216
|
+
}
|
|
217
|
+
return this.dps[COMMAND.error];
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
runtime() {
|
|
221
|
+
if (!this.dps) {
|
|
222
|
+
debug('no data points available yet');
|
|
223
|
+
return -1;
|
|
224
|
+
}
|
|
225
|
+
if (!this.dps.hasOwnProperty(COMMAND.cleaningRuntime)) {
|
|
226
|
+
throw new Error('RoboVac does not support this command');
|
|
227
|
+
}
|
|
228
|
+
return this.dps[COMMAND.cleaningRuntime];
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
coverage() {
|
|
232
|
+
if (!this.dps) {
|
|
233
|
+
debug('no data points available yet');
|
|
234
|
+
return -1;
|
|
235
|
+
}
|
|
236
|
+
if (!this.dps.hasOwnProperty(COMMAND.cleaningCoverage)) {
|
|
237
|
+
throw new Error('RoboVac does not support this command');
|
|
238
|
+
}
|
|
239
|
+
return this.dps[COMMAND.cleaningCoverage];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
consumables() {
|
|
243
|
+
if (!this.dps) {
|
|
244
|
+
debug('no data points available yet');
|
|
245
|
+
return ''
|
|
246
|
+
}
|
|
247
|
+
if (!this.dps.hasOwnProperty(COMMAND.consumables)) {
|
|
248
|
+
throw new Error('RoboVac does not support this command');
|
|
249
|
+
}
|
|
250
|
+
const json = Buffer.from(this.dps[COMMAND.consumables], 'base64');
|
|
251
|
+
return JSON.parse(json);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
status() {
|
|
255
|
+
if (!this.dps) {
|
|
256
|
+
debug('no data points available yet');
|
|
257
|
+
return ''
|
|
258
|
+
}
|
|
259
|
+
if (!this.dps.hasOwnProperty(COMMAND.status)) {
|
|
260
|
+
throw new Error('RoboVac does not support this command');
|
|
261
|
+
}
|
|
262
|
+
const json = Buffer.from(this.dps[COMMAND.status], 'base64');
|
|
263
|
+
return JSON.parse(json);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
docked() {
|
|
267
|
+
const activity = this.activity();
|
|
268
|
+
return activity === 'Sleeping' || activity === 'Charging' || activity === 'completed';
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async connect() {
|
|
272
|
+
await this.device.find();
|
|
273
|
+
return this.device.connect();
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
async disconnect() {
|
|
277
|
+
return this.device.disconnect();
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async get(data) {
|
|
281
|
+
if (!this.connected) {
|
|
282
|
+
throw new Error('RoboVac is disconnected');
|
|
283
|
+
}
|
|
284
|
+
return this.device.get(data);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async set(data) {
|
|
288
|
+
if (!this.connected) {
|
|
289
|
+
throw new Error('RoboVac is disconnected');
|
|
290
|
+
}
|
|
291
|
+
return this.device.set({ multiple: true, data });
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
async refresh() {
|
|
295
|
+
return this.get({ schema: true });
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
async locate(flag) {
|
|
299
|
+
if (!this.dps) {
|
|
300
|
+
throw new Error('no data points available yet');
|
|
301
|
+
}
|
|
302
|
+
if (!this.dps.hasOwnProperty(COMMAND.findMyRobot)) {
|
|
303
|
+
throw new Error('RoboVac does not support this command');
|
|
304
|
+
}
|
|
305
|
+
if (this.docked()) {
|
|
306
|
+
throw new Error('RoboVac is on the charging base');
|
|
307
|
+
}
|
|
308
|
+
const b = this.dps[COMMAND.findMyRobot];
|
|
309
|
+
if (b === flag) {
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
return this.set({ [COMMAND.findMyRobot]: flag });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async goHome(flag) {
|
|
316
|
+
if (!this.dps) {
|
|
317
|
+
throw new Error('no data points available yet');
|
|
318
|
+
}
|
|
319
|
+
if (this.docked()) {
|
|
320
|
+
throw new Error('RoboVac is already home');
|
|
321
|
+
}
|
|
322
|
+
if (!this.dps.hasOwnProperty(COMMAND.goHome)) {
|
|
323
|
+
throw new Error('RoboVac does not support this command');
|
|
324
|
+
}
|
|
325
|
+
const b = this.dps[COMMAND.goHome];
|
|
326
|
+
if (b === flag) {
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
return this.set({ [COMMAND.goHome]: flag });
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
volume() {
|
|
333
|
+
if (!this.dps) {
|
|
334
|
+
throw new Error('no data points available yet');
|
|
335
|
+
}
|
|
336
|
+
if (!this.dps.hasOwnProperty(COMMAND.volume)) {
|
|
337
|
+
throw new Error('RoboVac does not support this command');
|
|
338
|
+
}
|
|
339
|
+
return this.dps[COMMAND.volume];
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
async setVolume(value) {
|
|
343
|
+
if (!this.dps.hasOwnProperty(COMMAND.volume)) {
|
|
344
|
+
throw new Error('RoboVac does not support this command');
|
|
345
|
+
}
|
|
346
|
+
if (value < 0 || volume > 100) {
|
|
347
|
+
throw new Error('expecting value between 0 to 100');
|
|
348
|
+
}
|
|
349
|
+
return this.set({ [COMMAND.volume]: value });
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
multimaps() {
|
|
353
|
+
if (!this.dps) {
|
|
354
|
+
throw new Error('no data points available yet');
|
|
355
|
+
}
|
|
356
|
+
if (!this.dps.hasOwnProperty(COMMAND.multimaps)) {
|
|
357
|
+
throw new Error('RoboVac does not support this command');
|
|
358
|
+
}
|
|
359
|
+
const json = Buffer.from(this.dps[COMMAND.multimaps], 'base64');
|
|
360
|
+
return JSON.parse(json);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
voice() {
|
|
364
|
+
if (!this.dps) {
|
|
365
|
+
throw new Error('no data points available yet');
|
|
366
|
+
}
|
|
367
|
+
if (!this.dps.hasOwnProperty(COMMAND.voice)) {
|
|
368
|
+
throw new Error('RoboVac does not support this command');
|
|
369
|
+
}
|
|
370
|
+
const json = Buffer.from(this.dps[COMMAND.voice], 'base64');
|
|
371
|
+
return JSON.parse(json);
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
hello() {
|
|
375
|
+
if (!this.dps) {
|
|
376
|
+
throw new Error('no data points available yet');
|
|
377
|
+
}
|
|
378
|
+
if (!this.dps.hasOwnProperty(COMMAND.hello)) {
|
|
379
|
+
throw new Error('RoboVac does not support this command');
|
|
380
|
+
}
|
|
381
|
+
const json = Buffer.from(this.dps[COMMAND.hello], 'base64');
|
|
382
|
+
return JSON.parse(json);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
autoReturn() {
|
|
386
|
+
if (!this.dps) {
|
|
387
|
+
throw new Error('no data points available yet');
|
|
388
|
+
}
|
|
389
|
+
if (!this.dps.hasOwnProperty(COMMAND.autoReturn)) {
|
|
390
|
+
throw new Error('RoboVac does not support this command');
|
|
391
|
+
}
|
|
392
|
+
return this.dps[COMMAND.autoReturn];
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
async setAutoReturn(flag) {
|
|
396
|
+
if (!this.dps.hasOwnProperty(COMMAND.autoReturn)) {
|
|
397
|
+
throw new Error('RoboVac does not support this command');
|
|
398
|
+
}
|
|
399
|
+
return this.set({ [COMMAND.autoReturn]: flag });
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
module.exports = { RoboVac };
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@george.talusan/eufy-robovac-js",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"debug": "^4.3.5",
|
|
12
|
+
"net-ping": "^1.2.4",
|
|
13
|
+
"tuyapi": "github:codetheweb/tuyapi"
|
|
14
|
+
},
|
|
15
|
+
"directories": {
|
|
16
|
+
"lib": "lib"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {},
|
|
19
|
+
"description": ""
|
|
20
|
+
}
|