-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrpi2.js
44 lines (37 loc) · 1.19 KB
/
rpi2.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
import { v5 as uuid } from 'uuid';
import { getRoom } from '../adapters';
export default 'rpi2';
export const namespace = 'rpi2';
export const deviceObjectType = 'state';
/**
*
*
*/
export function root(objects, options) {
return new Promise(resolve => {
const stateList = Object.values(objects).map(state => state.id);
const devices = {};
for (let instance = 0; instance < 99; instance++) {
// verify that instance exists
if (stateList.indexOf(namespace + '.' + instance + '.cpu.load1') === -1) {
break;
}
// device
devices[namespace + '.' + instance] = devices[namespace + '.' + instance] || {
'id': (namespace + '.' + instance).toLowerCase().replace(/ /g, '') + '_' + uuid(namespace + '.' + instance, '4eaf6392-6a70-4802-b343-5ff1a1673f39').substr(0, 5),
'name': namespace + '.' + instance,
'function': 'server',
'room': getRoom(deviceStructure),
'states': {}
}
// add states
stateList.forEach(state => {
const stateKey = state.replace(namespace + '.' + instance + '.', '').replace(/\./g, '-');
devices[namespace + '.' + instance].states[stateKey] = {
"state": state
}
});
}
resolve(Object.values(devices));
});
}