-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathzwave2.js
93 lines (81 loc) · 2.19 KB
/
zwave2.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import { validateStates, parseDefault, getRoom } from '../adapters';
import _rfdc from 'rfdc/default';
export default 'Z-Wave 2';
export const namespace = 'zwave2';
export const deviceObjectType = 'device';
/*
* State Mapping
*/
const STATE_MAPPING = {
// heating
"thermostat": {
"valve": {
"state": ".Multilevel_Switch.currentValue",
"unit": "%",
"icon": "rotate-right"
},
"mode": {
"state": ".Thermostat_Mode.mode",
"action": ".Thermostat_Mode.mode",
"icon": {
"0": "radiator-off",
"1": "radiator",
"11": "radiator-disabled",
"15": "radiator"
}
},
"setTemperatureEnergySave": {
"state": ".Thermostat_Setpoint.setpoint_energySaveHeating",
"action": ".Thermostat_Setpoint.setpoint_energySaveHeating",
"unit": "°C",
"icon": "radiator-disabled"
},
"temperature": {
"state": ".Multilevel_Sensor.airTemperature"
},
"setTemperature": {
"state": ".Thermostat_Setpoint.setpoint_heating",
"action": ".Thermostat_Setpoint.setpoint_heating"
}
}
}
/**
*
*
*/
export function parse(deviceStructure, options) {
return new Promise(resolve => {
const obj = deviceStructure.objects[deviceStructure.root];
const device = {
'name': obj.common.name,
'function': 'other',
'room': getRoom(deviceStructure),
'states': {
'reachability': '.alive',
'battery': '.Battery.level',
'firmware': '.Version.firmwareVersions'
}
}
// state by function
if (obj.native.type && obj.native.type.generic && STATE_MAPPING[obj.native.type.generic.toLowerCase()] !== undefined) {
// device function
const functionMapping = {
'thermostat': 'heating'
}
device.function = functionMapping[obj.native.type.generic.toLowerCase()];
// add states
device.states = {
...device.states,
..._rfdc(STATE_MAPPING[obj.native.type.generic.toLowerCase()])
}
// validate states
device.states = validateStates(device.states, deviceStructure);
// resolve
resolve(device);
}
// no pre-defined function, thus parse it all
else {
parseDefault(deviceStructure, options, device).then(resolve);
}
});
}