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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement, BREAKING CHANGE - await for the unsubscribe()'s reply before closing the connection #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hass_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,13 @@ async def subscribe(
await self.send_command(**message_base, message_id=message_id)
self._subscriptions[message_id] = sub

def remove_listener():
async def remove_listener():
self._subscriptions.pop(message_id)
# try to unsubscribe
if "subscribe" not in message_base["type"]:
return
unsub_command = message_base["type"].replace("subscribe", "unsubscribe")
asyncio.create_task(self.send_command_no_wait(unsub_command, subscription=message_id))
await self.send_command(unsub_command, subscription=message_id)

return remove_listener

Expand Down