2020-04-11 09:31:57 -07:00
|
|
|
const Extension = require('./extension');
|
|
|
|
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This extension calls the zigbee-herdsman-converters onEvent.
|
|
|
|
*/
|
|
|
|
class OnEvent extends Extension {
|
|
|
|
async onZigbeeStarted() {
|
|
|
|
for (const device of this.zigbee.getClients()) {
|
|
|
|
const resolvedEntity = this.zigbee.resolveEntity(device);
|
|
|
|
this.callOnEvent(resolvedEntity, 'start', {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onZigbeeEvent(type, data, resolvedEntity) {
|
|
|
|
if (resolvedEntity && resolvedEntity.type === 'device') {
|
|
|
|
this.callOnEvent(resolvedEntity, type, data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async stop() {
|
2020-07-29 14:10:03 -07:00
|
|
|
super.stop();
|
2020-04-11 09:31:57 -07:00
|
|
|
for (const device of this.zigbee.getClients()) {
|
|
|
|
const resolvedEntity = this.zigbee.resolveEntity(device);
|
|
|
|
this.callOnEvent(resolvedEntity, 'stop', {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callOnEvent(resolvedEntity, type, data) {
|
2020-09-07 09:46:46 -07:00
|
|
|
zigbeeHerdsmanConverters.onEvent(type, data, resolvedEntity.device, resolvedEntity.settings);
|
2020-04-11 09:31:57 -07:00
|
|
|
|
|
|
|
if (resolvedEntity.definition && resolvedEntity.definition.onEvent) {
|
2020-09-07 09:46:46 -07:00
|
|
|
resolvedEntity.definition.onEvent(type, data, resolvedEntity.device, resolvedEntity.settings);
|
2020-04-11 09:31:57 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = OnEvent;
|