diff --git a/custom_components/haefele_connect_mesh/__init__.py b/custom_components/haefele_connect_mesh/__init__.py index e855ee0..2b22586 100644 --- a/custom_components/haefele_connect_mesh/__init__.py +++ b/custom_components/haefele_connect_mesh/__init__.py @@ -36,7 +36,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: # Create API client session = async_get_clientsession(hass) - client = HafeleClient(entry.data["api_token"], session) + client = HafeleClient(entry.data["api_token"], session, timeout=10) # Store client for use by platforms hass.data[DOMAIN][entry.entry_id] = { diff --git a/custom_components/haefele_connect_mesh/api/client.py b/custom_components/haefele_connect_mesh/api/client.py index 3fe4bd7..6572903 100644 --- a/custom_components/haefele_connect_mesh/api/client.py +++ b/custom_components/haefele_connect_mesh/api/client.py @@ -37,7 +37,7 @@ def __init__( } logger.debug("Initialized HafeleClient with base URL: %s", self._base_url) - @retry_with_backoff(max_delay=8.0) + @retry_with_backoff(base_delay=0.5, max_delay=4.0, jitter_range=0.5) async def _request( self, method: str, endpoint: str, timeout: Optional[int] = None, **kwargs: Any ) -> aiohttp.ClientResponse: diff --git a/custom_components/haefele_connect_mesh/config_flow.py b/custom_components/haefele_connect_mesh/config_flow.py index 3fd2bc1..39f95aa 100644 --- a/custom_components/haefele_connect_mesh/config_flow.py +++ b/custom_components/haefele_connect_mesh/config_flow.py @@ -38,7 +38,7 @@ async def _validate_api_token(self, api_token: str) -> tuple[bool, str | None]: Tuple of (success, error_message) """ session = async_get_clientsession(self.hass) - client = HafeleClient(api_token, session) + client = HafeleClient(api_token, session, timeout=6) try: networks = await client.get_networks() diff --git a/custom_components/haefele_connect_mesh/utils/retry.py b/custom_components/haefele_connect_mesh/utils/retry.py index 0be8cc1..a39807c 100644 --- a/custom_components/haefele_connect_mesh/utils/retry.py +++ b/custom_components/haefele_connect_mesh/utils/retry.py @@ -92,7 +92,7 @@ async def wrapper(*args: Any, **kwargs: Any) -> T: delay = min(base_delay * (2 ** (attempt - 1)), max_delay) # Add random jitter jitter = random.uniform(-jitter_range, jitter_range) - total_delay = max(delay + jitter, 0.1) + total_delay = max(delay + jitter, base_delay) logger.debug( "Retrying request after %.2f seconds (attempt %d/%d)",