Skip to content

Commit 0c68837

Browse files
committed
Fixed test, cleaned up documentation
1 parent 2af0ce4 commit 0c68837

File tree

2 files changed

+11
-20
lines changed

2 files changed

+11
-20
lines changed

docs/reference.rst

+9-19
Original file line numberDiff line numberDiff line change
@@ -864,25 +864,19 @@ matches any of the positive arguments, and none of the negative arguments.
864864
865865
@webhook_trigger(webhook_id, str_expr=None, local_only=True, methods={"POST", "PUT", kwargs=None)
866866
867-
``@webhook_trigger`` listens for calls to a `Home Assistant webhook <https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger>`__
868-
at `your_hass_url/api/webhook/webhook_id` and triggers whenever a request is made at that endpoint.
869-
Multiple ``@webhook_trigger`` decorators can be applied to a single function if you want
870-
to trigger off different mqtt topics.
867+
``@webhook_trigger`` listens for calls to a `Home Assistant webhook <https://www.home-assistant.io/docs/automation/trigger/#webhook-trigger>`__ at ``your_hass_url/api/webhook/webhook_id`` and triggers whenever a request is made at that endpoint. Multiple ``@webhook_trigger`` decorators can be applied to a single function if you want to trigger off different webhook ids.
871868
872-
An optional ``str_expr`` can be used to match against payload message data, and the trigger will only occur
873-
if that expression evaluates to ``True`` or non-zero. This expression has available these four
874-
variables:
869+
Setting ``local_only`` option to ``False`` will allow request made from anywhere on the internet (as opposed to just on local network).
870+
The methods option needs to be an list or set with elements ``GET``, ``HEAD``, ``POST``, or ``PUT``.
875871
876-
Setting `local_only` option to `False` will allow request made from anywhere on the internet (as opposed to just locally).
877-
The methods option needs to be an list or set with elements `GET`, `HEAD`, `POST`, or `PUT`.
872+
An optional ``str_expr`` can be used to match against payload message data, and the trigger will only occur if that expression evaluates to ``True`` or non-zero. This expression has available these three
873+
variables:
878874
879-
- ``trigger_type`` is set to "mqtt"
875+
- ``trigger_type`` is set to "webhook"
880876
- ``webhook_id`` is set to the webhook_id that was called.
881877
- ``webhook_data`` is the data/json that was sent in the request returned as a `MultiDictProxy <https://aiohttp-kxepal-test.readthedocs.io/en/latest/multidict.html#aiohttp.MultiDictProxy>`__ (ie a python dictionary that allows multiple of the same keys).
882878
883-
When the ``@webhook_trigger`` occurs, those same variables are passed as keyword arguments to the
884-
function in case it needs them. Additional keyword parameters can be specified by setting the
885-
optional ``kwargs`` argument to a ``dict`` with the keywords and values.
879+
When the ``@webhook_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 optional ``kwargs`` argument to a ``dict`` with the keywords and values.
886880
887881
An simple example looks like
888882
@@ -892,9 +886,7 @@ An simple example looks like
892886
def webhook_test(webhook_data, extra):
893887
log.info(f"It ran! {webhook_data}, {extra}")
894888
895-
which if called using the curl command `curl -X POST -d 'key1=xyz&key2=abc' hass_url/api/webhook/myid
896-
bhook` outputs `It ran! <MultiDictProxy('key1': 'xyz', 'key2': 'abc')>, 10`
897-
889+
which if called using the curl command ``curl -X POST -d 'key1=xyz&key2=abc' hass_url/api/webhook/myid`` outputs ``It ran! <MultiDictProxy('key1': 'xyz', 'key2': 'abc')>, 10``
898890
899891
Other Function Decorators
900892
-------------------------
@@ -1352,9 +1344,7 @@ It takes the following keyword arguments (all are optional):
13521344
- ``mqtt_trigger=None`` can be set to a string or list of two strings, just like
13531345
``@mqtt_trigger``. The first string is the MQTT topic, and the second string
13541346
(when the setting is a two-element list) is an expression based on the message variables.
1355-
- ``webhook_trigger=None`` can be set to a string or list of two strings, just like
1356-
``@webhook_trigger``. The first string is the webhook id, and the second string
1357-
(when the setting is a two-element list) is an expression based on the message variables.
1347+
- ``webhook_trigger=None`` can be set to a string or list of two strings, just like ``@webhook_trigger``. The first string is the webhook id, and the second string (when the setting is a two-element list) is an expression based on the message variables.
13581348
- ``webhook_local_only=True`` is used with ``webhook_trigger`` to specify whether to only allow
13591349
local webhooks.
13601350
- ``webhook_methods={"POST", "PUT"}`` is used with ``webhook_trigger`` to specify allowed webhook

tests/test_decorator_errors.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Test pyscript decorator syntax error and eval-time exception reporting."""
2+
23
from ast import literal_eval
34
import asyncio
45
from datetime import datetime as dt
@@ -217,7 +218,7 @@ def func4():
217218
""",
218219
)
219220
assert (
220-
"func4 defined in file.hello: needs at least one trigger decorator (ie: event_trigger, mqtt_trigger, state_trigger, time_trigger)"
221+
"func4 defined in file.hello: needs at least one trigger decorator (ie: event_trigger, mqtt_trigger, state_trigger, time_trigger, webhook_trigger)"
221222
in caplog.text
222223
)
223224

0 commit comments

Comments
 (0)