Skip to content

Commit

Permalink
Fix issue where an error is thrown during disconnect because the unsu…
Browse files Browse the repository at this point in the history
…bscribe request hasn't been completed
  • Loading branch information
natekspencer committed Sep 16, 2021
1 parent 7f5308a commit 5a27289
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = vivintpy
version = 2021.9.6
version = 2021.9.7
author = Nathan Spencer
author_email = [email protected]
description = Python library for interacting with the Vivint Sky API.
Expand Down
19 changes: 18 additions & 1 deletion vivintpy/account.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module that implements the Vivint class."""
import asyncio
import logging
from typing import List, Optional

Expand Down Expand Up @@ -80,11 +81,27 @@ async def disconnect(self) -> None:
if self.connected:
if self.__pubnub:
self.__pubnub.remove_listener(self.__pubnub_listener)
self.__pubnub.unsubscribe_all()
await self.__pubnub_unsubscribe_all()
await self.__pubnub.stop()
await self.vivintskyapi.disconnect()
self.__connected = False

async def __pubnub_unsubscribe_all(self) -> None:
"""
Unsubscribe from all channels and wait for the response.
The pubnub code doesn't properly wait for the unsubscribe event to finish or to
be canceled, so we have to manually do it by finding the coroutine in asyncio.
"""
self.__pubnub.unsubscribe_all()
tasks = [
task
for task in asyncio.all_tasks()
if getattr(getattr(task.get_coro(), "cr_code", None), "co_name", None)
== "_send_leave_helper"
]
await asyncio.gather(*tasks)

async def verify_mfa(self, code: str) -> None:
"""Verify multi-factor authentication with the VivintSky API."""
await self.vivintskyapi.verify_mfa(code)
Expand Down
2 changes: 1 addition & 1 deletion vivintpy/zjs_device_config_db.json
Original file line number Diff line number Diff line change
Expand Up @@ -13424,5 +13424,5 @@
"label": "BW8120",
"manufacturer": "Remotec"
},
"updated_at": "2021-09-16T18:02:36.075009"
"updated_at": "2021-09-16T22:13:06.015662"
}

0 comments on commit 5a27289

Please sign in to comment.