mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
26 lines
780 B
JavaScript
26 lines
780 B
JavaScript
const events = require('events');
|
|
const assert = require('assert');
|
|
|
|
const allowedEvents = [
|
|
'deviceRemoved', // Device has been removed
|
|
'deviceRenamed', // Device has been renamed
|
|
'groupRenamed', // Group has been renamed
|
|
'publishEntityState', // Entity state will be published
|
|
'stateChange', // Entity changes its state
|
|
'groupMembersChanged', // Members of a group has been changed
|
|
];
|
|
|
|
class EventBus extends events.EventEmitter {
|
|
emit(event, data) {
|
|
assert(allowedEvents.includes(event), `Event '${event}' not supported`);
|
|
super.emit(event, data);
|
|
}
|
|
|
|
on(event, callback) {
|
|
assert(allowedEvents.includes(event), `Event '${event}' not supported`);
|
|
super.on(event, callback);
|
|
}
|
|
}
|
|
|
|
module.exports = EventBus;
|