Skip to content

Commit

Permalink
Make sure 429 is logged only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ReneNulschDE committed Dec 6, 2024
1 parent 8b0e8a7 commit b3f18ed
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions custom_components/mbapi2020/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(
self.ws_connect_retry_counter_reseted: bool = False
self.ws_connect_retry_counter: int = 0
self.account_blocked: bool = False
self.ws_blocked_connection_error_logged = False

async def async_connect(self, on_data=None) -> None:
"""Connect to the socket."""
Expand Down Expand Up @@ -221,14 +222,17 @@ async def _start_websocket_handler(self, session: ClientSession):
retry_in = retry_in * 2 if retry_in < 120 else 120
self.ws_connect_retry_counter += 1
except WSServerHandshakeError as error:
LOGGER.info("WSS Connection blocked: %s, retry in %s seconds...", error, retry_in)
LOGGER.debug(error)
if not self.ws_blocked_connection_error_logged:
LOGGER.error("MB-API access blocked. %s, retry in %s seconds...", error, retry_in)
self.ws_blocked_connection_error_logged = True
else:
LOGGER.info("WSS Connection blocked: %s, retry in %s seconds...", error, retry_in)
if "429" in str(error.code):
self.account_blocked = True
self.ws_connect_retry_counter += 1
self.connection_state = STATE_RECONNECTING
await asyncio.sleep(retry_in)
retry_in = retry_in * 2 if retry_in < 120 else 120
retry_in = retry_in * self.ws_connect_retry_counter * self.ws_connect_retry_counter
except Exception as error:
LOGGER.error("Other error %s", error)
raise
Expand Down

0 comments on commit b3f18ed

Please sign in to comment.