@@ -15,17 +15,18 @@ const { RangeValue, RangeValueAdjust } = require('./contorllers/range_value_cont
15
15
const { Volume, VolumeAdjust, Mute } = require ( './contorllers/tv_controller' ) ;
16
16
const { ChangeChannel, SkipChannel, Media } = require ( './contorllers/tv_controller' ) ;
17
17
const { Input } = require ( './contorllers/tv_controller' ) ;
18
- const { Bands, Mode , BandReset } = require ( './contorllers/speaker_controller' ) ;
18
+ const { Bands, BandReset } = require ( './contorllers/speaker_controller' ) ;
19
19
const { AdjustBands } = require ( './contorllers/speaker_controller' ) ;
20
20
const { ToggleState } = require ( './contorllers/toggle_state_controller' ) ;
21
+ const { Mode } = require ( './contorllers/mode_controller' ) ;
21
22
22
- const jsonResponse = ( client , defaultPayload , dValue ) => {
23
+ const jsonResponse = ( client , defaultPayload , payloadValue , instanceId ) => {
23
24
const header = {
24
25
payloadVersion : 2 ,
25
26
signatureVersion : 1 ,
26
27
} ;
27
28
28
- const payload = {
29
+ let payload = {
29
30
action : defaultPayload . action ,
30
31
clientId : defaultPayload . clientId ,
31
32
createdAt : Math . floor ( new Date ( ) / 1000 ) ,
@@ -34,9 +35,11 @@ const jsonResponse = (client, defaultPayload, dValue) => {
34
35
replyToken : defaultPayload . replyToken ,
35
36
success : true ,
36
37
type : 'response' ,
37
- value : dValue ,
38
+ value : payloadValue ,
38
39
} ;
39
40
41
+ if ( instanceId ) payload . instanceId = instanceId ;
42
+
40
43
const signature = {
41
44
HMAC : getSignature ( client , JSON . stringify ( payload ) ) ,
42
45
} ;
@@ -50,150 +53,150 @@ const handlePayload = (client, payload, signature, callbacks) => verifySignature
50
53
return powerState ( payload , callbacks )
51
54
. then ( ( value ) => jsonResponse ( client , payload , value ) )
52
55
. catch ( ( err ) => {
53
- console . log ( err . message ) ;
56
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
54
57
} ) ;
55
58
} else if ( action === 'setPowerLevel' ) {
56
59
return powerLevel ( payload , callbacks )
57
60
. then ( ( value ) => jsonResponse ( client , payload , value ) )
58
61
. catch ( ( err ) => {
59
- console . log ( err . message ) ;
62
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
60
63
} ) ;
61
64
} else if ( action === 'adjustPowerLevel' ) {
62
65
return powerLevelAdjust ( payload , callbacks )
63
66
. then ( ( value ) => jsonResponse ( client , payload , value ) )
64
67
. catch ( ( err ) => {
65
- console . log ( err . message ) ;
68
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
66
69
} ) ;
67
70
} else if ( action === 'setBrightness' ) {
68
71
return Brightness ( payload , callbacks )
69
72
. then ( ( value ) => jsonResponse ( client , payload , value ) )
70
73
. catch ( ( err ) => {
71
- console . log ( err . message ) ;
74
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
72
75
} ) ;
73
76
} else if ( action === 'adjustBrightness' ) {
74
77
return BrightnessAdjust ( payload , callbacks )
75
78
. then ( ( value ) => jsonResponse ( client , payload , value ) )
76
79
. catch ( ( err ) => {
77
- console . log ( err . message ) ;
80
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
78
81
} ) ;
79
82
} else if ( action === 'setColor' ) {
80
83
return Color ( payload , callbacks )
81
84
. then ( ( value ) => jsonResponse ( client , payload , value ) )
82
85
. catch ( ( err ) => {
83
- console . log ( err . message ) ;
86
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
84
87
} ) ;
85
88
} else if ( action === 'setColorTemperature' ) {
86
89
return ColorTemperature ( payload , callbacks )
87
90
. then ( ( value ) => jsonResponse ( client , payload , value ) )
88
91
. catch ( ( err ) => {
89
- console . log ( err . message ) ;
92
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
90
93
} ) ;
91
94
} else if ( action === 'setThermostatMode' ) {
92
95
return ThermoStatMode ( payload , callbacks )
93
96
. then ( ( value ) => jsonResponse ( client , payload , value ) )
94
97
. catch ( ( err ) => {
95
- console . log ( err . message ) ;
98
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
96
99
} ) ;
97
100
} else if ( action === 'targetTemperature' ) {
98
101
return ThermoStatTemperature ( payload , callbacks )
99
102
. then ( ( value ) => jsonResponse ( client , payload , value ) )
100
103
. catch ( ( err ) => {
101
- console . log ( err . message ) ;
104
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
102
105
} ) ;
103
106
} else if ( action === 'setRangeValue' ) {
104
107
return RangeValue ( payload , callbacks )
105
- . then ( ( value ) => jsonResponse ( client , payload , value ) )
108
+ . then ( ( [ value , instanceId ] ) => jsonResponse ( client , payload , value , instanceId ) )
106
109
. catch ( ( err ) => {
107
- console . log ( err . message ) ;
110
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
108
111
} ) ;
109
112
} else if ( action === 'adjustRangeValue' ) {
110
113
return RangeValueAdjust ( payload , callbacks )
111
- . then ( ( value ) => jsonResponse ( client , payload , value ) )
114
+ . then ( ( [ value , instanceId ] ) => jsonResponse ( client , payload , value , instanceId ) )
112
115
. catch ( ( err ) => {
113
- console . log ( err . message ) ;
116
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
114
117
} ) ;
115
118
} else if ( action === 'setVolume' ) {
116
119
return Volume ( payload , callbacks )
117
120
. then ( ( value ) => jsonResponse ( client , payload , value ) )
118
121
. catch ( ( err ) => {
119
- console . log ( err . message ) ;
122
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
120
123
} ) ;
121
124
} else if ( action === 'adjustVolume' ) {
122
125
return VolumeAdjust ( payload , callbacks )
123
126
. then ( ( value ) => jsonResponse ( client , payload , value ) )
124
127
. catch ( ( err ) => {
125
- console . log ( err . message ) ;
128
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
126
129
} ) ;
127
130
} else if ( action === 'selectInput' ) {
128
131
return Input ( payload , callbacks )
129
132
. then ( ( value ) => jsonResponse ( client , payload , value ) )
130
133
. catch ( ( err ) => {
131
- console . log ( err . message ) ;
134
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
132
135
} ) ;
133
136
} else if ( action === 'mediaControl' ) {
134
137
return Media ( payload , callbacks )
135
138
. then ( ( value ) => jsonResponse ( client , payload , value ) )
136
139
. catch ( ( err ) => {
137
- console . log ( err . message ) ;
140
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
138
141
} ) ;
139
142
} else if ( action === 'changeChannel' ) {
140
143
return ChangeChannel ( payload , callbacks )
141
144
. then ( ( value ) => jsonResponse ( client , payload , value ) )
142
145
. catch ( ( err ) => {
143
- console . log ( err . message ) ;
146
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
144
147
} ) ;
145
148
} else if ( action === 'skipChannels' ) {
146
149
return SkipChannel ( payload , callbacks )
147
150
. then ( ( value ) => jsonResponse ( client , payload , value ) )
148
151
. catch ( ( err ) => {
149
- console . log ( err . message ) ;
152
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
150
153
} ) ;
151
154
} else if ( action === 'setBands' ) {
152
155
return Bands ( payload , callbacks )
153
156
. then ( ( value ) => jsonResponse ( client , payload , value ) )
154
157
. catch ( ( err ) => {
155
- console . log ( err . message ) ;
158
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
156
159
} ) ;
157
160
} else if ( action === 'adjustBands' ) {
158
161
return AdjustBands ( payload , callbacks )
159
162
. then ( ( value ) => jsonResponse ( client , payload , value ) )
160
163
. catch ( ( err ) => {
161
- console . log ( err . message ) ;
164
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
162
165
} ) ;
163
166
} else if ( action === 'resetBands' ) {
164
167
return BandReset ( payload , callbacks )
165
168
. then ( ( value ) => jsonResponse ( client , payload , value ) )
166
169
. catch ( ( err ) => {
167
- console . log ( err . message ) ;
170
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
168
171
} ) ;
169
172
} else if ( action === 'setMode' ) {
170
173
return Mode ( payload , callbacks )
171
- . then ( ( value ) => jsonResponse ( client , payload , value ) )
174
+ . then ( ( [ value , instanceId ] ) => jsonResponse ( client , payload , value , instanceId ) )
172
175
. catch ( ( err ) => {
173
- console . log ( err . message ) ;
176
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
174
177
} ) ;
175
178
} else if ( action === 'setLockState' ) {
176
179
return Lock ( payload , callbacks )
177
180
. then ( ( value ) => jsonResponse ( client , payload , value ) )
178
181
. catch ( ( err ) => {
179
- console . log ( err . message ) ;
182
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
180
183
} ) ;
181
184
} else if ( action === 'setMute' ) {
182
185
return Mute ( payload , callbacks )
183
186
. then ( ( value ) => jsonResponse ( client , payload , value ) )
184
187
. catch ( ( err ) => {
185
- console . log ( err . message ) ;
188
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
186
189
} ) ;
187
190
} else if ( action === 'setToggleState' ) {
188
191
return ToggleState ( payload , callbacks )
189
- . then ( ( value ) => jsonResponse ( client , payload , value ) )
192
+ . then ( ( [ value , instanceId ] ) => jsonResponse ( client , payload , value , instanceId ) )
190
193
. catch ( ( err ) => {
191
- console . log ( err . message ) ;
194
+ if ( process . env . SR_DEBUG ) console . log ( err . message ) ;
192
195
} ) ;
193
196
}
194
197
return { } ;
195
198
} )
196
199
. catch ( ( err ) => {
197
- console . log ( err . message ) ;
200
+ console . error ( err . message ) ;
198
201
} ) ;
199
202
module . exports = handlePayload ;
0 commit comments