sinricpro 2.5.1 → 2.6.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.
@@ -1,32 +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}}
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/CHANGELOG.md ADDED
@@ -0,0 +1,6 @@
1
+ ## [2.6.1]
2
+
3
+ ### Features
4
+
5
+ * **Custom device types support**
6
+ * **SR_DEBUG to support debug logs**
package/README.md CHANGED
@@ -1,15 +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
- ### Examples
15
- Check the examples [here](https://github.com/sinricpro/nodejs-sdk/tree/master/examples)
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,199 +1,202 @@
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
+ /*
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, BandReset } = require('./contorllers/speaker_controller');
19
+ const { AdjustBands } = require('./contorllers/speaker_controller');
20
+ const { ToggleState } = require('./contorllers/toggle_state_controller');
21
+ const { Mode } = require('./contorllers/mode_controller');
22
+
23
+ const jsonResponse = (client, defaultPayload, payloadValue, instanceId) => {
24
+ const header = {
25
+ payloadVersion: 2,
26
+ signatureVersion: 1,
27
+ };
28
+
29
+ let payload = {
30
+ action: defaultPayload.action,
31
+ clientId: defaultPayload.clientId,
32
+ createdAt: Math.floor(new Date() / 1000),
33
+ deviceId: defaultPayload.deviceId,
34
+ message: 'OK',
35
+ replyToken: defaultPayload.replyToken,
36
+ success: true,
37
+ type: 'response',
38
+ value: payloadValue,
39
+ };
40
+
41
+ if(instanceId) payload.instanceId = instanceId;
42
+
43
+ const signature = {
44
+ HMAC: getSignature(client, JSON.stringify(payload)),
45
+ };
46
+ return { header, payload, signature };
47
+ };
48
+
49
+ const handlePayload = (client, payload, signature, callbacks) => verifySignature(client, payload, signature)
50
+ .then((action) => {
51
+ /* eslint no-else-return: ["error", {allowElseIf: true}] */
52
+ if (action === 'setPowerState') {
53
+ return powerState(payload, callbacks)
54
+ .then((value) => jsonResponse(client, payload, value))
55
+ .catch((err) => {
56
+ if (process.env.SR_DEBUG) console.log(err.message);
57
+ });
58
+ } else if (action === 'setPowerLevel') {
59
+ return powerLevel(payload, callbacks)
60
+ .then((value) => jsonResponse(client, payload, value))
61
+ .catch((err) => {
62
+ if (process.env.SR_DEBUG) console.log(err.message);
63
+ });
64
+ } else if (action === 'adjustPowerLevel') {
65
+ return powerLevelAdjust(payload, callbacks)
66
+ .then((value) => jsonResponse(client, payload, value))
67
+ .catch((err) => {
68
+ if (process.env.SR_DEBUG) console.log(err.message);
69
+ });
70
+ } else if (action === 'setBrightness') {
71
+ return Brightness(payload, callbacks)
72
+ .then((value) => jsonResponse(client, payload, value))
73
+ .catch((err) => {
74
+ if (process.env.SR_DEBUG) console.log(err.message);
75
+ });
76
+ } else if (action === 'adjustBrightness') {
77
+ return BrightnessAdjust(payload, callbacks)
78
+ .then((value) => jsonResponse(client, payload, value))
79
+ .catch((err) => {
80
+ if (process.env.SR_DEBUG) console.log(err.message);
81
+ });
82
+ } else if (action === 'setColor') {
83
+ return Color(payload, callbacks)
84
+ .then((value) => jsonResponse(client, payload, value))
85
+ .catch((err) => {
86
+ if (process.env.SR_DEBUG) console.log(err.message);
87
+ });
88
+ } else if (action === 'setColorTemperature') {
89
+ return ColorTemperature(payload, callbacks)
90
+ .then((value) => jsonResponse(client, payload, value))
91
+ .catch((err) => {
92
+ if (process.env.SR_DEBUG) console.log(err.message);
93
+ });
94
+ } else if (action === 'setThermostatMode') {
95
+ return ThermoStatMode(payload, callbacks)
96
+ .then((value) => jsonResponse(client, payload, value))
97
+ .catch((err) => {
98
+ if (process.env.SR_DEBUG) console.log(err.message);
99
+ });
100
+ } else if (action === 'targetTemperature') {
101
+ return ThermoStatTemperature(payload, callbacks)
102
+ .then((value) => jsonResponse(client, payload, value))
103
+ .catch((err) => {
104
+ if (process.env.SR_DEBUG) console.log(err.message);
105
+ });
106
+ } else if (action === 'setRangeValue') {
107
+ return RangeValue(payload, callbacks)
108
+ .then(([value, instanceId]) => jsonResponse(client, payload, value, instanceId))
109
+ .catch((err) => {
110
+ if (process.env.SR_DEBUG) console.log(err.message);
111
+ });
112
+ } else if (action === 'adjustRangeValue') {
113
+ return RangeValueAdjust(payload, callbacks)
114
+ .then(([value, instanceId]) => jsonResponse(client, payload, value, instanceId))
115
+ .catch((err) => {
116
+ if (process.env.SR_DEBUG) console.log(err.message);
117
+ });
118
+ } else if (action === 'setVolume') {
119
+ return Volume(payload, callbacks)
120
+ .then((value) => jsonResponse(client, payload, value))
121
+ .catch((err) => {
122
+ if (process.env.SR_DEBUG) console.log(err.message);
123
+ });
124
+ } else if (action === 'adjustVolume') {
125
+ return VolumeAdjust(payload, callbacks)
126
+ .then((value) => jsonResponse(client, payload, value))
127
+ .catch((err) => {
128
+ if (process.env.SR_DEBUG) console.log(err.message);
129
+ });
130
+ } else if (action === 'selectInput') {
131
+ return Input(payload, callbacks)
132
+ .then((value) => jsonResponse(client, payload, value))
133
+ .catch((err) => {
134
+ if (process.env.SR_DEBUG) console.log(err.message);
135
+ });
136
+ } else if (action === 'mediaControl') {
137
+ return Media(payload, callbacks)
138
+ .then((value) => jsonResponse(client, payload, value))
139
+ .catch((err) => {
140
+ if (process.env.SR_DEBUG) console.log(err.message);
141
+ });
142
+ } else if (action === 'changeChannel') {
143
+ return ChangeChannel(payload, callbacks)
144
+ .then((value) => jsonResponse(client, payload, value))
145
+ .catch((err) => {
146
+ if (process.env.SR_DEBUG) console.log(err.message);
147
+ });
148
+ } else if (action === 'skipChannels') {
149
+ return SkipChannel(payload, callbacks)
150
+ .then((value) => jsonResponse(client, payload, value))
151
+ .catch((err) => {
152
+ if (process.env.SR_DEBUG) console.log(err.message);
153
+ });
154
+ } else if (action === 'setBands') {
155
+ return Bands(payload, callbacks)
156
+ .then((value) => jsonResponse(client, payload, value))
157
+ .catch((err) => {
158
+ if (process.env.SR_DEBUG) console.log(err.message);
159
+ });
160
+ } else if (action === 'adjustBands') {
161
+ return AdjustBands(payload, callbacks)
162
+ .then((value) => jsonResponse(client, payload, value))
163
+ .catch((err) => {
164
+ if (process.env.SR_DEBUG) console.log(err.message);
165
+ });
166
+ } else if (action === 'resetBands') {
167
+ return BandReset(payload, callbacks)
168
+ .then((value) => jsonResponse(client, payload, value))
169
+ .catch((err) => {
170
+ if (process.env.SR_DEBUG) console.log(err.message);
171
+ });
172
+ } else if (action === 'setMode') {
173
+ return Mode(payload, callbacks)
174
+ .then(([value, instanceId]) => jsonResponse(client, payload, value, instanceId))
175
+ .catch((err) => {
176
+ if (process.env.SR_DEBUG) console.log(err.message);
177
+ });
178
+ } else if (action === 'setLockState') {
179
+ return Lock(payload, callbacks)
180
+ .then((value) => jsonResponse(client, payload, value))
181
+ .catch((err) => {
182
+ if (process.env.SR_DEBUG) console.log(err.message);
183
+ });
184
+ } else if (action === 'setMute') {
185
+ return Mute(payload, callbacks)
186
+ .then((value) => jsonResponse(client, payload, value))
187
+ .catch((err) => {
188
+ if (process.env.SR_DEBUG) console.log(err.message);
189
+ });
190
+ } else if (action === 'setToggleState') {
191
+ return ToggleState(payload, callbacks)
192
+ .then(([value, instanceId]) => jsonResponse(client, payload, value, instanceId))
193
+ .catch((err) => {
194
+ if (process.env.SR_DEBUG) console.log(err.message);
195
+ });
196
+ }
197
+ return {};
198
+ })
199
+ .catch((err) => {
200
+ console.error(err.message);
201
+ });
202
+ module.exports = handlePayload;
@@ -0,0 +1,21 @@
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 sinricData = require('../storage');
9
+
10
+ const Mode = (payload, callbacks) => {
11
+ const resp = callbacks.setMode(payload.deviceId, payload.value.mode, payload.instanceId);
12
+
13
+ return new Promise((resolve, reject) => {
14
+ if (resp) resolve([payload.value, payload.instanceId]);
15
+ else reject(new Error('Mode undefined'));
16
+ });
17
+ };
18
+
19
+ module.exports = {
20
+ Mode
21
+ };
@@ -1,32 +1,36 @@
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 };
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 sinricProData = require('../storage');
9
+
10
+ const RangeValue = (payload, callbacks) => {
11
+ sinricProData.rangeValue = payload.value.rangeValue;
12
+
13
+ const resp = callbacks.setRangeValue(payload.deviceId, sinricProData.rangeValue, payload.instanceId);
14
+
15
+ return new Promise((resolve, reject) => {
16
+ if (payload.value.rangeValue !== undefined && resp) resolve([payload.value, payload.instanceId]);
17
+ else reject(new Error('RangeValue is undefined'));
18
+ });
19
+ };
20
+
21
+ const RangeValueAdjust = (payload, callbacks) => {
22
+ sinricProData.rangeValue += payload.value.rangeValueDelta;
23
+
24
+ if (sinricProData.rangeValue < 0) sinricProData.rangeValue = 0;
25
+ else if (sinricProData.rangeValue > 100) sinricProData.rangeValue = 100;
26
+
27
+ const resp = callbacks.adjustRangeValue(payload.deviceId, sinricProData.rangeValue, payload.instanceId);
28
+
29
+ return new Promise((resolve, reject) => {
30
+ if (payload.value.rangeValueDelta && resp) resolve([{ rangeValue: sinricProData.rangeValue }, payload.instanceId]);
31
+ else reject(new Error('RangeValue undefined'));
32
+ });
33
+ };
34
+
35
+
36
+ module.exports = { RangeValue, RangeValueAdjust };
@@ -18,14 +18,6 @@ const Bands = (payload, callbacks) => {
18
18
  });
