generated from homebridge/homebridge-plugin-template
/
platformEventBus.ts
52 lines (48 loc) · 1.33 KB
/
platformEventBus.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
import { EventEmitter } from 'events';
import { ButtonAction, DeviceInfo } from './commonTypes';
import { ButtonId } from './dingzTypes';
// Platform elements
// EVENT TYPES
export const enum PlatformEvent {
UPDATE_DEVICE_INFO = 'updateDeviceInfo',
ACTION = 'deviceAction',
REQUEST_STATE_UPDATE = 'requestStateUpdate',
}
export declare interface PlatformEventBus {
on(
event: PlatformEvent.ACTION,
listener: (mac: string, action: ButtonAction, battery: number) => void,
): this;
on(
event: PlatformEvent.ACTION,
listener: (mac: string, action: ButtonAction, button: ButtonId) => void,
): this;
on(
event: PlatformEvent.UPDATE_DEVICE_INFO,
listener: (deviceInfo: DeviceInfo) => void,
): this;
on(event: PlatformEvent.REQUEST_STATE_UPDATE, listener: () => void): this;
emit(
event: PlatformEvent.ACTION,
mac: string,
action: ButtonAction,
battery: number,
): boolean;
emit(
event: PlatformEvent.ACTION,
mac: string,
action: ButtonAction,
button: ButtonId,
): boolean;
emit(
event: PlatformEvent.UPDATE_DEVICE_INFO,
deviceInfo: DeviceInfo,
): boolean;
emit(event: PlatformEvent.REQUEST_STATE_UPDATE): boolean;
}
export class PlatformEventBus extends EventEmitter {
constructor() {
super();
this.setMaxListeners(20); // Maximum of 20 services
}
}