forked from Apollon77/meross-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
81 lines (61 loc) · 2.06 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* jshint -W097 */
/* jshint -W030 */
/* jshint strict:true */
/* jslint node: true */
/* jslint esversion: 6 */
'use strict';
const MerossCloud = require('../index.js');
const options = {
'email': 'email',
'password': 'password',
'logger': console.log
};
const meross = new MerossCloud(options);
meross.on('deviceInitialized', (deviceId, deviceDef, device) => {
console.log('New device ' + deviceId + ': ' + JSON.stringify(deviceDef));
device.on('connected', () => {
console.log('DEV: ' + deviceId + ' connected');
device.getSystemAbilities((err, res) => {
console.log('Abilities: ' + JSON.stringify(res));
device.getSystemAllData((err, res) => {
console.log('All-Data: ' + JSON.stringify(res));
});
});
setTimeout(() => {
console.log('toggle ...');
device.controlToggleX(1, true, (err, res) => {
console.log('Toggle Response: err: ' + err + ', res: ' + JSON.stringify(res));
});
}, 2000);
});
device.on('close', (error) => {
console.log('DEV: ' + deviceId + ' closed: ' + error);
});
device.on('error', (error) => {
console.log('DEV: ' + deviceId + ' error: ' + error);
});
device.on('reconnect', () => {
console.log('DEV: ' + deviceId + ' reconnected');
});
device.on('data', (namespace, payload) => {
console.log('DEV: ' + deviceId + ' ' + namespace + ' - data: ' + JSON.stringify(payload));
});
});
meross.on('connected', (deviceId) => {
console.log(deviceId + ' connected');
});
meross.on('close', (deviceId, error) => {
console.log(deviceId + ' closed: ' + error);
});
meross.on('error', (deviceId, error) => {
console.log(deviceId + ' error: ' + error);
});
meross.on('reconnect', (deviceId) => {
console.log(deviceId + ' reconnected');
});
meross.on('data', (deviceId, payload) => {
console.log(deviceId + ' data: ' + JSON.stringify(payload));
});
meross.connect((error) => {
console.log('connect error: ' + error);
});