From 620a770317838d857b87879f99c83d984622b11e Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Sun, 1 Oct 2023 11:31:54 +0200 Subject: [PATCH] add support for plain text in payload (i.e. no JSON) this permits something like `condition: event.payload == 'hello'` for an MQTT publish with a payload consisting of the word "hello" --- plugins/event_source/mqtt.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/event_source/mqtt.py b/plugins/event_source/mqtt.py index 12c50af..0fa41e3 100644 --- a/plugins/event_source/mqtt.py +++ b/plugins/event_source/mqtt.py @@ -71,7 +71,10 @@ async def main(queue: asyncio.Queue, args: Dict[str, Any]) -> None: await mqtt_consumer.subscribe(topic) async for message in messages: try: - data = json.loads(message.payload.decode()) + try: + data = json.loads(message.payload.decode()) + except json.decoder.JSONDecodeError: + data = dict(payload=message.payload.decode()) await queue.put(data) except json.decoder.JSONDecodeError: logger.exception("Decoding exception for incoming message")