-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
42 lines (32 loc) · 1.61 KB
/
app.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
'use strict';
const Homey = require('homey');
const SonyBraviaAndroidTvCommunicator = require('./helpers/sony-bravia-android-tv-communicator');
const SonyBraviaFlowActions = require('../../definitions/flow-actions');
class SonyBraviaAndroidTvApp extends Homey.App {
async onInit() {
this.log('SonyBraviaAndroidTvApp is running...');
await this.registerFlowListeners();
}
async registerFlowListeners() {
SonyBraviaFlowActions.forEach(flow => {
try {
const flowCard = this.homey.flow.getActionCard(flow.action);
flowCard.registerRunListener(async (args, state) => {
try {
flow.parsedCommand = flow.command;
if (flow.command instanceof Function) {
flow.parsedCommand = flow.command(args, state)
}
this.log(`${this.homey.manifest.id} - ${this.homey.manifest.version}: starting flow: ${flow.action} and sending command: `, flow.parsedCommand);
return await SonyBraviaAndroidTvCommunicator.sendCommand(args.device, flow.parsedCommand);
} catch (err) {
this.log(`${this.homey.manifest.id} - ${this.homey.manifest.version}: flow command could not be executed: `, flow, err);
}
});
} catch (err) {
this.log(`${this.homey.manifest.id} - ${this.homey.manifest.version}: flow command could not be registered: `, flow, err);
}
});
}
}
module.exports = SonyBraviaAndroidTvApp;