Fix crash when converter throws exception. https://github.com/Koenkk/zigbee2mqtt/issues/9133

This commit is contained in:
Koen Kanters
2021-10-13 19:05:14 +02:00
parent 6b380526ae
commit 749381bf2f
2 changed files with 13 additions and 7 deletions
+12 -6
View File
@@ -85,7 +85,7 @@ export default class Receive extends Extension {
return true;
}
@bind onDeviceMessage(data: eventdata.DeviceMessage): void {
@bind async onDeviceMessage(data: eventdata.DeviceMessage): Promise<void> {
/* istanbul ignore next */
if (!data.device) return;
@@ -147,12 +147,18 @@ export default class Receive extends Extension {
const meta = {device: data.device.zh, logger, state: this.state.get(data.device)};
let payload: KeyValue = {};
converters.forEach((converter) => {
const converted = converter.convert(data.device.definition, data, publish, data.device.settings, meta);
if (converted) {
payload = {...payload, ...converted};
for (const converter of converters) {
try {
const converted = await converter.convert(
data.device.definition, data, publish, data.device.settings, meta);
if (converted) {
payload = {...payload, ...converted};
}
} catch (error) {
// istanbul ignore next
logger.error(`Exception while calling fromZigbee converter: ${error.message}}`);
}
});
}
if (Object.keys(payload).length) {
publish(payload);
+1 -1
View File
@@ -91,7 +91,7 @@ declare global {
cluster: string,
type: string[] | string,
convert: (model: Definition, msg: KeyValue, publish: (payload: KeyValue) => void, options: KeyValue,
meta: {state: KeyValue, logger: Logger, device: zh.Device}) => KeyValue,
meta: {state: KeyValue, logger: Logger, device: zh.Device}) => Promise<KeyValue>,
}
interface DefinitionExposeFeature {name: string, endpoint?: string,