-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnuki-extended.js
176 lines (166 loc) · 3.7 KB
/
nuki-extended.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import { validateStates, getRoom } from '../adapters';
import _rfdc from 'rfdc/default';
export default 'nuki-extended';
export const namespace = 'nuki-extended';
export const deviceObjectType = 'channel';
export const devicePattern = '(openers|smartlocks)+\\.([^.]+\\w+)';
/*
* State Mapping
*/
const STATE_MAPPING = {
// opener
"openers": {
"door": {
"state": ".state.doorState"
},
"ring": {
"state": ".state.ringState"
},
"ringUpdate": {
"state": ".state.ringStateUpdate"
},
"state": {
"state": ".state.lockState",
"display": {
"0": "UNTRAINED",
"1": "ONLINE",
"3": "RING_TO_OPEN",
"5": "OPEN",
"7": "OPENING",
"253": "BOOT_RUN",
"255": "UNDEFINED"
}
},
"lowbattery": {
"state": ".state.batteryCritical"
},
"ACTIONS": {
"action": "._ACTION",
"display": {
"0": "NO_ACTION",
"1": "ACTIVE RTO",
"2": "DEACTIVATE RTO",
"3": "ELECTRIC STRIKE ACTUATION",
"4": "ACTIVATE CM",
"5": "DEACTIVATE CM"
},
"actionElement": "DropdownAction"
},
"ACTIVATE_CM": {
"action": "._ACTION.ACTIVATE_CM",
"actionElement": "IconButtonAction"
},
"ACTIVE_RTO": {
"action": "._ACTION.ACTIVE_RTO",
"actionElement": "IconButtonAction"
},
"DEACTIVATE_CM": {
"action": "._ACTION.DEACTIVATE_CM",
"actionElement": "IconButtonAction"
},
"DEACTIVATE_RTO": {
"action": "._ACTION.DEACTIVATE_RTO",
"actionElement": "IconButtonAction"
},
"ELECTRIC_STRIKE_ACTUATION": {
"action": "._ACTION.ELECTRIC_STRIKE_ACTUATION",
"actionElement": "IconButtonAction"
}
},
// smartlock
"smartlocks": {
"door": {
"state": ".state.closed"
},
"doorState": {
"state": ".state.doorState",
"display": {
"0": "UNAVAILABLE",
"1": "DEACTIVATED",
"2": "DOOR_CLOSED",
"3": "DOOR_OPENED",
"4": "DOOR_STATE_UNKNOWN",
"5": "CALIBRATING"
}
},
"lock": {
"state": ".state.locked"
},
"lockState": {
"state": ".state.lockState",
"display": {
"0": "UNCALIBRATED",
"1": "LOCKED",
"2": "UNLOCKING",
"3": "UNLOCKED",
"4": "LOCKING",
"5": "UNLATCHED",
"6": "UNLOCKED_LOCK_N_GO",
"7": "UNLATCHING",
"254": "MOTOR_BLOCKED",
"255": "UNDEFINED"
}
},
"lockUpdate": {
"state": ".state.lastStateUpdate"
},
"lowbattery": {
"state": ".state.batteryCritical"
},
"ACTIONS": {
"action": "._ACTION",
"display": {
"0": "NO_ACTION",
"1": "UNLOCK",
"2": "LOCK",
"3": "UNLATCH",
"4": "LOCK_N_GO",
"5": "LOCK_N_GO_WITH_UNLATCH"
},
"actionElement": "DropdownAction"
},
"LOCK": {
"action": "._ACTION.LOCK",
"actionElement": "IconButtonAction"
},
"LOCK_N_GO": {
"action": "._ACTION.LOCK_N_GO",
"actionElement": "IconButtonAction"
},
"LOCK_N_GO_WITH_UNLATCH": {
"action": "._ACTION.LOCK_N_GO_WITH_UNLATCH",
"actionElement": "IconButtonAction"
},
"UNLATCH": {
"action": "._ACTION.UNLATCH",
"actionElement": "IconButtonAction"
},
"UNLOCK": {
"action": "._ACTION.UNLOCK",
"actionElement": "IconButtonAction"
}
}
}
/**
*
*
*/
export function parse(deviceStructure, options) {
return new Promise((resolve, reject) => {
const type = deviceStructure.states[deviceStructure.root + '.type'];
if (type) {
const name = deviceStructure.states[deviceStructure.root + '.name'];
const device = {
'name': (name && name.val) || deviceStructure.root,
'function': 'door',
'room': getRoom(deviceStructure),
'states': _rfdc(STATE_MAPPING[type.val === 0 ? 'smartlocks' : 'openers'])
}
// validate states
device.states = validateStates(device.states, deviceStructure);
// resolve
return resolve(device);
}
return reject(new Error('Nuki has no type'));
});
}