-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.ts
141 lines (117 loc) · 5.79 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
'use strict';
import Homey, { FlowCardAction, FlowCardCondition } from 'homey';
class Pax extends Homey.App {
static DEFAULT_BOOST_DURATION: number = 900;
/**
* onInit is called when the app is initialized.
*/
async onInit(): Promise<void> {
this.registerFlowListeners();
this.log('PAX has been initialized');
}
registerFlowListeners(): void {
// action cards
const boostOff: FlowCardAction = this.homey.flow.getActionCard('boost_off');
boostOff.registerRunListener(async (args: any) => {
this.homey.log('boostOff action triggered');
if (!args.device) {
this.homey.error('Device is not defined');
throw new Error('Device is not defined');
}
await args.device.boostOnOff({ on: false });
this.homey.log('boostOff action executed successfully');
return Promise.resolve(true);
});
const boostOn: FlowCardAction = this.homey.flow.getActionCard('boost_on');
boostOn.registerRunListener(async (args: any) => {
this.homey.log('boostOn action triggered');
if (!args.device) {
this.homey.error('Device is not defined');
throw new Error('Device is not defined');
}
const duration = typeof args.duration === 'number' && args.duration % 25 === 0
? args.duration / 1000 // given in MS
: Pax.DEFAULT_BOOST_DURATION;
try {
this.homey.log(`Calling boostOnOff with duration: ${duration}`);
await args.device.boostOnOff({
on: true,
duration,
});
this.homey.log(`boostOn action executed successfully with duration: ${duration}`);
} catch (error) {
this.homey.error('Error executing boostOn action');
throw error;
}
return Promise.resolve(true);
});
// condition cards
const modeEquals: FlowCardCondition = this.homey.flow.getConditionCard('mode_equals');
modeEquals.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('mode') === args.mode;
});
const boostOnCondition: FlowCardCondition = this.homey.flow.getConditionCard('boost_on');
boostOnCondition.registerRunListener(async (args: any) => {
return args.device ? args.device.getCapabilityValue('boost') : false;
});
// Additional condition cards for above values
const temperatureAbove: FlowCardCondition = this.homey.flow.getConditionCard('temperature_above');
temperatureAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_temperature') > args.temperature;
});
const humidityAbove: FlowCardCondition = this.homey.flow.getConditionCard('humidity_above');
humidityAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_humidity') > args.humidity;
});
const luminanceAbove: FlowCardCondition = this.homey.flow.getConditionCard('luminance_above');
luminanceAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_luminance') > args.luminance;
});
const rpmAbove: FlowCardCondition = this.homey.flow.getConditionCard('rpm_above');
rpmAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_rpm') > args.rpm;
});
const trickleSpeedAbove: FlowCardCondition = this.homey.flow.getConditionCard('trickle_speed_above');
trickleSpeedAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('fanspeed.trickle') > args.speed;
});
const humiditySpeedAbove: FlowCardCondition = this.homey.flow.getConditionCard('humidity_speed_above');
humiditySpeedAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('fanspeed.humidity') > args.speed;
});
const lightSpeedAbove: FlowCardCondition = this.homey.flow.getConditionCard('light_speed_above');
lightSpeedAbove.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('fanspeed.light') > args.speed;
});
// Additional condition cards for below values
const temperatureBelow: FlowCardCondition = this.homey.flow.getConditionCard('temperature_below');
temperatureBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_temperature') < args.temperature;
});
const humidityBelow: FlowCardCondition = this.homey.flow.getConditionCard('humidity_below');
humidityBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_humidity') < args.humidity;
});
const luminanceBelow: FlowCardCondition = this.homey.flow.getConditionCard('luminance_below');
luminanceBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_luminance') < args.luminance;
});
const rpmBelow: FlowCardCondition = this.homey.flow.getConditionCard('rpm_below');
rpmBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('measure_rpm') < args.rpm;
});
const trickleSpeedBelow: FlowCardCondition = this.homey.flow.getConditionCard('trickle_speed_below');
trickleSpeedBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('fanspeed.trickle') < args.speed;
});
const humiditySpeedBelow: FlowCardCondition = this.homey.flow.getConditionCard('humidity_speed_below');
humiditySpeedBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('fanspeed.humidity') < args.speed;
});
const lightSpeedBelow: FlowCardCondition = this.homey.flow.getConditionCard('light_speed_below');
lightSpeedBelow.registerRunListener(async (args: any) => {
return args.device.getCapabilityValue('fanspeed.light') < args.speed;
});
}
}
module.exports = Pax;