From 25c9b5a4dcaf6b67ed48871d9df577f9391f306e Mon Sep 17 00:00:00 2001 From: David Fries Date: Sun, 9 Mar 2025 18:54:09 -0500 Subject: [PATCH 1/2] Update reference.rst @mqtt_trigger It says four variables, but lists five, removed "four". I was tripped up by a null message with a payload_obj listed as a required function parameter, give a hint for not specifying it as a required parameter. Moved qos before payload as I listed the arguments in order, and needed it to not be last for payload_obj to be optional and qos not. Fixed the Wildcard formatting, the two bullet points were all made into one paragraph with "- + matches" confusing as I didn't think - was a wildcard, it needed the blank line to render them as bullet points. --- docs/reference.rst | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/reference.rst b/docs/reference.rst index 4e38699..240328c 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -774,15 +774,16 @@ on that topic. Multiple ``@mqtt_trigger`` decorators can be applied to a single to trigger off different mqtt topics. An optional ``str_expr`` can be used to match the MQTT message data, and the trigger will only occur -if that expression evaluates to ``True`` or non-zero. This expression has available these four +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 +- ``qos`` is set to the message QoS. - ``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. -- ``qos`` is set to the message QoS. + 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. 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 @@ -792,6 +793,7 @@ Wildcards in topics are supported. The ``topic`` variables will be set to the fu the message arrived on. Wildcards are: + - ``+`` matches a single level in the topic hierarchy. - ``#`` matches zero or more levels in the topic hierarchy, can only be last. From 1e787705096b88b16c325900b82dc98007d149c2 Mon Sep 17 00:00:00 2001 From: David Fries Date: Sun, 9 Mar 2025 19:04:59 -0500 Subject: [PATCH 2/2] Update reference.rst Language Limiations Give @pyscript_compile and lambda as another work around for python callback functions. --- docs/reference.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/reference.rst b/docs/reference.rst index 240328c..5bdb602 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -2146,7 +2146,8 @@ it doesn't faithfully mimic Python. Here are some areas where pyscript differs won't be able to call that pyscript function unless it uses ``await``, which requires that function to be declared ``async``. Unless the Python module is designed to support async callbacks, it is not currently possible to have Python modules and packages call pyscript functions. The workaround is - to move your callbacks from pyscript and make them native Python functions; see `Importing <#importing>`__. + to move your callbacks from pyscript and make them native Python functions; see `Importing <#importing>`__, + call a function with the ``@pyscript_compile`` decorator, or a lambda (which is also compiled). - Continuing that point, special methods (e.g., ``__eq__``) in a class created in `pyscript` will not work since they are async functions and Python will not be able to call them. The two workarounds are to use the ``@pyscript_compile`` decorator so the method is compiled to a native (non-async) Python