-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhue.js
67 lines (60 loc) · 1.42 KB
/
hue.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { validateStates, parseDefault, getRoom } from '../adapters';
import _rfdc from 'rfdc/default';
export default 'hue'
export const namespace = 'hue'
export const deviceObjectType = 'channel';
/*
* State Mapping
*/
const STATE_MAPPING = {
// lights
"light": {
"power": {
"state": ".on",
"action": ".on"
},
"level": {
"state": ".level",
"action": ".level"
},
"colorTemperature": {
"state": ".ct",
"action": ".ct"
},
"hue": {
"state": ".hue",
"action": ".hue"
},
"reachability": {
"state": ".reachable"
}
}
}
/**
*
*
* @param {Object} deviceStructure
* @param {String} deviceStructure.root root state
* @param {Array} deviceStructure.states all states
* @param {Object} deviceStructure.values all states with its value
* @return {Object} device
*/
export function parse(deviceStructure, options) {
return new Promise(resolve => {
const device = {
'name': deviceStructure.objects[deviceStructure.root].common.name,
'function': 'light',
'room': getRoom(deviceStructure),
'states': _rfdc(STATE_MAPPING.light)
}
// validate states
device.states = validateStates(device.states, deviceStructure);
// no light, thus inherit all states
if (device.states.level !== undefined || device.states.colorTemperature !== undefined || device.states.hue !== undefined) {
parseDefault(deviceStructure, options).then(resolve);
}
else {
resolve(device);
}
});
}