mirror of
https://github.com/Koenkk/zigbee2mqtt.git
synced 2024-11-17 02:48:31 -07:00
37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
const BaseExtension = require('./baseExtension');
|
|
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
|
|
|
|
class DeviceEvent extends BaseExtension {
|
|
async onZigbeeStarted() {
|
|
for (const device of this.zigbee.getClients()) {
|
|
this.callOnEvent(device, 'start', {});
|
|
}
|
|
}
|
|
|
|
onZigbeeEvent(type, data, resolvedEntity) {
|
|
if (data.device && resolvedEntity.definition) {
|
|
this.callOnEvent(data.device, type, data, resolvedEntity.definition);
|
|
}
|
|
}
|
|
|
|
async stop() {
|
|
for (const device of this.zigbee.getClients()) {
|
|
this.callOnEvent(device, 'stop', {});
|
|
}
|
|
}
|
|
|
|
callOnEvent(device, type, data, definition) {
|
|
zigbeeHerdsmanConverters.onEvent(type, data, device);
|
|
|
|
if (!definition) {
|
|
definition = zigbeeHerdsmanConverters.findByZigbeeModel(device.modelID);
|
|
}
|
|
|
|
if (definition && definition.onEvent) {
|
|
definition.onEvent(type, data, device);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = DeviceEvent;
|