sinricpro 2.2.8 → 2.3.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/.github/workflows/npm-publish.yml +32 -0
- package/README.md +15 -191
- package/lib/contorllers/tv_controller.js +1 -1
- package/lib/sinrcpro.js +15 -16
- package/lib/storage.js +1 -1
- package/package.json +38 -42
|
@@ -0,0 +1,32 @@
|
|
|
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://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages
|
|
3
|
+
|
|
4
|
+
name: Node.js Package
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
release:
|
|
8
|
+
types: [created]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v2
|
|
15
|
+
- uses: actions/setup-node@v2
|
|
16
|
+
with:
|
|
17
|
+
node-version: 16
|
|
18
|
+
- run: npm ci
|
|
19
|
+
|
|
20
|
+
publish-npm:
|
|
21
|
+
needs: build
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v2
|
|
25
|
+
- uses: actions/setup-node@v2
|
|
26
|
+
with:
|
|
27
|
+
node-version: 16
|
|
28
|
+
registry-url: https://registry.npmjs.org/
|
|
29
|
+
- run: npm ci
|
|
30
|
+
- run: npm publish
|
|
31
|
+
env:
|
|
32
|
+
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
|
package/README.md
CHANGED
|
@@ -1,191 +1,15 @@
|
|
|
1
|
-
# SinricPro (NodeJs-SDK)
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/sinricpro)
|
|
4
|
-
[](https://www.npmjs.com/package/sinricpro)
|
|
5
|
-
[](https://www.npmjs.com/package/sinricpro)
|
|
6
|
-
[](https://www.npmjs.com/package/sinricpro)
|
|
7
|
-
|
|
8
|
-
### Installation
|
|
9
|
-
|
|
10
|
-
```
|
|
11
|
-
npm install sinricpro
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
###
|
|
15
|
-
|
|
16
|
-
- [websockets](https://www.npmjs.com/package/ws)
|
|
17
|
-
|
|
18
|
-
- [crypto](https://nodejs.org/api/crypto.html)
|
|
19
|
-
|
|
20
|
-
- [uuid](https://www.npmjs.com/package/uuid)
|
|
21
|
-
|
|
22
|
-
- [dgram]()
|
|
23
|
-
|
|
24
|
-
- [rxjs](https://www.npmjs.com/package/rxjs)
|
|
25
|
-
|
|
26
|
-
### Basic example
|
|
27
|
-
|
|
28
|
-
```javascript 1.8
|
|
29
|
-
const {
|
|
30
|
-
SinricPro,
|
|
31
|
-
SinricProActions,
|
|
32
|
-
raiseEvent,
|
|
33
|
-
eventNames,
|
|
34
|
-
SinricProUdp
|
|
35
|
-
} = require("../index"); // Use require('sinricpro'); if you are using NPM
|
|
36
|
-
|
|
37
|
-
const appKey = ""; // d89f1***-****-****-****-************
|
|
38
|
-
const secretKey = ""; // f44d1d31-1c19-****-****-9bc96c34b5bb-d19f42dd-****-****-****-************
|
|
39
|
-
const device1 = ""; // 5d7e7d96069e275ea9******
|
|
40
|
-
const device2 = ""; // 5d80ac5713fa175e99******
|
|
41
|
-
const deviceId = [device1, device2];
|
|
42
|
-
|
|
43
|
-
function setPowerState(deviceid, data) {
|
|
44
|
-
console.log(deviceid, data);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const callbacks = {
|
|
49
|
-
setPowerState
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const sinricpro = new SinricPro(appKey, deviceId, secretKey, true);
|
|
53
|
-
|
|
54
|
-
SinricProActions(sinricpro, callbacks);
|
|
55
|
-
|
|
56
|
-
setInterval(() => {
|
|
57
|
-
raiseEvent(sinricpro, eventNames.powerState, device1, { state: "On" });
|
|
58
|
-
}, 2000);
|
|
59
|
-
|
|
60
|
-
// https://github.com/sinricpro/nodejs-sdk/blob/master/examples/simple-example/simple-example.js
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Advanced example
|
|
64
|
-
|
|
65
|
-
#### Add a credential file into your root folder (credential.js)
|
|
66
|
-
|
|
67
|
-
```javascript 1.8
|
|
68
|
-
const credential = {
|
|
69
|
-
appkey: "",
|
|
70
|
-
secretKey: ""
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
const deviceIds = {
|
|
74
|
-
deviceId1: "",
|
|
75
|
-
deviceId2: "",
|
|
76
|
-
deviceId3: ""
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// No need to edit the code below
|
|
80
|
-
|
|
81
|
-
let deviceIdT = [];
|
|
82
|
-
|
|
83
|
-
for (let key in deviceIds) {
|
|
84
|
-
if (deviceIds.hasOwnProperty(key)) {
|
|
85
|
-
deviceIdT.push(deviceIds[key]);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
module.exports = {
|
|
90
|
-
appKey: credential.appkey,
|
|
91
|
-
secretKey: credential.secretKey,
|
|
92
|
-
deviceId: deviceIdT
|
|
93
|
-
};
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
#### Example (app.js)
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
const { appKey, deviceId, secretKey } = require("../credentials");
|
|
100
|
-
const {
|
|
101
|
-
SinricPro,
|
|
102
|
-
SinricProActions,
|
|
103
|
-
raiseEvent,
|
|
104
|
-
eventNames,
|
|
105
|
-
SinricProUdp
|
|
106
|
-
} = require("../index");
|
|
107
|
-
|
|
108
|
-
function setPowerState(deviceid, data) {
|
|
109
|
-
console.log(deviceid, data);
|
|
110
|
-
return true;
|
|
111
|
-
}
|
|
112
|
-
function setPowerLevel(deviceid, data) {
|
|
113
|
-
console.log(deviceid, data);
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function adjustPowerLevel(deviceid, data) {
|
|
118
|
-
console.log(deviceid, data);
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function setColor(deviceid, data) {
|
|
123
|
-
console.log(deviceid, data);
|
|
124
|
-
return true;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function setRangeValue(deviceid, data) {
|
|
128
|
-
console.log(deviceid, data);
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
function setLockState(deviceid, data) {
|
|
132
|
-
console.log(deviceid, data);
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function setBrightness(deviceid, data) {
|
|
137
|
-
console.log(deviceid, data);
|
|
138
|
-
return true;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
function setVolume(deviceid, data) {
|
|
142
|
-
console.log(deviceid, data);
|
|
143
|
-
return true;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function adjustVolume(deviceid, data) {
|
|
147
|
-
console.log(deviceid, data);
|
|
148
|
-
return true;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function setMute(deviceid, data) {
|
|
152
|
-
console.log(deviceid, data);
|
|
153
|
-
return true;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
const callbacks = {
|
|
157
|
-
setPowerState,
|
|
158
|
-
setPowerLevel,
|
|
159
|
-
adjustPowerLevel,
|
|
160
|
-
setColor,
|
|
161
|
-
setRangeValue,
|
|
162
|
-
setLockState,
|
|
163
|
-
setBrightness,
|
|
164
|
-
setVolume,
|
|
165
|
-
adjustVolume,
|
|
166
|
-
setMute
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
const sinricpro = new SinricPro(appKey, deviceId, secretKey, true);
|
|
170
|
-
SinricProActions(sinricpro, callbacks);
|
|
171
|
-
|
|
172
|
-
setInterval(() => {
|
|
173
|
-
// raiseEvent(sinricpro, eventNames.powerState, 'deviceId', { state: 'On' });
|
|
174
|
-
// raiseEvent(sinricpro, eventNames.setBrightness, 'deviceId', { brightness: 44 });
|
|
175
|
-
// raiseEvent(sinricpro, eventNames.powerLevel, 'deviceId', { powerLevel: 44 });
|
|
176
|
-
// raiseEvent(sinricpro, eventNames.color, 'DeviceId', { color: { b: 0, g: 0, r: 0 } });
|
|
177
|
-
// raiseEvent(sinricpro, eventNames.colorTemperature, 'Deviceid', { colorTemperature: 8 });
|
|
178
|
-
// raiseEvent(sinricpro, eventNames.doorBell, 'DeviceId', { state: 'pressed' });
|
|
179
|
-
// raiseEvent(sinricpro, eventNames.thermostatMode, 'DeviceId', { thermostatMode: 'AUTO' });
|
|
180
|
-
// raiseEvent(sinricpro, eventNames.rangvalue, 'DeviceId', { rangvalue: 3 });
|
|
181
|
-
// raiseEvent(sinricpro, eventNames.motion, 'DeviceId', { state: 'detected' });
|
|
182
|
-
// raiseEvent(sinricpro, eventNames.contact, 'DeviceId', { state: 'closed' });
|
|
183
|
-
// raiseEvent(sinricpro, eventNames.setVolume, 'DeviceId', { volume: 29 });
|
|
184
|
-
// raiseEvent(sinricpro, eventNames.selectInput, 'DeviceId', { input: 'HDMI' });
|
|
185
|
-
// raiseEvent(sinricpro, eventNames.media, 'DeviceId', { control: 'FastForward' });
|
|
186
|
-
// raiseEvent(sinricpro, eventNames.channel, 'DeviceId', { channel: { name: 'HBO' } });
|
|
187
|
-
// raiseEvent(sinricpro, eventNames.mode, 'DeviceId', { mode: 'MOVIE' });
|
|
188
|
-
// raiseEvent(sinricpro, eventNames.lock, 'DeviceId', { state: 'LOCKED' });
|
|
189
|
-
// raiseEvent(sinricpro, eventNames.mute, 'DeviceId', { mute: true });
|
|
190
|
-
}, 2000);
|
|
191
|
-
```
|
|
1
|
+
# SinricPro (NodeJs-SDK)
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/sinricpro)
|
|
4
|
+
[](https://www.npmjs.com/package/sinricpro)
|
|
5
|
+
[](https://www.npmjs.com/package/sinricpro)
|
|
6
|
+
[](https://www.npmjs.com/package/sinricpro)
|
|
7
|
+
|
|
8
|
+
### Installation
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
npm install sinricpro
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### Examples
|
|
15
|
+
Check the examples [here](https://github.com/sinricpro/nodejs-sdk/tree/master/examples)
|
|
@@ -55,7 +55,7 @@ const Media = (payload, callbacks) => {
|
|
|
55
55
|
};
|
|
56
56
|
|
|
57
57
|
const ChangeChannel = (payload, callbacks) => {
|
|
58
|
-
const channel = payload.value.channel.name
|
|
58
|
+
const channel = payload.value.channel.name || payload.value.channel.number;
|
|
59
59
|
const resp = callbacks.changeChannel(payload.deviceId, channel);
|
|
60
60
|
return new Promise((resolve, reject) => {
|
|
61
61
|
if (channel && resp) resolve(payload.value);
|
package/lib/sinrcpro.js
CHANGED
|
@@ -8,20 +8,19 @@
|
|
|
8
8
|
const Websocket = require("ws");
|
|
9
9
|
const rx = require("rxjs");
|
|
10
10
|
|
|
11
|
-
const callbackHandler = require(
|
|
12
|
-
const { raiseEvent, eventNames } = require(
|
|
13
|
-
const SinricProUdp = require(
|
|
14
|
-
|
|
15
|
-
const VERSION = "2.2.2";
|
|
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;
|
|
16
15
|
|
|
17
16
|
class SinricPro extends Websocket {
|
|
18
17
|
constructor(appkey, deviceids, secretKey, restoreStates) {
|
|
19
18
|
super("ws://ws.sinric.pro", {
|
|
20
19
|
headers: {
|
|
21
20
|
appkey,
|
|
22
|
-
deviceids: deviceids.join(
|
|
23
|
-
platform:
|
|
24
|
-
|
|
21
|
+
deviceids: deviceids.join(';'),
|
|
22
|
+
platform: 'nodejs',
|
|
23
|
+
sdkversion: sdkVersion,
|
|
25
24
|
restoredevicestates: restoreStates,
|
|
26
25
|
},
|
|
27
26
|
});
|
|
@@ -37,9 +36,9 @@ class SinricPro extends Websocket {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
const
|
|
41
|
-
client.on(
|
|
42
|
-
console.log(
|
|
39
|
+
const startSinricPro = (client, callbacks) => {
|
|
40
|
+
client.on('open', () => {
|
|
41
|
+
console.log('Connected to Sinric Pro');
|
|
43
42
|
});
|
|
44
43
|
|
|
45
44
|
client.on("message", (data) => {
|
|
@@ -73,9 +72,9 @@ const SinricProActions = (client, callbacks) => {
|
|
|
73
72
|
});
|
|
74
73
|
};
|
|
75
74
|
|
|
76
|
-
const
|
|
77
|
-
client.on(
|
|
78
|
-
console.log(
|
|
75
|
+
const startSinricProObservable = (client, callbacks) => new rx.Observable((observer) => {
|
|
76
|
+
client.on('open', () => {
|
|
77
|
+
console.log('Connected');
|
|
79
78
|
});
|
|
80
79
|
|
|
81
80
|
client.on("message", (data) => {
|
|
@@ -114,8 +113,8 @@ const SinricProActionsObservable = (client, callbacks) => new rx.Observable((obs
|
|
|
114
113
|
|
|
115
114
|
module.exports = {
|
|
116
115
|
SinricPro,
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
startSinricPro,
|
|
117
|
+
startSinricProObservable,
|
|
119
118
|
raiseEvent,
|
|
120
119
|
eventNames,
|
|
121
120
|
SinricProUdp,
|
package/lib/storage.js
CHANGED
package/package.json
CHANGED
|
@@ -1,42 +1,38 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "sinricpro",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Sinric Pro Nodejs SDK",
|
|
5
|
-
"main": "index.js",
|
|
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
|
-
"eslint": "^
|
|
35
|
-
"eslint-
|
|
36
|
-
"eslint-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
"eslint-plugin-promise": "^4.2.1",
|
|
40
|
-
"eslint-plugin-standard": "^4.0.1"
|
|
41
|
-
}
|
|
42
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "sinricpro",
|
|
3
|
+
"version": "2.3.1",
|
|
4
|
+
"description": "Sinric Pro Nodejs SDK",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/sinricpro/nodejs-sdk.git"
|
|
9
|
+
},
|
|
10
|
+
"author": "Dhanush",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/sinricpro/nodejs-sdk/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/sinricpro/nodejs-sdk#readme",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"dgram": "^1.0.1",
|
|
18
|
+
"leaky-bucket": "^4.1.4",
|
|
19
|
+
"process": "^0.11.10",
|
|
20
|
+
"rate-limiter-flexible": "^2.3.6",
|
|
21
|
+
"rxjs": "^6.6.3",
|
|
22
|
+
"uuid": "^3.3.3",
|
|
23
|
+
"ws": "^8.5.0"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"sinricpro",
|
|
27
|
+
"sinric"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"eslint": "^6.8.0",
|
|
31
|
+
"eslint-config-airbnb-base": "^14.0.0",
|
|
32
|
+
"eslint-config-standard": "^14.1.0",
|
|
33
|
+
"eslint-plugin-import": "^2.18.2",
|
|
34
|
+
"eslint-plugin-node": "^10.0.0",
|
|
35
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
36
|
+
"eslint-plugin-standard": "^4.0.1"
|
|
37
|
+
}
|
|
38
|
+
}
|