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