diff --git a/lib/extension/receive.ts b/lib/extension/receive.ts index 0ff7a0a04..2df4547c9 100755 --- a/lib/extension/receive.ts +++ b/lib/extension/receive.ts @@ -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 { /* 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); diff --git a/lib/types/types.d.ts b/lib/types/types.d.ts index 90778bf7e..54071c087 100644 --- a/lib/types/types.d.ts +++ b/lib/types/types.d.ts @@ -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, } interface DefinitionExposeFeature {name: string, endpoint?: string,