-
Notifications
You must be signed in to change notification settings - Fork 3
/
printFunctions.ts
45 lines (39 loc) · 1.17 KB
/
printFunctions.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
import { HarmonyClient } from '@harmonyhub/client-ws';
import { HubReporter } from './setup';
const hubReporter = new HubReporter();
hubReporter.on( HarmonyClient.Events.CONNECTED, async (harmonyClient: HarmonyClient) => {
try {
// get all activities
const activities = await harmonyClient.getActivities();
console.log(
'available activities',
activities.map(
(activity) => activity.label
)
);
// get all devices
const commands = await harmonyClient.getAvailableCommands();
console.log(
'devices',
commands.device.map(
(dev) => dev.label + dev.type
)
);
// print television functions
const tv = commands.device.find(
(dev) => dev.type === 'Television'
);
console.log(
'Functions for television',
tv.controlGroup.map(
(control) => `${control.name} [${control.function.map((func) => func.name)}]`
)
);
harmonyClient.end();
} catch (error) {
console.error('Error', error.message);
}
} );
hubReporter.start();
console.log('listening for 10 seconds to retrieve hub infos from the network');
setTimeout( () => hubReporter.stop(), 10 * 1000 );