From b3f18ed4a6cc4c9ae3b8bc61530ea416d48d0020 Mon Sep 17 00:00:00 2001 From: Rene Nulsch Date: Fri, 6 Dec 2024 21:27:58 +0100 Subject: [PATCH] Make sure 429 is logged only once --- custom_components/mbapi2020/websocket.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/custom_components/mbapi2020/websocket.py b/custom_components/mbapi2020/websocket.py index 44659c72..d500998c 100644 --- a/custom_components/mbapi2020/websocket.py +++ b/custom_components/mbapi2020/websocket.py @@ -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.""" @@ -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