From d7b84b6ebd304c41c11075b8ed68fe99329bd49c Mon Sep 17 00:00:00 2001 From: Developer Date: Thu, 15 Jan 2026 16:50:53 -0800 Subject: [PATCH] Mark network errors as retriable in authentication methods This change addresses an issue where network errors during authentication were being treated the same as invalid credentials, causing unnecessary reauth prompts when Home Assistant starts without network connectivity. Changes: - Mark network errors in sign_in() as retriable - Mark network errors in refresh_token() as retriable - This allows consuming code (e.g. Home Assistant integration) to distinguish between transient network failures and actual auth failures The retriable flag is set via the existing Nwp500Error.retriable attribute which was designed for this exact purpose. Fixes: Network errors during startup cause false reauth requests --- src/nwp500/auth.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nwp500/auth.py b/src/nwp500/auth.py index 6e4e451..08fcded 100644 --- a/src/nwp500/auth.py +++ b/src/nwp500/auth.py @@ -447,7 +447,10 @@ async def sign_in( except aiohttp.ClientError as e: _logger.error(f"Network error during sign-in: {e}") - raise AuthenticationError(f"Network error: {str(e)}") from e + raise AuthenticationError( + f"Network error: {str(e)}", + retriable=True, + ) from e except (KeyError, ValueError, json.JSONDecodeError) as e: _logger.error(f"Failed to parse authentication response: {e}") raise AuthenticationError( @@ -545,7 +548,10 @@ async def refresh_token( except aiohttp.ClientError as e: _logger.error(f"Network error during token refresh: {e}") - raise TokenRefreshError(f"Network error: {str(e)}") from e + raise TokenRefreshError( + f"Network error: {str(e)}", + retriable=True, + ) from e except (KeyError, ValueError, json.JSONDecodeError) as e: _logger.error(f"Failed to parse refresh response: {e}") raise TokenRefreshError(f"Invalid response format: {str(e)}") from e