forked from jensweigele/ioBroker.yahka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yahka.meta-generator.ts
51 lines (43 loc) · 1.56 KB
/
yahka.meta-generator.ts
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
import {CompleterResult} from 'readline';
import {Characteristic} from './node_modules/hap-nodejs/lib/Characteristic';
import {Service} from './node_modules/hap-nodejs/lib/Service';
import './node_modules/hap-nodejs/lib/gen/HomeKitTypes';
let availableServices = Object.keys(Service);
let availableCharacteristics = Object.keys(Characteristic);
let result = {};
let serviceDictionary = {};
let charDictionary = {};
for (let charName of availableCharacteristics) {
if (charName === 'super_') {
continue;
}
charDictionary[Characteristic[charName].UUID] = charName;
}
for (let serviceName of availableServices) {
if (serviceName === 'super_') {
continue;
}
let serviceDescriptor = {
type: serviceName,
characteristics: {}
};
let serviceInstance = new Service[serviceName]('', '');
for (let char of serviceInstance.characteristics) {
let charName = charDictionary[char.UUID];
if (charName === undefined) {
continue;
}
let charDescriptor = {name: charName, optional: false};
serviceDescriptor.characteristics[charName] = charDescriptor;
}
for (let char of serviceInstance.optionalCharacteristics) {
let charName = charDictionary[char.UUID];
if (charName === undefined) {
continue;
}
let charDescriptor_ = {name: charName, optional: true};
serviceDescriptor.characteristics[charName] = charDescriptor_;
}
serviceDictionary[serviceName] = serviceDescriptor;
}
console.log(JSON.stringify(serviceDictionary));