-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathknx.js
40 lines (33 loc) · 1.03 KB
/
knx.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
import { v5 as uuid } from 'uuid'
import { detectFunction, detectStateElements, getRoom } from '../adapters'
export default 'knx'
export const namespace = 'knx'
export const deviceObjectType = 'state'
/**
*
* @see https://github.com/Zefau/ioBroker.jarvis/issues/231
*/
export function root(objects, options) {
return new Promise(resolve => {
const devices = [];
for (const objectId in objects) {
const obj = objects[objectId];
if (objectId.indexOf('.info.connection') > -1) {
continue;
}
const name = objectId.replace('knx.', '').substr(2).replace(/\./g, ' - ').replace(/_/g, ' ');
let device = {
'id': obj.common.name.toLowerCase().replace(/ /g, '') + '_' + uuid(objectId, '4eaf6392-6a70-4802-b343-5ff1a1673f39').substr(0, 5),
name,
'function': 'other',
'room': getRoom(deviceStructure),
'states': {
[obj.native.address]: detectStateElements(objectId, { 'objects': objects })
}
}
device = detectFunction(device);
devices.push(device);
}
resolve(devices);
});
}