From e18e455db467d27a05f2e2f1fdaad900f0beccca Mon Sep 17 00:00:00 2001 From: 3735943886 <9522390+3735943886@users.noreply.github.com> Date: Sat, 30 Aug 2025 07:42:31 +0900 Subject: [PATCH 1/3] Add MQTT retain flag handling to pyscript trigger and message handler Adds the `retain` flag to `TRIGGER_KWARGS` in pyscript's `eval.py` to prevent a TypeError with mqtt_trigger. --- custom_components/pyscript/eval.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/pyscript/eval.py b/custom_components/pyscript/eval.py index dea95cc..2d3eef6 100644 --- a/custom_components/pyscript/eval.py +++ b/custom_components/pyscript/eval.py @@ -70,6 +70,7 @@ "payload", "payload_obj", "qos", + "retain", "topic", "trigger_type", "trigger_time", From b227b12177d2b19db4b52a9c04fd24c2a135370c Mon Sep 17 00:00:00 2001 From: 3735943886 <9522390+3735943886@users.noreply.github.com> Date: Sat, 30 Aug 2025 07:45:49 +0900 Subject: [PATCH 2/3] Add MQTT retain flag handling to pyscript trigger and message handler Updates the message handler in `mqtt.py` to include the `retain` flag in its processed arguments. --- custom_components/pyscript/mqtt.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/pyscript/mqtt.py b/custom_components/pyscript/mqtt.py index 25d72a1..8e15b3d 100644 --- a/custom_components/pyscript/mqtt.py +++ b/custom_components/pyscript/mqtt.py @@ -45,6 +45,7 @@ async def mqtt_message_handler(mqttmsg): "topic": mqttmsg.topic, "payload": mqttmsg.payload, "qos": mqttmsg.qos, + "retain": mqttmsg.retain, } try: From 9ae65557eaf99be1687184fefeee056302d23639 Mon Sep 17 00:00:00 2001 From: 3735943886 <9522390+3735943886@users.noreply.github.com> Date: Sun, 31 Aug 2025 07:50:37 +0900 Subject: [PATCH 3/3] Update reference.rst Updates the documentation to include the 'retain' flag. --- docs/reference.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/reference.rst b/docs/reference.rst index 7c7dd96..5f62226 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -778,13 +778,14 @@ An optional ``str_expr`` can be used to match the MQTT message data, and the tri if that expression evaluates to ``True`` or non-zero. This expression has available these variables: -- ``trigger_type`` is set to "mqtt" -- ``topic`` is set to the topic the message was received on +- ``trigger_type`` is set to "mqtt". +- ``topic`` is set to the topic the message was received on. - ``qos`` is set to the message QoS. -- ``payload`` is set to the string payload of the message +- ``payload`` is set to the string payload of the message. - ``payload_obj`` if the payload was valid JSON, this will be set to the native Python object representing that payload. A null message will not be converted. If payload_obj is a required function argument an exception will be thrown, use payload_obj=None. +- ``retain`` is set to the message retain flag. True if the message was retained, False otherwise. When the ``@mqtt_trigger`` occurs, those same variables are passed as keyword arguments to the function in case it needs them. Additional keyword parameters can be specified by setting the