zigbee2mqtt/lib/extension/deviceEvent.js

37 lines
1.0 KiB
JavaScript
Raw Normal View History

const BaseExtension = require('./baseExtension');
const zigbeeHerdsmanConverters = require('zigbee-herdsman-converters');
class DeviceEvent extends BaseExtension {
async onZigbeeStarted() {
2019-09-23 13:21:27 -07:00
for (const device of this.zigbee.getClients()) {
this.callOnEvent(device, 'start', {});
}
}
onZigbeeEvent(type, data, mappedDevice, settingsDevice) {
if (data.device) {
this.callOnEvent(data.device, type, data, mappedDevice);
}
}
async stop() {
2019-09-23 13:21:27 -07:00
for (const device of this.zigbee.getClients()) {
this.callOnEvent(device, 'stop', {});
}
}
callOnEvent(device, type, data, mappedDevice) {
2020-01-08 12:06:01 -07:00
zigbeeHerdsmanConverters.onEvent(type, data, device);
if (!mappedDevice) {
mappedDevice = zigbeeHerdsmanConverters.findByZigbeeModel(device.modelID);
}
if (mappedDevice && mappedDevice.onEvent) {
mappedDevice.onEvent(type, data, device);
}
}
}
module.exports = DeviceEvent;