Support multiple trigger instances for a single webhook (#76037)
This commit is contained in:
parent
56050e9fbe
commit
32b1259786
3 changed files with 107 additions and 23 deletions
|
@ -23,7 +23,7 @@ async def test_webhook_json(hass, hass_client_no_auth):
|
|||
|
||||
@callback
|
||||
def store_event(event):
|
||||
"""Helepr to store events."""
|
||||
"""Help store events."""
|
||||
events.append(event)
|
||||
|
||||
hass.bus.async_listen("test_success", store_event)
|
||||
|
@ -62,7 +62,7 @@ async def test_webhook_post(hass, hass_client_no_auth):
|
|||
|
||||
@callback
|
||||
def store_event(event):
|
||||
"""Helepr to store events."""
|
||||
"""Help store events."""
|
||||
events.append(event)
|
||||
|
||||
hass.bus.async_listen("test_success", store_event)
|
||||
|
@ -97,7 +97,7 @@ async def test_webhook_query(hass, hass_client_no_auth):
|
|||
|
||||
@callback
|
||||
def store_event(event):
|
||||
"""Helepr to store events."""
|
||||
"""Help store events."""
|
||||
events.append(event)
|
||||
|
||||
hass.bus.async_listen("test_success", store_event)
|
||||
|
@ -126,13 +126,68 @@ async def test_webhook_query(hass, hass_client_no_auth):
|
|||
assert events[0].data["hello"] == "yo world"
|
||||
|
||||
|
||||
async def test_webhook_multiple(hass, hass_client_no_auth):
|
||||
"""Test triggering multiple triggers with a POST webhook."""
|
||||
events1 = []
|
||||
events2 = []
|
||||
|
||||
@callback
|
||||
def store_event1(event):
|
||||
"""Help store events."""
|
||||
events1.append(event)
|
||||
|
||||
@callback
|
||||
def store_event2(event):
|
||||
"""Help store events."""
|
||||
events2.append(event)
|
||||
|
||||
hass.bus.async_listen("test_success1", store_event1)
|
||||
hass.bus.async_listen("test_success2", store_event2)
|
||||
|
||||
assert await async_setup_component(
|
||||
hass,
|
||||
"automation",
|
||||
{
|
||||
"automation": [
|
||||
{
|
||||
"trigger": {"platform": "webhook", "webhook_id": "post_webhook"},
|
||||
"action": {
|
||||
"event": "test_success1",
|
||||
"event_data_template": {"hello": "yo {{ trigger.data.hello }}"},
|
||||
},
|
||||
},
|
||||
{
|
||||
"trigger": {"platform": "webhook", "webhook_id": "post_webhook"},
|
||||
"action": {
|
||||
"event": "test_success2",
|
||||
"event_data_template": {
|
||||
"hello": "yo2 {{ trigger.data.hello }}"
|
||||
},
|
||||
},
|
||||
},
|
||||
]
|
||||
},
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
client = await hass_client_no_auth()
|
||||
|
||||
await client.post("/api/webhook/post_webhook", data={"hello": "world"})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(events1) == 1
|
||||
assert events1[0].data["hello"] == "yo world"
|
||||
assert len(events2) == 1
|
||||
assert events2[0].data["hello"] == "yo2 world"
|
||||
|
||||
|
||||
async def test_webhook_reload(hass, hass_client_no_auth):
|
||||
"""Test reloading a webhook."""
|
||||
events = []
|
||||
|
||||
@callback
|
||||
def store_event(event):
|
||||
"""Helepr to store events."""
|
||||
"""Help store events."""
|
||||
events.append(event)
|
||||
|
||||
hass.bus.async_listen("test_success", store_event)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue