sinricpro 2.3.1 → 2.4.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/lib/contorllers/range_value_controller.js +32 -32
- package/lib/sinrcpro.js +121 -121
- package/notes-to-aruna.txt +6 -0
- package/package.json +2 -2
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
4
|
-
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
5
|
-
*
|
|
6
|
-
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const sinricProData = require('../storage');
|
|
10
|
-
|
|
11
|
-
const RangeValue = (payload, callbacks) => {
|
|
12
|
-
sinricProData.rangeValue = payload.value.rangeValue;
|
|
13
|
-
const resp = callbacks.setRangeValue(payload.deviceId, sinricProData.rangeValue);
|
|
14
|
-
return new Promise((resolve, reject) => {
|
|
15
|
-
if (payload.value.rangeValue && resp) resolve(payload.value);
|
|
16
|
-
else reject(new Error('RangeValue is undefined'));
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const RangeValueAdjust = (payload, callbacks) => {
|
|
21
|
-
sinricProData.rangeValue += payload.value.rangeValueDelta;
|
|
22
|
-
if (sinricProData.rangeValue < 0) sinricProData.rangeValue = 0;
|
|
23
|
-
else if (sinricProData.rangeValue > 100) sinricProData.rangeValue = 100;
|
|
24
|
-
const resp = callbacks.adjustRangeValue(payload.deviceId, sinricProData.rangeValue);
|
|
25
|
-
return new Promise((resolve, reject) => {
|
|
26
|
-
if (payload.value.rangeValueDelta && resp) resolve({ rangeValue: sinricProData.rangeValue });
|
|
27
|
-
else reject(new Error('RangeValue undefined'));
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
module.exports = { RangeValue, RangeValueAdjust };
|
|
1
|
+
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
4
|
+
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
5
|
+
*
|
|
6
|
+
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const sinricProData = require('../storage');
|
|
10
|
+
|
|
11
|
+
const RangeValue = (payload, callbacks) => {
|
|
12
|
+
sinricProData.rangeValue = payload.value.rangeValue;
|
|
13
|
+
const resp = callbacks.setRangeValue(payload.deviceId, sinricProData.rangeValue);
|
|
14
|
+
return new Promise((resolve, reject) => {
|
|
15
|
+
if (payload.value.rangeValue !== undefined && resp) resolve(payload.value);
|
|
16
|
+
else reject(new Error('RangeValue is undefined'));
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const RangeValueAdjust = (payload, callbacks) => {
|
|
21
|
+
sinricProData.rangeValue += payload.value.rangeValueDelta;
|
|
22
|
+
if (sinricProData.rangeValue < 0) sinricProData.rangeValue = 0;
|
|
23
|
+
else if (sinricProData.rangeValue > 100) sinricProData.rangeValue = 100;
|
|
24
|
+
const resp = callbacks.adjustRangeValue(payload.deviceId, sinricProData.rangeValue);
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
if (payload.value.rangeValueDelta && resp) resolve({ rangeValue: sinricProData.rangeValue });
|
|
27
|
+
else reject(new Error('RangeValue undefined'));
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
module.exports = { RangeValue, RangeValueAdjust };
|
package/lib/sinrcpro.js
CHANGED
|
@@ -1,121 +1,121 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
3
|
-
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
4
|
-
*
|
|
5
|
-
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
6
|
-
*
|
|
7
|
-
*/
|
|
8
|
-
const Websocket = require("ws");
|
|
9
|
-
const rx = require("rxjs");
|
|
10
|
-
|
|
11
|
-
const callbackHandler = require('./cbhandler');
|
|
12
|
-
const { raiseEvent, eventNames } = require('./events/event_handler');
|
|
13
|
-
const SinricProUdp = require('./sinricproudp');
|
|
14
|
-
const sdkVersion = require('./../package.json').version;
|
|
15
|
-
|
|
16
|
-
class SinricPro extends Websocket {
|
|
17
|
-
constructor(appkey, deviceids, secretKey, restoreStates) {
|
|
18
|
-
super("ws://ws.sinric.pro", {
|
|
19
|
-
headers: {
|
|
20
|
-
appkey,
|
|
21
|
-
deviceids: deviceids.join(';'),
|
|
22
|
-
platform: 'nodejs',
|
|
23
|
-
sdkversion: sdkVersion,
|
|
24
|
-
restoredevicestates: restoreStates,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
this._secretKey = secretKey;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
get getSecretKey() {
|
|
31
|
-
return this._secretKey;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
set setSecretKey(key) {
|
|
35
|
-
this._secretKey = key;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const startSinricPro = (client, callbacks) => {
|
|
40
|
-
client.on('open', () => {
|
|
41
|
-
console.log('Connected to Sinric Pro');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
client.on("message", (data) => {
|
|
45
|
-
const parsedData = JSON.parse(data);
|
|
46
|
-
|
|
47
|
-
if (parsedData.timestamp) {
|
|
48
|
-
if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
|
|
49
|
-
console.log("Timestamp is not in sync");
|
|
50
|
-
} else console.log("TimeStamp is in sync");
|
|
51
|
-
} else {
|
|
52
|
-
const response = callbackHandler(
|
|
53
|
-
client,
|
|
54
|
-
parsedData.payload,
|
|
55
|
-
parsedData.signature.HMAC,
|
|
56
|
-
callbacks,
|
|
57
|
-
);
|
|
58
|
-
response
|
|
59
|
-
.then((res) => {
|
|
60
|
-
client.send(JSON.stringify(res));
|
|
61
|
-
})
|
|
62
|
-
.catch((err) => {
|
|
63
|
-
console.log(err.message);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
client.on("close", () => {
|
|
69
|
-
if (callbacks.onDisconnect) {
|
|
70
|
-
callbacks.onDisconnect();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const startSinricProObservable = (client, callbacks) => new rx.Observable((observer) => {
|
|
76
|
-
client.on('open', () => {
|
|
77
|
-
console.log('Connected');
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
client.on("message", (data) => {
|
|
81
|
-
const parsedData = JSON.parse(data);
|
|
82
|
-
if (parsedData.timestamp) {
|
|
83
|
-
if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
|
|
84
|
-
console.log("Timestamp is not in sync");
|
|
85
|
-
} else console.log("TimeStamp is in sync");
|
|
86
|
-
} else {
|
|
87
|
-
const response = callbackHandler(
|
|
88
|
-
client,
|
|
89
|
-
parsedData.payload,
|
|
90
|
-
parsedData.signature.HMAC,
|
|
91
|
-
callbacks,
|
|
92
|
-
);
|
|
93
|
-
response
|
|
94
|
-
.then((res) => {
|
|
95
|
-
observer.next(res);
|
|
96
|
-
client.send(JSON.stringify(res));
|
|
97
|
-
})
|
|
98
|
-
.catch((err) => {
|
|
99
|
-
observer.error(err.message);
|
|
100
|
-
console.log(err.message);
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
client.on("close", () => {
|
|
106
|
-
observer.complete();
|
|
107
|
-
if (callbacks.onDisconnect) {
|
|
108
|
-
callbacks.onDisconnect();
|
|
109
|
-
}
|
|
110
|
-
console.log("Disconnected");
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
module.exports = {
|
|
115
|
-
SinricPro,
|
|
116
|
-
startSinricPro,
|
|
117
|
-
startSinricProObservable,
|
|
118
|
-
raiseEvent,
|
|
119
|
-
eventNames,
|
|
120
|
-
SinricProUdp,
|
|
121
|
-
};
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2019 Sinric. All rights reserved.
|
|
3
|
+
* Licensed under Creative Commons Attribution-Share Alike (CC BY-SA)
|
|
4
|
+
*
|
|
5
|
+
* This file is part of the Sinric Pro (https://github.com/sinricpro/)
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
const Websocket = require("ws");
|
|
9
|
+
const rx = require("rxjs");
|
|
10
|
+
|
|
11
|
+
const callbackHandler = require('./cbhandler');
|
|
12
|
+
const { raiseEvent, eventNames } = require('./events/event_handler');
|
|
13
|
+
const SinricProUdp = require('./sinricproudp');
|
|
14
|
+
const sdkVersion = require('./../package.json').version;
|
|
15
|
+
|
|
16
|
+
class SinricPro extends Websocket {
|
|
17
|
+
constructor(appkey, deviceids, secretKey, restoreStates) {
|
|
18
|
+
super("ws://ws.sinric.pro", {
|
|
19
|
+
headers: {
|
|
20
|
+
appkey,
|
|
21
|
+
deviceids: deviceids.join(';'),
|
|
22
|
+
platform: 'nodejs',
|
|
23
|
+
sdkversion: sdkVersion,
|
|
24
|
+
restoredevicestates: restoreStates,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
this._secretKey = secretKey;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get getSecretKey() {
|
|
31
|
+
return this._secretKey;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
set setSecretKey(key) {
|
|
35
|
+
this._secretKey = key;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const startSinricPro = (client, callbacks) => {
|
|
40
|
+
client.on('open', () => {
|
|
41
|
+
console.log('Connected to Sinric Pro');
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
client.on("message", (data) => {
|
|
45
|
+
const parsedData = JSON.parse(data);
|
|
46
|
+
|
|
47
|
+
if (parsedData.timestamp) {
|
|
48
|
+
if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
|
|
49
|
+
console.log("Timestamp is not in sync");
|
|
50
|
+
} else console.log("TimeStamp is in sync");
|
|
51
|
+
} else {
|
|
52
|
+
const response = callbackHandler(
|
|
53
|
+
client,
|
|
54
|
+
parsedData.payload,
|
|
55
|
+
parsedData.signature.HMAC,
|
|
56
|
+
callbacks,
|
|
57
|
+
);
|
|
58
|
+
response
|
|
59
|
+
.then((res) => {
|
|
60
|
+
client.send(JSON.stringify(res));
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
console.log(err.message);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
client.on("close", () => {
|
|
69
|
+
if (callbacks.onDisconnect) {
|
|
70
|
+
callbacks.onDisconnect();
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const startSinricProObservable = (client, callbacks) => new rx.Observable((observer) => {
|
|
76
|
+
client.on('open', () => {
|
|
77
|
+
console.log('Connected');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
client.on("message", (data) => {
|
|
81
|
+
const parsedData = JSON.parse(data);
|
|
82
|
+
if (parsedData.timestamp) {
|
|
83
|
+
if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
|
|
84
|
+
console.log("Timestamp is not in sync");
|
|
85
|
+
} else console.log("TimeStamp is in sync");
|
|
86
|
+
} else {
|
|
87
|
+
const response = callbackHandler(
|
|
88
|
+
client,
|
|
89
|
+
parsedData.payload,
|
|
90
|
+
parsedData.signature.HMAC,
|
|
91
|
+
callbacks,
|
|
92
|
+
);
|
|
93
|
+
response
|
|
94
|
+
.then((res) => {
|
|
95
|
+
observer.next(res);
|
|
96
|
+
client.send(JSON.stringify(res));
|
|
97
|
+
})
|
|
98
|
+
.catch((err) => {
|
|
99
|
+
observer.error(err.message);
|
|
100
|
+
console.log(err.message);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
client.on("close", () => {
|
|
106
|
+
observer.complete();
|
|
107
|
+
if (callbacks.onDisconnect) {
|
|
108
|
+
callbacks.onDisconnect();
|
|
109
|
+
}
|
|
110
|
+
console.log("Disconnected");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
module.exports = {
|
|
115
|
+
SinricPro,
|
|
116
|
+
startSinricPro,
|
|
117
|
+
startSinricProObservable,
|
|
118
|
+
raiseEvent,
|
|
119
|
+
eventNames,
|
|
120
|
+
SinricProUdp,
|
|
121
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sinricpro",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Sinric Pro Nodejs SDK",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"sinric"
|
|
28
28
|
],
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"eslint": "^
|
|
30
|
+
"eslint": "^8.9.0",
|
|
31
31
|
"eslint-config-airbnb-base": "^14.0.0",
|
|
32
32
|
"eslint-config-standard": "^14.1.0",
|
|
33
33
|
"eslint-plugin-import": "^2.18.2",
|