-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.ts
81 lines (61 loc) · 3.12 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
import Homey from 'homey';
import moment from 'moment-timezone';
import {DeviceHandler} from "./lib/DeviceHandler";
class UtilityCostsApp extends Homey.App {
async onInit() {
moment.tz.setDefault(this.homey.clock.getTimezone());
await this._initFlows();
this.log('UtilityCostsApp is running...');
}
async _initFlows() {
this.homey.flow.getConditionCard('price_incl_below')
.registerRunListener(args => args.device.getCapabilityValue(`meter_price_incl`) < args.price);
this.homey.flow.getConditionCard('gridprice_incl_below')
.registerRunListener(args => args.device.getCapabilityValue(`meter_gridprice_incl`) < args.price);
this.homey.flow.getConditionCard('sum_current_below')
.registerRunListener(args => args.device.getCapabilityValue(`meter_sum_current`) < args.sum_current);
this.homey.flow.getActionCard('update_consumption')
.registerRunListener((args, state) => args.device.onUpdateConsumption(args.unit === 'kW' ? args.consumption * 1000 : args.consumption));
this.homey.flow.getActionCard('update_energy')
.registerRunListener((args, state) => args.device.onUpdateEnergy(args.energy));
this.homey.flow.getActionCard('update_price')
.registerRunListener((args, state) => args.device.onUpdatePrice(args.price));
this.homey.flow.getActionCard('set_utility_costs_settings')
.registerRunListener((args, state) => args.device.onSetUtilityCostsSettings(args));
this.homey.flow.getActionCard('set_gridcapacity_settings')
.registerRunListener((args, state) => args.device.onSetGridCapacitySettings(args));
this.homey.flow.getActionCard('set_gridenergy_settings')
.registerRunListener((args, state) => args.device.onSetGridEnergySettings(args));
this.homey.flow.getActionCard('meter_power_reset')
.registerRunListener((args, state) => args.device.onMeterPowerReset());
this.homey.flow.getActionCard('meter_reset_all')
.registerRunListener((args, state) => args.device.onMeterResetAll());
this.homey.flow.getActionCard('fetch_config_data')
.registerRunListener((args, state) => args.device.onFetchConfigData());
}
getDeviceHandler(): DeviceHandler | undefined {
const driver = this.homey.drivers.getDriver('UtilityCosts');
const devices = driver.getDevices();
if (devices.length > 0) {
// @ts-ignore
return devices[0].getDeviceHandler();
}
}
async getPrices(): Promise<void> {
const driver = this.homey.drivers.getDriver('UtilityCosts');
const devices = driver.getDevices();
if (devices.length > 0) {
// @ts-ignore
return devices[0].getPrices();
}
}
async getGridCosts(): Promise<void> {
const driver = this.homey.drivers.getDriver('UtilityCosts');
const devices = driver.getDevices();
if (devices.length > 0) {
// @ts-ignore
return devices[0].getGridCosts();
}
}
}
module.exports = UtilityCostsApp;