-
Notifications
You must be signed in to change notification settings - Fork 8
/
app.ts
56 lines (45 loc) · 1.52 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
import 'newrelic';
import sourceMapSupport from 'source-map-support';
import { App } from 'homey';
import Homey from 'homey/lib/Homey';
import { setGlobalAttributes } from './lib/newrelic-transaction';
import * as appJson from './app.json';
sourceMapSupport.install();
type HomeyWithMissingTypings = Homey & {
platformVersion: string;
};
class TibberApp extends App {
async onInit() {
this.log('Tibber app is running...');
const { version: firmwareVersion, platformVersion } = this
.homey as HomeyWithMissingTypings;
const { version: appVersion } = appJson;
this.log(`platformVersion:`, platformVersion);
this.log(`firmwareVersion:`, firmwareVersion);
this.log(`appVersion:`, appVersion);
setGlobalAttributes({ firmwareVersion, platformVersion, appVersion });
const v = this.homey.settings.get('v');
if (v !== 2) {
this.log('Cleaning logs');
this.homey.settings.set('v', 2);
this.cleanupLogs('*').catch(console.error);
}
}
async cleanupLogs(prefix: string) {
if (prefix !== '*') return;
const logs = await this.homey.insights.getLogs();
await Promise.all(
logs
.filter(({ name }) => name.startsWith(prefix))
.map((log) => {
console.log('Deleting log', log.name);
return this.homey.insights.deleteLog(log);
}),
);
}
async onUninit() {
this.log('Tibber app is stopping');
}
}
// workaround for `The class exported in '<filepath>' must extend Homey.<classname>` error
module.exports = TibberApp;