2019-09-19 11:36:05 -07:00
|
|
|
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()) {
|
2019-09-19 11:36:05 -07:00
|
|
|
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()) {
|
2019-09-19 11:36:05 -07:00
|
|
|
this.callOnEvent(device, 'stop', {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
callOnEvent(device, type, data, mappedDevice) {
|
2020-01-08 12:06:01 -07:00
|
|
|
zigbeeHerdsmanConverters.onEvent(type, data, device);
|
|
|
|
|
2019-09-19 11:36:05 -07:00
|
|
|
if (!mappedDevice) {
|
|
|
|
mappedDevice = zigbeeHerdsmanConverters.findByZigbeeModel(device.modelID);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mappedDevice && mappedDevice.onEvent) {
|
|
|
|
mappedDevice.onEvent(type, data, device);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = DeviceEvent;
|