2020-01-09 13:47:19 -07:00
|
|
|
const events = require('events');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
|
|
|
const allowedEvents = [
|
|
|
|
'deviceRemoved', // Device has been removed
|
2020-03-04 04:55:08 -07:00
|
|
|
'deviceRenamed', // Device has been renamed
|
|
|
|
'groupRenamed', // Group has been renamed
|
2020-02-29 10:07:15 -07:00
|
|
|
'publishEntityState', // Entity state will be published
|
2020-01-09 13:47:19 -07:00
|
|
|
];
|
|
|
|
|
|
|
|
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;
|