-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
77 lines (63 loc) · 2.56 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
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
'use strict';
const Homey = require('homey');
// const { sendCommandToMyAir } = require('./lib/myAirAPI');
class MyApp extends Homey.App {
/**
* onInit is called when the app is initialized.
*/
async onInit() {
this.log('MyApp has been initialized');
// Registering the flow action listener for setting aircon mode
try {
this.log('Attempting to register setAirconModeAction...');
const setAirconModeAction = this.homey.flow.getActionCard('set_aircon_mode');
setAirconModeAction.registerRunListener(async (args, state) => {
this.log(`Set aircon mode to ${args.fan_mode}`);
if (!args.device) {
this.log('Device not found');
return false; // Ensure there's a device reference
}
// Correctly invoke the method to change the fan speed
try {
// Directly call the method designed to handle fan speed changes
await args.device.onCapabilityMode(args.fan_mode);
this.log(`Aircon mode set to ${args.fan_mode}`);
return true; // Success
} catch (error) {
this.log(`Error setting aircon mode: ${error}`);
return false; // Indicate failure
}
});
this.log('setAirconModeAction registered successfully.');
} catch (error) {
this.log('Failed to register setAirconModeAction:', error);
}
// Registering the flow action listener for setting aircon mode
try {
this.log('Attempting to register setAirconFanAction...');
const setAirconFanAction = this.homey.flow.getActionCard('set_aircon_fan');
setAirconFanAction.registerRunListener(async (args, state) => {
this.log(`Attempting to set aircon fan to: ${args.fan_speed}`);
// Assuming 'args.device' directly provides a reference to your device instance
if (!args.device) {
this.log('Device not found');
return false; // Ensure there's a device reference
}
// Correctly invoke the method to change the fan speed
try {
// Directly call the method designed to handle fan speed changes
await args.device.onCapabilityFan(args.fan_speed);
this.log(`Aircon fan set to ${args.fan_speed}`);
return true; // Success
} catch (error) {
this.log(`Error setting aircon fan: ${error}`);
return false; // Indicate failure
}
});
this.log('setAirconFanAction registered successfully.');
} catch (error) {
this.log('Failed to register setAirconFanAction:', error);
}
}
}
module.exports = MyApp;