Skip to content

Commit

Permalink
fix: add further session closed checks
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed May 12, 2020
1 parent 7bf4139 commit 118f644
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ async def async_update_data():
if (
email not in hass.data[DATA_ALEXAMEDIA]["accounts"]
or "login_successful" not in login_obj.status
or login_obj.session.closed
):
return
existing_serials = _existing_serials(hass, login_obj)
Expand Down Expand Up @@ -577,6 +578,12 @@ async def ws_connect() -> WebsocketEchoClient:
"""
websocket: Optional[WebsocketEchoClient] = None
try:
if login_obj.session.closed:
_LOGGER.debug(
"%s: Websocket creation aborted. Session is closed.",
hide_email(email),
)
return
websocket = WebsocketEchoClient(
login_obj,
ws_handler,
Expand Down Expand Up @@ -853,7 +860,7 @@ async def ws_error_handler(message):
type(message),
)
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocket"] = None
if message == "<class 'aiohttp.streams.EofStream'>":
if login_obj.session.closed or message == "<class 'aiohttp.streams.EofStream'>":
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = 5
_LOGGER.debug("%s: Immediate abort on EoFstream", hide_email(email))
return
Expand Down Expand Up @@ -937,7 +944,7 @@ async def close_connections(hass, email: Text) -> None:
login_obj = account_dict["login_obj"]
await login_obj.close()
_LOGGER.debug(
"%s: Connection closed: %s", hide_email(email), login_obj._session.closed
"%s: Connection closed: %s", hide_email(email), login_obj.session.closed
)
await clear_configurator(hass, email)

Expand Down

0 comments on commit 118f644

Please sign in to comment.