19
19
  };
20
20
 
21
- const Mode = (payload, callbacks) => {
22
- const resp = callbacks.setMode(payload.deviceId, payload.value.mode);
23
- return new Promise((resolve, reject) => {
24
- if (resp) resolve(payload.value);
25
- else reject(new Error('Mode undefined'));
26
- });
27
- };
28
-
29
21
  const BandReset = (payload, callbacks) => {
30
22
  const resp = callbacks.resetBands(payload.deviceId, payload.value);
31
23
  return new Promise((resolve, reject) => {
@@ -45,6 +37,7 @@ const AdjustBands = (payload, callbacks) => {
45
37
  else reject(new Error('Rest Bands Failed'));
46
38
  });
47
39
  };
40
+
48
41
  module.exports = {
49
- Bands, Mode, BandReset, AdjustBands,
42
+ Bands, BandReset, AdjustBands,
50
43
  };
@@ -1,18 +1,19 @@
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
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, payload.value.state, payload.instanceId);
10
+
11
+ return new Promise((resolve, reject) => {
12
+ if (resp) resolve([payload.value, payload.instanceId]);
13
+ else reject(new Error('Toggle State Error'));
14
+ });
15
+ };
16
+
17
+ module.exports = {
18
+ ToggleState
18
19
  };
@@ -86,7 +86,9 @@ const raiseEvent = async (client, eventName, deviceId, value) => {
86
86
  if (actionArr.includes(eventName)) {
87
87
  try {
88
88
  await burstyLimiter.consume('queue');
89
- client.send(JSON.stringify(getJson(client, eventName, deviceId, value)));
89
+ const request = JSON.stringify(getJson(client, eventName, deviceId, value));
90
+ if (process.env.SR_DEBUG) console.log('>> %j', request);
91
+ client.send(request);
90
92
  } catch (rlRejected) {
91
93
  console.log('Too many events!');
92
94
  }
package/lib/sinrcpro.js CHANGED
@@ -1,121 +1,127 @@
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
+ if (process.env.SR_DEBUG) console.log('<< %s', data.toString());
46
+
47
+ const parsedData = JSON.parse(data);
48
+
49
+ if (parsedData.timestamp) {
50
+ if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
51
+ if (process.env.SR_DEBUG) console.log("Timestamp is not in sync");
52
+ } else if (process.env.SR_DEBUG) console.log("TimeStamp is in sync");
53
+ } else {
54
+ const response = callbackHandler(
55
+ client,
56
+ parsedData.payload,
57
+ parsedData.signature.HMAC,
58
+ callbacks,
59
+ );
60
+ response
61
+ .then((res) => {
62
+ const reqResponse = JSON.stringify(res);
63
+ if (process.env.SR_DEBUG) console.log('>> %s', reqResponse);
64
+ client.send(reqResponse);
65
+ })
66
+ .catch((err) => {
67
+ console.log(err.message);
68
+ });
69
+ }
70
+ });
71
+
72
+ client.on("close", () => {
73
+ if (callbacks.onDisconnect) {
74
+ callbacks.onDisconnect();
75
+ }
76
+ });
77
+ };
78
+
79
+ const startSinricProObservable = (client, callbacks) => new rx.Observable((observer) => {
80
+ client.on('open', () => {
81
+ console.log('Connected to Sinric Pro');
82
+ });
83
+
84
+ client.on("message", (data) => {
85
+ const parsedData = JSON.parse(data);
86
+ if (parsedData.timestamp) {
87
+ if (Math.floor(new Date() / 1000) - parsedData.timestamp > 60000) {
88
+ if (process.env.SR_DEBUG) console.log("Timestamp is not in sync");
89
+ } else if (process.env.SR_DEBUG) console.log("TimeStamp is in sync");
90
+ } else {
91
+ const response = callbackHandler(
92
+ client,
93
+ parsedData.payload,
94
+ parsedData.signature.HMAC,
95
+ callbacks,
96
+ );
97
+ response
98
+ .then((res) => {
99
+ observer.next(res);
100
+ const reqResponse = JSON.stringify(res);
101
+ if (process.env.SR_DEBUG) console.log('>> %s', reqResponse);
102
+ client.send(reqResponse);
103
+ })
104
+ .catch((err) => {
105
+ observer.error(err.message);
106
+ console.log(err.message);
107
+ });
108
+ }
109
+ });
110
+
111
+ client.on("close", () => {
112
+ observer.complete();
113
+ if (callbacks.onDisconnect) {
114
+ callbacks.onDisconnect();
115
+ }
116
+ console.log("Disconnected");
117
+ });
118
+ });
119
+
120
+ module.exports = {
121
+ SinricPro,
122
+ startSinricPro,
123
+ startSinricProObservable,
124
+ raiseEvent,
125
+ eventNames,
126
+ SinricProUdp,
127
+ };
package/package.json CHANGED
@@ -1,38 +1,37 @@
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
- }
1
+ {
2
+ "name": "sinricpro",
3
+ "version": "2.6.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": "SinricPro",
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
+ "process": "^0.11.10",
19
+ "rate-limiter-flexible": "^2.3.6",
20
+ "rxjs": "^6.6.3",
21
+ "uuid": "^3.3.3",
22
+ "ws": "^8.5.0"
23
+ },
24
+ "keywords": [
25
+ "sinricpro",
26
+ "sinric"
27
+ ],
28
+ "devDependencies": {
29
+ "eslint": "^8.9.0",
30
+ "eslint-config-airbnb-base": "^14.0.0",
31
+ "eslint-config-standard": "^14.1.0",
32
+ "eslint-plugin-import": "^2.18.2",
33
+ "eslint-plugin-node": "^10.0.0",
34
+ "eslint-plugin-promise": "^4.2.1",
35
+ "eslint-plugin-standard": "^4.0.1"
36
+ }
37
+ }