-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.ts
85 lines (65 loc) · 3.33 KB
/
app.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Homey from 'homey';
import {Logger} from "./lib/Logger";
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
class SamsungSmartApp extends Homey.App {
logger: any;
async onInit() {
try {
// @ts-ignore
this.logger = new Logger({
homey: this.homey,
logFunc: this.log,
errorFunc: this.error,
}, Homey.env);
await this.initFlows();
this.logger.verbose('SamsungSmartApp is running...');
} catch (err) {
this.logger.error('App onInit', err);
}
}
async initFlows() {
this.homey.flow.getConditionCard('is_power_onoff')
.registerRunListener(args => args.device.turning_onoff_process !== undefined);
this.homey.flow.getActionCard('send_key')
.registerRunListener(args => args.device.samsungClient.sendKey(args.key.id))
.getArgument('key')
.registerAutocompleteListener((query, args) => args.device.onKeyAutocomplete(query, args));
this.homey.flow.getActionCard('send_keys')
.registerRunListener(args => args.device.samsungClient.sendKeys([args.keys1]));
this.homey.flow.getActionCard('change_channel')
.registerRunListener(args => args.device.samsungClient.setChannel(args.channel));
this.homey.flow.getConditionCard('is_app_running')
.registerRunListener(args => args.device.samsungClient.isAppRunning(args.app_id))
.getArgument('app_id')
.registerAutocompleteListener((query, args) => args.device.onAppAutocomplete(query, args));
this.homey.flow.getActionCard('launch_app')
.registerRunListener(args => args.device.samsungClient.launchApp(args.app_id))
.getArgument('app_id')
.registerAutocompleteListener((query, args) => args.device.onAppAutocomplete(query, args));
this.homey.flow.getActionCard('close_app')
.registerRunListener(args => args.device.samsungClient.closeApp(args.app_id))
.getArgument('app_id')
.registerAutocompleteListener((query, args) => args.device.onAppAutocomplete(query, args));
this.homey.flow.getActionCard('youtube')
.registerRunListener(args => {
if (!args.videoId || args.videoId.length !== 11) {
return Promise.reject(this.homey.__('errors.invalid_video_id'));
}
return args.device.samsungClient.launchYouTube(args.videoId);
});
this.homey.flow.getActionCard('browse')
.registerRunListener(args => {
if (!args.url || args.url.length === 0) {
return Promise.reject(this.homey.__('errors.invalid_browse_url'));
}
return args.device.samsungClient.launchBrowser(args.url);
});
this.homey.flow.getActionCard('set_input_source')
.registerRunListener(args => args.device.setStInputSource(args.input_source.id))
.getArgument('input_source')
.registerAutocompleteListener((query, args) => args.device.onInputSourceAutocomplete(query, args));
this.homey.flow.getActionCard('set_power_state')
.registerRunListener(args => args.device.setPowerState(args.power_state === 'on'));
}
}
module.exports = SamsungSmartApp;