aboutsummaryrefslogtreecommitdiff
path: root/plugin.ts
blob: 01af191d7ed09289332b4fc3015830fb47e93da9 (plain)
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
import {
	API,
	Characteristic,
	DynamicPlatformPlugin,
	Logger,
	PlatformAccessory,
	PlatformConfig,
	Service,
} from 'homebridge';

export default class BekenBridge implements DynamicPlatformPlugin {
	public readonly Service: typeof Service = this.api.hap.Service;
	public readonly Characteristic: typeof Characteristic = this.api.hap.Characteristic;

	public readonly accessories: PlatformAccessory[] = [];

	constructor(
		public readonly log: Logger,
		public readonly config: PlatformConfig,
		public readonly api: API,
	) {
		this.log.debug('Loaded BekenBridge');

		this.api.on('didFinishLaunching', () => {
			log.debug('Executed didFinishLaunching callback');
			this.discoverDevices();
		});
	}

	configureAccessory(accessory: PlatformAccessory) {
		this.log.info('Loading accessory from cache:', accessory.displayName);

		this.accessories.push(accessory);
	}

	discoverDevices() {
		this.log.info('gert');
		// const exampleDevices = [
		// 	{
		// 		exampleUniqueId: 'ABCD',
		// 		exampleDisplayName: 'Bedroom',
		// 	},
		// 	{
		// 		exampleUniqueId: 'EFGH',
		// 		exampleDisplayName: 'Kitchen',
		// 	},
		// ];

		// for (const device of exampleDevices) {

		// 	const uuid = this.api.hap.uuid.generate(device.exampleUniqueId);

		// 	const existingAccessory = this.accessories.find(accessory => accessory.UUID === uuid);

		// 	if (existingAccessory) {
		// 		this.log.info('Restoring existing accessory from cache:', existingAccessory.displayName);

		// 		new ExamplePlatformAccessory(this, existingAccessory);

		// 	} else {
		// 		this.log.info('Adding new accessory:', device.exampleDisplayName);

		// 		const accessory = new this.api.platformAccessory(device.exampleDisplayName, uuid);

		// 		accessory.context.device = device;

		// 		new ExamplePlatformAccessory(this, accessory);

		// 		this.api.registerPlatformAccessories(PLUGIN_NAME, PLATFORM_NAME, [accessory]);
		// 	}
		// }
	}
}