Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2127188

Browse files
Merge pull request #707 from dfries/docs_reference_mqtt_trigger
docs/reference.rst @mqtt_trigger and callbacks
2 parents 673a0a0 + 1e78770 commit 2127188

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

‎docs/reference.rst‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -774,15 +774,16 @@ on that topic. Multiple ``@mqtt_trigger`` decorators can be applied to a single
774774
to trigger off different mqtt topics.
775775

776776
An optional ``str_expr`` can be used to match the MQTT message data, and the trigger will only occur
777-
if that expression evaluates to ``True`` or non-zero. This expression has available these four
777+
if that expression evaluates to ``True`` or non-zero. This expression has available these
778778
variables:
779779

780780
- ``trigger_type`` is set to "mqtt"
781781
- ``topic`` is set to the topic the message was received on
782+
- ``qos`` is set to the message QoS.
782783
- ``payload`` is set to the string payload of the message
783784
- ``payload_obj`` if the payload was valid JSON, this will be set to the native Python object
784-
representing that payload.
785-
- ``qos`` is set to the message QoS.
785+
representing that payload. A null message will not be converted. If payload_obj is a
786+
required function argument an exception will be thrown, use payload_obj=None.
786787

787788
When the ``@mqtt_trigger`` occurs, those same variables are passed as keyword arguments to the
788789
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
792793
the message arrived on.
793794

794795
Wildcards are:
796+
795797
- ``+`` matches a single level in the topic hierarchy.
796798
- ``#`` matches zero or more levels in the topic hierarchy, can only be last.
797799

@@ -2144,7 +2146,8 @@ it doesn't faithfully mimic Python. Here are some areas where pyscript differs
21442146
won't be able to call that pyscript function unless it uses ``await``, which requires that function to
21452147
be declared ``async``. Unless the Python module is designed to support async callbacks, it is not
21462148
currently possible to have Python modules and packages call pyscript functions. The workaround is
2147-
to move your callbacks from pyscript and make them native Python functions; see `Importing <#importing>`__.
2149+
to move your callbacks from pyscript and make them native Python functions; see `Importing <#importing>`__,
2150+
call a function with the ``@pyscript_compile`` decorator, or a lambda (which is also compiled).
21482151
- Continuing that point, special methods (e.g., ``__eq__``) in a class created in `pyscript` will not work since
21492152
they are async functions and Python will not be able to call them. The two workarounds are to
21502153
use the ``@pyscript_compile`` decorator so the method is compiled to a native (non-async) Python

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /