-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
inverter.ts
39 lines (30 loc) · 905 Bytes
/
inverter.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
import { Device } from "homey";
export class Inverter extends Device {
/** The refresh interval in minutes */
interval?: number;
currentInterval?: NodeJS.Timeout;
private setInterval(interval: number) {
this.currentInterval = this.homey.setInterval(
this.checkProduction.bind(this),
interval * 60000
);
}
resetInterval(newInterval: number) {
this.homey.clearInterval(this.currentInterval);
this.setInterval(newInterval);
}
async onInit(): Promise<void> {
if (!this.interval) {
throw new Error("Expected interval to be set");
}
this.homey.log("Initializing device");
this.setInterval(this.interval);
// SDK v3 migration, remove cron listeners
this.removeAllListeners();
// Force immediate production check
this.checkProduction.bind(this)();
}
checkProduction() {
throw new Error("Expected override");
}
}