Skip to content

Commit

Permalink
fix: update check for number of websocket errors
Browse files Browse the repository at this point in the history
Because the error counter can be changed asynchronously, the local
variable needs to be refreshed after regaining control.
  • Loading branch information
alandtse committed Mar 29, 2020
1 parent 6107134 commit bc2677d
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
https://community.home-assistant.io/t/echo-devices-alexa-as-media-player-testers-needed/58639
"""
from datetime import datetime, timedelta
import aiohttp
import logging
import time
from typing import List, Optional, Text
Expand Down Expand Up @@ -971,6 +970,7 @@ async def ws_close_handler():
)
delay = 5 * 2 ** errors
await sleep(delay)
errors = hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"]
_LOGGER.debug(
"%s: Websocket closed; retries exceeded; polling", hide_email(email)
)
Expand All @@ -996,10 +996,7 @@ async def ws_error_handler(message):
type(message),
)
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocket"] = None
if (
isinstance(message, aiohttp.streams.EofStream)
or message == "<class 'aiohttp.streams.EofStream'>"
):
if message == "<class 'aiohttp.streams.EofStream'>":
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = 5
_LOGGER.debug("%s: Immediate abort on EoFstream", hide_email(email))
hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocketerror"] = errors + 1
Expand Down

0 comments on commit bc2677d

Please sign in to comment.