mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Fix double subscriptions for local push notifications (#52039)
This commit is contained in:
parent
57106098f9
commit
af8ef634c1
@ -160,7 +160,7 @@ def handle_push_notification_channel(hass, connection, msg):
|
|||||||
registered_channels = hass.data[DOMAIN][DATA_PUSH_CHANNEL]
|
registered_channels = hass.data[DOMAIN][DATA_PUSH_CHANNEL]
|
||||||
|
|
||||||
if webhook_id in registered_channels:
|
if webhook_id in registered_channels:
|
||||||
registered_channels.pop(webhook_id)()
|
registered_channels.pop(webhook_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def forward_push_notification(data):
|
def forward_push_notification(data):
|
||||||
|
@ -136,6 +136,18 @@ async def test_notify_ws_works(
|
|||||||
sub_result = await client.receive_json()
|
sub_result = await client.receive_json()
|
||||||
assert sub_result["success"]
|
assert sub_result["success"]
|
||||||
|
|
||||||
|
# Subscribe twice, it should forward all messages to 2nd subscription
|
||||||
|
await client.send_json(
|
||||||
|
{
|
||||||
|
"id": 6,
|
||||||
|
"type": "mobile_app/push_notification_channel",
|
||||||
|
"webhook_id": "mock-webhook_id",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
sub_result = await client.receive_json()
|
||||||
|
assert sub_result["success"]
|
||||||
|
|
||||||
assert await hass.services.async_call(
|
assert await hass.services.async_call(
|
||||||
"notify", "mobile_app_test", {"message": "Hello world"}, blocking=True
|
"notify", "mobile_app_test", {"message": "Hello world"}, blocking=True
|
||||||
)
|
)
|
||||||
@ -144,13 +156,14 @@ async def test_notify_ws_works(
|
|||||||
|
|
||||||
msg_result = await client.receive_json()
|
msg_result = await client.receive_json()
|
||||||
assert msg_result["event"] == {"message": "Hello world"}
|
assert msg_result["event"] == {"message": "Hello world"}
|
||||||
|
assert msg_result["id"] == 6 # This is the new subscription
|
||||||
|
|
||||||
# Unsubscribe, now it should go over http
|
# Unsubscribe, now it should go over http
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
"id": 6,
|
"id": 7,
|
||||||
"type": "unsubscribe_events",
|
"type": "unsubscribe_events",
|
||||||
"subscription": 5,
|
"subscription": 6,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
sub_result = await client.receive_json()
|
sub_result = await client.receive_json()
|
||||||
@ -165,7 +178,7 @@ async def test_notify_ws_works(
|
|||||||
# Test non-existing webhook ID
|
# Test non-existing webhook ID
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
"id": 7,
|
"id": 8,
|
||||||
"type": "mobile_app/push_notification_channel",
|
"type": "mobile_app/push_notification_channel",
|
||||||
"webhook_id": "non-existing",
|
"webhook_id": "non-existing",
|
||||||
}
|
}
|
||||||
@ -180,7 +193,7 @@ async def test_notify_ws_works(
|
|||||||
# Test webhook ID linked to other user
|
# Test webhook ID linked to other user
|
||||||
await client.send_json(
|
await client.send_json(
|
||||||
{
|
{
|
||||||
"id": 8,
|
"id": 9,
|
||||||
"type": "mobile_app/push_notification_channel",
|
"type": "mobile_app/push_notification_channel",
|
||||||
"webhook_id": "webhook_id_2",
|
"webhook_id": "webhook_id_2",
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user