sinricpro 2.2.8 → 2.5.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.
@@ -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://img.shields.io/npm/v/sinricpro)](https://www.npmjs.com/package/sinricpro)
4
- [![](https://img.shields.io/npm/dependency-version/sinricpro/dev/eslint)](https://www.npmjs.com/package/sinricpro)
5
- [![](https://img.shields.io/bundlephobia/min/sinricpro)](https://www.npmjs.com/package/sinricpro)
6
- [![](https://img.shields.io/github/languages/code-size/sinricpro/nodejs-sdk)](https://www.npmjs.com/package/sinricpro)
7
-
8
- ### Installation
9
-
10
- ```
11
- npm install sinricpro
12
- ```
13
-
14
- ### Dependencies
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://img.shields.io/npm/v/sinricpro)](https://www.npmjs.com/package/sinricpro)
4
+ [![](https://img.shields.io/npm/dependency-version/sinricpro/dev/eslint)](https://www.npmjs.com/package/sinricpro)
5
+ [![](https://img.shields.io/bundlephobia/min/sinricpro)](https://www.npmjs.com/package/sinricpro)
6
+ [![](https://img.shields.io/github/languages/code-size/sinricpro/nodejs-sdk)](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)
package/lib/cbhandler.js CHANGED
@@ -1,192 +1,199 @@
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 { getSignature, verifySignature } = require('./signature');
9
- const { powerState, powerLevel, powerLevelAdjust } = require('./contorllers/power_controller');
10
- const { Brightness, BrightnessAdjust } = require('./contorllers/brightness_controller');
11
- const { Color } = require('./contorllers/color_controller');
12
- const { ColorTemperature } = require('./contorllers/color_temperature');
13
- const { ThermoStatMode, ThermoStatTemperature, Lock } = require('./contorllers/sensors_controller');
14
- const { RangeValue, RangeValueAdjust } = require('./contorllers/range_value_controller');
15
- const { Volume, VolumeAdjust, Mute } = require('./contorllers/tv_controller');
16
- const { ChangeChannel, SkipChannel, Media } = require('./contorllers/tv_controller');
17
- const { Input } = require('./contorllers/tv_controller');
18
- const { Bands, Mode, BandReset } = require('./contorllers/speaker_controller');
19
- const { AdjustBands } = require('./contorllers/speaker_controller');
20
-
21
- const jsonResponse = (client, defaultPayload, dValue) => {
22
- const header = {
23
- payloadVersion: 2,
24
- signatureVersion: 1,
25
- };
26
-
27
- const payload = {
28
- action: defaultPayload.action,
29
- clientId: defaultPayload.clientId,
30
- createdAt: Math.floor(new Date() / 1000),
31
- deviceId: defaultPayload.deviceId,
32
- message: 'OK',
33
- replyToken: defaultPayload.replyToken,
34
- success: true,
35
- type: 'response',
36
- value: dValue,
37
- };
38
-
39
- const signature = {
40
- HMAC: getSignature(client, JSON.stringify(payload)),
41
- };
42
- return { header, payload, signature };
43
- };
44
-
45
- const handlePayload = (client, payload, signature, callbacks) => verifySignature(client, payload, signature)
46
- .then((action) => {
47
- /* eslint no-else-return: ["error", {allowElseIf: true}] */
48
- if (action === 'setPowerState') {
49
- return powerState(payload, callbacks)
50
- .then((value) => jsonResponse(client, payload, value))
51
- .catch((err) => {
52
- console.log(err.message);
53
- });
54
- } else if (action === 'setPowerLevel') {
55
- return powerLevel(payload, callbacks)
56
- .then((value) => jsonResponse(client, payload, value))
57
- .catch((err) => {
58
- console.log(err.message);
59
- });
60
- } else if (action === 'adjustPowerLevel') {
61
- return powerLevelAdjust(payload, callbacks)
62
- .then((value) => jsonResponse(client, payload, value))
63
- .catch((err) => {
64
- console.log(err.message);
65
- });
66
- } else if (action === 'setBrightness') {
67
- return Brightness(payload, callbacks)
68
- .then((value) => jsonResponse(client, payload, value))
69
- .catch((err) => {
70
- console.log(err.message);
71
- });
72
- } else if (action === 'adjustBrightness') {
73
- return BrightnessAdjust(payload, callbacks)
74
- .then((value) => jsonResponse(client, payload, value))
75
- .catch((err) => {
76
- console.log(err.message);
77
- });
78
- } else if (action === 'setColor') {
79
- return Color(payload, callbacks)
80
- .then((value) => jsonResponse(client, payload, value))
81
- .catch((err) => {
82
- console.log(err.message);
83
- });
84
- } else if (action === 'setColorTemperature') {
85
- return ColorTemperature(payload, callbacks)
86
- .then((value) => jsonResponse(client, payload, value))
87
- .catch((err) => {
88
- console.log(err.message);
89
- });
90
- } else if (action === 'setThermostatMode') {
91
- return ThermoStatMode(payload, callbacks)
92
- .then((value) => jsonResponse(client, payload, value))
93
- .catch((err) => {
94
- console.log(err.message);
95
- });
96
- } else if (action === 'targetTemperature') {
97
- return ThermoStatTemperature(payload, callbacks)
98
- .then((value) => jsonResponse(client, payload, value))
99
- .catch((err) => {
100
- console.log(err.message);
101
- });
102
- } else if (action === 'setRangeValue') {
103
- return RangeValue(payload, callbacks)
104
- .then((value) => jsonResponse(client, payload, value))
105
- .catch((err) => {
106
- console.log(err.message);
107
- });
108
- } else if (action === 'adjustRangeValue') {
109
- return RangeValueAdjust(payload, callbacks)
110
- .then((value) => jsonResponse(client, payload, value))
111
- .catch((err) => {
112
- console.log(err.message);
113
- });
114
- } else if (action === 'setVolume') {
115
- return Volume(payload, callbacks)
116
- .then((value) => jsonResponse(client, payload, value))
117
- .catch((err) => {
118
- console.log(err.message);
119
- });
120
- } else if (action === 'adjustVolume') {
121
- return VolumeAdjust(payload, callbacks)
122
- .then((value) => jsonResponse(client, payload, value))
123
- .catch((err) => {
124
- console.log(err.message);
125
- });
126
- } else if (action === 'selectInput') {
127
- return Input(payload, callbacks)
128
- .then((value) => jsonResponse(client, payload, value))
129
- .catch((err) => {
130
- console.log(err.message);
131
- });
132
- } else if (action === 'mediaControl') {
133
- return Media(payload, callbacks)
134
- .then((value) => jsonResponse(client, payload, value))
135
- .catch((err) => {
136
- console.log(err.message);
137
- });
138
- } else if (action === 'changeChannel') {
139
- return ChangeChannel(payload, callbacks)
140
- .then((value) => jsonResponse(client, payload, value))
141
- .catch((err) => {
142
- console.log(err.message);
143
- });
144
- } else if (action === 'skipChannels') {
145
- return SkipChannel(payload, callbacks)
146
- .then((value) => jsonResponse(client, payload, value))
147
- .catch((err) => {
148
- console.log(err.message);
149
- });
150
- } else if (action === 'setBands') {
151
- return Bands(payload, callbacks)
152
- .then((value) => jsonResponse(client, payload, value))
153
- .catch((err) => {
154
- console.log(err.message);
155
- });
156
- } else if (action === 'adjustBands') {
157
- return AdjustBands(payload, callbacks)
158
- .then((value) => jsonResponse(client, payload, value))
159
- .catch((err) => {
160
- console.log(err.message);
161
- });
162
- } else if (action === 'resetBands') {
163
- return BandReset(payload, callbacks)
164
- .then((value) => jsonResponse(client, payload, value))
165
- .catch((err) => {
166
- console.log(err.message);
167
- });
168
- } else if (action === 'setMode') {
169
- return Mode(payload, callbacks)
170
- .then((value) => jsonResponse(client, payload, value))
171
- .catch((err) => {
172
- console.log(err.message);
173
- });
174
- } else if (action === 'setLockState') {
175
- return Lock(payload, callbacks)
176
- .then((value) => jsonResponse(client, payload, value))
177
- .catch((err) => {
178
- console.log(err.message);
179
- });
180
- } else if (action === 'setMute') {
181
- return Mute(payload, callbacks)
182
- .then((value) => jsonResponse(client, payload, value))
183
- .catch((err) => {
184
- console.log(err.message);
185
- });
186
- }
187
- return {};
188
- })
189
- .catch((err) => {
190
- console.log(err.message);
191
- });
192
- module.exports = handlePayload;
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 { getSignature, verifySignature } = require('./signature');
9
+ const { powerState, powerLevel, powerLevelAdjust } = require('./contorllers/power_controller');
10
+ const { Brightness, BrightnessAdjust } = require('./contorllers/brightness_controller');
11
+ const { Color } = require('./contorllers/color_controller');
12
+ const { ColorTemperature } = require('./contorllers/color_temperature');
13
+ const { ThermoStatMode, ThermoStatTemperature, Lock } = require('./contorllers/sensors_controller');
14
+ const { RangeValue, RangeValueAdjust } = require('./contorllers/range_value_controller');
15
+ const { Volume, VolumeAdjust, Mute } = require('./contorllers/tv_controller');
16
+ const { ChangeChannel, SkipChannel, Media } = require('./contorllers/tv_controller');
17
+ const { Input } = require('./contorllers/tv_controller');
18
+ const { Bands, Mode, BandReset } = require('./contorllers/speaker_controller');
19
+ const { AdjustBands } = require('./contorllers/speaker_controller');
20
+ const { ToggleState } = require('./contorllers/toggle_state_controller');
21
+
22
+ const jsonResponse = (client, defaultPayload, dValue) => {
23
+ const header = {
24
+ payloadVersion: 2,
25
+ signatureVersion: 1,
26
+ };
27
+
28
+ const payload = {
29
+ action: defaultPayload.action,
30
+ clientId: defaultPayload.clientId,
31
+ createdAt: Math.floor(new Date() / 1000),
32
+ deviceId: defaultPayload.deviceId,
33
+ message: 'OK',
34
+ replyToken: defaultPayload.replyToken,
35
+ success: true,
36
+ type: 'response',
37
+ value: dValue,
38
+ };
39
+
40
+ const signature = {
41
+ HMAC: getSignature(client, JSON.stringify(payload)),
42
+ };
43
+ return { header, payload, signature };
44
+ };
45
+
46
+ const handlePayload = (client, payload, signature, callbacks) => verifySignature(client, payload, signature)
47
+ .then((action) => {
48
+ /* eslint no-else-return: ["error", {allowElseIf: true}] */
49
+ if (action === 'setPowerState') {
50
+ return powerState(payload, callbacks)
51
+ .then((value) => jsonResponse(client, payload, value))
52
+ .catch((err) => {
53
+ console.log(err.message);
54
+ });
55
+ } else if (action === 'setPowerLevel') {
56
+ return powerLevel(payload, callbacks)
57
+ .then((value) => jsonResponse(client, payload, value))
58
+ .catch((err) => {
59
+ console.log(err.message);
60
+ });
61
+ } else if (action === 'adjustPowerLevel') {
62
+ return powerLevelAdjust(payload, callbacks)
63
+ .then((value) => jsonResponse(client, payload, value))
64
+ .catch((err) => {
65
+ console.log(err.message);
66
+ });
67
+ } else if (action === 'setBrightness') {
68
+ return Brightness(payload, callbacks)
69
+ .then((value) => jsonResponse(client, payload, value))
70
+ .catch((err) => {
71
+ console.log(err.message);
72
+ });
73
+ } else if (action === 'adjustBrightness') {
74
+ return BrightnessAdjust(payload, callbacks)
75
+ .then((value) => jsonResponse(client, payload, value))
76
+ .catch((err) => {
77
+ console.log(err.message);
78
+ });
79
+ } else if (action === 'setColor') {
80
+ return Color(payload, callbacks)
81
+ .then((value) => jsonResponse(client, payload, value))
82
+ .catch((err) => {
83
+ console.log(err.message);
84
+ });
85
+ } else if (action === 'setColorTemperature') {
86
+ return ColorTemperature(payload, callbacks)
87
+ .then((value) => jsonResponse(client, payload, value))
88
+ .catch((err) => {
89
+ console.log(err.message);
90
+ });
91
+ } else if (action === 'setThermostatMode') {
92
+ return ThermoStatMode(payload, callbacks)
93
+ .then((value) => jsonResponse(client, payload, value))
94
+ .catch((err) => {
95
+ console.log(err.message);
96
+ });
97
+ } else if (action === 'targetTemperature') {
98
+ return ThermoStatTemperature(payload, callbacks)
99
+ .then((value) => jsonResponse(client, payload, value))
100
+ .catch((err) => {
101
+ console.log(err.message);
102
+ });
103
+ } else if (action === 'setRangeValue') {
104
+ return RangeValue(payload, callbacks)
105
+ .then((value) => jsonResponse(client, payload, value))
106
+ .catch((err) => {
107
+ console.log(err.message);
108
+ });
109
+ } else if (action === 'adjustRangeValue') {
110
+ return RangeValueAdjust(payload, callbacks)
111
+ .then((value) => jsonResponse(client, payload, value))
112
+ .catch((err) => {
113
+ console.log(err.message);
114
+ });
115
+ } else if (action === 'setVolume') {
116
+ return Volume(payload, callbacks)
117
+ .then((value) => jsonResponse(client, payload, value))
118
+ .catch((err) => {
119
+ console.log(err.message);
120
+ });
121
+ } else if (action === 'adjustVolume') {
122
+ return VolumeAdjust(payload, callbacks)
123
+ .then((value) => jsonResponse(client, payload, value))
124
+ .catch((err) => {
125
+ console.log(err.message);
126
+ });
127
+ } else if (action === 'selectInput') {
128
+ return Input(payload, callbacks)
129
+ .then((value) => jsonResponse(client, payload, value))
130
+ .catch((err) => {
131
+ console.log(err.message);
132
+ });
133
+ } else if (action === 'mediaControl') {
134
+ return Media(payload, callbacks)
135
+ .then((value) => jsonResponse(client, payload, value))
136
+ .catch((err) => {
137
+ console.log(err.message);
138
+ });
139
+ } else if (action === 'changeChannel') {
140
+ return ChangeChannel(payload, callbacks)
141
+ .then((value) => jsonResponse(client, payload, value))
142
+ .catch((err) => {
143
+ console.log(err.message);
144
+ });
145
+ } else if (action === 'skipChannels') {
146
+ return SkipChannel(payload, callbacks)
147
+ .then((value) => jsonResponse(client, payload, value))
148
+ .catch((err) => {
149
+ console.log(err.message);
150
+ });
151
+ } else if (action === 'setBands') {
152
+ return Bands(payload, callbacks)
153
+ .then((value) => jsonResponse(client, payload, value))
154
+ .catch((err) => {
155
+ console.log(err.message);
156
+ });
157
+ } else if (action === 'adjustBands') {
158
+ return AdjustBands(payload, callbacks)
159
+ .then((value) => jsonResponse(client, payload, value))
160
+ .catch((err) => {
161
+ console.log(err.message);
162
+ });
163
+ } else if (action === 'resetBands') {
164
+ return BandReset(payload, callbacks)
165
+ .then((value) => jsonResponse(client, payload, value))
166
+ .catch((err) => {
167
+ console.log(err.message);
168
+ });
169
+ } else if (action === 'setMode') {
170
+ return Mode(payload, callbacks)
171
+ .then((value) => jsonResponse(client, payload, value))
172
+ .catch((err) => {
173
+ console.log(err.message);
174
+ });
175
+ } else if (action === 'setLockState') {
176
+ return Lock(payload, callbacks)
177
+ .then((value) => jsonResponse(client, payload, value))
178
+ .catch((err) => {
179
+ console.log(err.message);
180
+ });
181
+ } else if (action === 'setMute') {
182
+ return Mute(payload, callbacks)
183
+ .then((value) => jsonResponse(client, payload, value))
184
+ .catch((err) => {
185
+ console.log(err.message);
186
+ });
187
+ } else if (action === 'setToggleState') {
188
+ return ToggleState(payload, callbacks)
189
+ .then((value) => jsonResponse(client, payload, value))
190
+ .catch((err) => {
191
+ console.log(err.message);
192
+ });
193
+ }
194
+ return {};
195
+ })
196
+ .catch((err) => {
197
+ console.log(err.message);
198
+ });
199
+ module.exports = handlePayload;
@@ -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 };
@@ -0,0 +1,18 @@
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 ToggleState = (payload, callbacks) => {
9
+ const resp = callbacks.setToggleState(payload.deviceId, { instanceId: payload.instanceId, value: payload.value.state });
10
+ return new Promise((resolve, reject) => {
11
+ if (resp) resolve(payload);
12
+ else reject(new Error('Toggle State Error'));
13
+ });
14
+ };
15
+
16
+ module.exports = {
17
+ ToggleState
18
+ };
@@ -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 ?? payload.value.channel.number;
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
@@ -1,122 +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
-
15
- const VERSION = "2.2.2";
16
-
17
- class SinricPro extends Websocket {
18
- constructor(appkey, deviceids, secretKey, restoreStates) {
19
- super("ws://ws.sinric.pro", {
20
- headers: {
21
- appkey,
22
- deviceids: deviceids.join(";"),
23
- platform: "nodejs",
24
- version: VERSION,
25
- restoredevicestates: restoreStates,
26
- },
27
- });
28
- this._secretKey = secretKey;
29
- }
30
-
31
- get getSecretKey() {
32
- return this._secretKey;
33
- }
34
-
35
- set setSecretKey(key) {
36
- this._secretKey = key;
37
- }
38
- }
39
-
40
- const SinricProActions = (client, callbacks) => {
41
- client.on("open", () => {
42
- console.log("Connected to Sinric Pro");
43
- });
44
-
45
- client.on("message", (data) => {
46
- const parsedData = JSON.parse(data);
47
-
48
- if (parsedData.timestamp) {
49
- if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
50
- console.log("Timestamp is not in sync");
51
- } else console.log("TimeStamp is in sync");
52
- } else {
53
- const response = callbackHandler(
54
- client,
55
- parsedData.payload,
56
- parsedData.signature.HMAC,
57
- callbacks,
58
- );
59
- response
60
- .then((res) => {
61
- client.send(JSON.stringify(res));
62
- })
63
- .catch((err) => {
64
- console.log(err.message);
65
- });
66
- }
67
- });
68
-
69
- client.on("close", () => {
70
- if (callbacks.onDisconnect) {
71
- callbacks.onDisconnect();
72
- }
73
- });
74
- };
75
-
76
- const SinricProActionsObservable = (client, callbacks) => new rx.Observable((observer) => {
77
- client.on("open", () => {
78
- console.log("Connected");
79
- });
80
-
81
- client.on("message", (data) => {
82
- const parsedData = JSON.parse(data);
83
- if (parsedData.timestamp) {
84
- if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
85
- console.log("Timestamp is not in sync");
86
- } else console.log("TimeStamp is in sync");
87
- } else {
88
- const response = callbackHandler(
89
- client,
90
- parsedData.payload,
91
- parsedData.signature.HMAC,
92
- callbacks,
93
- );
94
- response
95
- .then((res) => {
96
- observer.next(res);
97
- client.send(JSON.stringify(res));
98
- })
99
- .catch((err) => {
100
- observer.error(err.message);
101
- console.log(err.message);
102
- });
103
- }
104
- });
105
-
106
- client.on("close", () => {
107
- observer.complete();
108
- if (callbacks.onDisconnect) {
109
- callbacks.onDisconnect();
110
- }
111
- console.log("Disconnected");
112
- });
113
- });
114
-
115
- module.exports = {
116
- SinricPro,
117
- SinricProActions,
118
- SinricProActionsObservable,
119
- raiseEvent,
120
- eventNames,
121
- SinricProUdp,
122
- };
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/lib/storage.js CHANGED
@@ -15,7 +15,7 @@ let data = {
15
15
  lockState: '',
16
16
  thermostat: {
17
17
  mode: '',
18
- temperature: 0
18
+ temperature: 0,
19
19
  },
20
20
  rangeValue: 0,
21
21
  volume: 0,
@@ -0,0 +1,6 @@
1
+ Switch to Login module (by typing "how-to-npm" on command line)
2
+ Type "npm adduser" to login
3
+ Type "npm whoami" to confirm if logged in
4
+ Switch back to the package at which you are getting error(my case it was Publish Again)
5
+ Type "npm publish"
6
+ Done
package/package.json CHANGED
@@ -1,42 +1,38 @@
1
- {
2
- "name": "sinricpro",
3
- "version": "2.2.8",
4
- "description": "Sinric Pro Nodejs SDK",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1",
8
- "lint": "eslint --fix ./"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/sinricpro/nodejs-sdk.git"
13
- },
14
- "author": "Dhanush",
15
- "license": "ISC",
16
- "bugs": {
17
- "url": "https://github.com/sinricpro/nodejs-sdk/issues"
18
- },
19
- "homepage": "https://github.com/sinricpro/nodejs-sdk#readme",
20
- "dependencies": {
21
- "dgram": "^1.0.1",
22
- "leaky-bucket": "^3.0.4",
23
- "process": "^0.11.10",
24
- "rate-limiter-flexible": "^2.2.1",
25
- "rxjs": "^6.6.3",
26
- "uuid": "^3.3.3",
27
- "ws": "^7.4.2"
28
- },
29
- "keywords": [
30
- "sinricpro",
31
- "sinric"
32
- ],
33
- "devDependencies": {
34
- "eslint": "^6.8.0",
35
- "eslint-config-airbnb-base": "^14.0.0",
36
- "eslint-config-standard": "^14.1.0",
37
- "eslint-plugin-import": "^2.18.2",
38
- "eslint-plugin-node": "^10.0.0",
39
- "eslint-plugin-promise": "^4.2.1",
40
- "eslint-plugin-standard": "^4.0.1"
41
- }
42
- }
1
+ {
2
+ "name": "sinricpro",
3
+ "version": "2.5.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": "^8.9.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
+ }