-
Notifications
You must be signed in to change notification settings - Fork 0
/
gardener.ts
51 lines (38 loc) · 1.34 KB
/
gardener.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
import { AccessoryManager } from './accessory-manager';
import { GardenMonitor, LOG_TYPE } from './garden-monitor';
// Register listeners for process shutdown
process.on('uncaughtException', (err) => {
console.trace(err);
setTimeout(() => { process.exit(1); }, 1000);
GardenMonitor.announce(LOG_TYPE.SHUTDOWN, ' ❗️ Gardener shutdown with error');
accessoryManager.shutdownAll(() => {
process.exit (1);
});
});
process.on('exit', () => {
GardenMonitor.closeDatabase();
});
process.on ('SIGINT', () => {
GardenMonitor.announce(LOG_TYPE.STOP, ' 🛑 Gardener stopped', () => {
GardenMonitor.closeDatabase();
accessoryManager.shutdownAll(() => {
process.exit (0);
});
});
});
// Controllers
import { GreenhousesController } from './controllers/greenhouses.controller';
import { LightsController } from './controllers/lights.controller';
// Init accessory manager
const accessoryManager = new AccessoryManager();
// Load all accessories from config
import accessoriesList from './config/accessories';
accessoryManager.loadFromConfig(accessoriesList);
// Start Homekit bridge
accessoryManager.publishAccessories();
GardenMonitor.announce(LOG_TYPE.START, ' 🚀 Gardener launched');
// Start controllers
const controllers = [
//new GreenhousesController(accessoryManager),
new LightsController(accessoryManager),
];