Fix double subscriptions for local push notifications (#52039)

pull/52042/head
Paulus Schoutsen 2021-06-20 14:53:21 -07:00 committed by GitHub
parent 57106098f9
commit af8ef634c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 5 deletions

View File

@ -160,7 +160,7 @@ def handle_push_notification_channel(hass, connection, msg):
registered_channels = hass.data[DOMAIN][DATA_PUSH_CHANNEL]
if webhook_id in registered_channels:
registered_channels.pop(webhook_id)()
registered_channels.pop(webhook_id)
@callback
def forward_push_notification(data):

View File

@ -136,6 +136,18 @@ async def test_notify_ws_works(
sub_result = await client.receive_json()
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(
"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()
assert msg_result["event"] == {"message": "Hello world"}
assert msg_result["id"] == 6 # This is the new subscription
# Unsubscribe, now it should go over http
await client.send_json(
{
"id": 6,
"id": 7,
"type": "unsubscribe_events",
"subscription": 5,
"subscription": 6,
}
)
sub_result = await client.receive_json()
@ -165,7 +178,7 @@ async def test_notify_ws_works(
# Test non-existing webhook ID
await client.send_json(
{
"id": 7,
"id": 8,
"type": "mobile_app/push_notification_channel",
"webhook_id": "non-existing",
}
@ -180,7 +193,7 @@ async def test_notify_ws_works(
# Test webhook ID linked to other user
await client.send_json(
{
"id": 8,
"id": 9,
"type": "mobile_app/push_notification_channel",
"webhook_id": "webhook_id_2",
}