-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (32 loc) · 1.35 KB
/
index.js
1
2
3
4
5
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
35
36
37
38
39
40
41
const log = require('./utils/logger');
const reportState = require('./handlers/report-state');
const discover = require('./handlers/discovery');
const turnOnOff = require('./handlers/turn-on-off');
const setBrightness = require('./handlers/set-brightness');
const adjustBrightness = require('./handlers/adjust-brightness');
exports.handler = async (event) => {
log("EVENT:", event);
let type = event.directive.header.name;
let response = await actOnType(type, event);
log("RESPONSE:", response);
return response;
};
async function actOnType(type, event){
let payload;
switch(type){
case 'Discover': payload = await discover(event); break;
case 'ReportState': payload = await reportState(event); break;
case 'AcceptGrant': payload = await acceptGrant(event); break;
case 'AdjustBrightness': payload = await adjustBrightness(event); break;
case 'SetBrightness': payload = await setBrightness(event); break;
case 'TurnOff': payload = await turnOnOff(event, 'OFF'); break;
case 'TurnOn': payload = await turnOnOff(event, 'ON'); break;
default: payload = event; break;
}
return payload;
}
function acceptGrant(event){
let header = event.directive.header;
header.name = 'AcceptGrant.Response';
return { event: { header: header, payload: {} } };
}