Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double subscriptions for local push notifications #52039

Merged
merged 1 commit into from Jun 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/mobile_app/__init__.py
Expand Up @@ -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):
Expand Down
21 changes: 17 additions & 4 deletions tests/components/mobile_app/test_notify.py
Expand Up @@ -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
)
Expand All @@ -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()
Expand All @@ -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",
}
Expand All @@ -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",
}
Expand Down