Skip to content

Enhanced API Resilience#18

Merged
nshp merged 6 commits intonshp:mainfrom
opdx0:enhance-api-resilience
Oct 11, 2025
Merged

Enhanced API Resilience#18
nshp merged 6 commits intonshp:mainfrom
opdx0:enhance-api-resilience

Conversation

@opdx0
Copy link
Copy Markdown
Contributor

@opdx0 opdx0 commented Oct 2, 2025

Proposed change to solve the RESOURCE_EXHAUSTED errors caused by API rate-limiting.

Retry with Exponential Backoff: The core API call (fetch_vehicles) in python-lucidmotors will now automatically retry upon receiving a rate-limit error from the server, waiting for an increasing amount of time between attempts. (Implemented with tenacity).

Asynchronous Caching: The fetch_vehicles method is now cached for 15 seconds. This prevents multiple, redundant API calls from being made in quick succession (e.g., during Home Assistant startup or dashboard refreshes), reducing the load on the Lucid API. (Implemented with async-lru).

@nshp
Copy link
Copy Markdown
Owner

nshp commented Oct 2, 2025

Thanks! Bit busy now but I'll get to testing this next week.

@opdx0
Copy link
Copy Markdown
Contributor Author

opdx0 commented Oct 2, 2025

Thanks! Bit busy now but I'll get to testing this next week.

👍

Forgot to update the requirements and requirements_dev to add the new dependencies. Hopefully mypy will pass now.

Update is_rate_limit_error function to match what tenacity expects. Address mypy error: Argument 1 to "retry_if_exception" has incompatible type "Callable[[RpcError], bool]"; expected "Callable[[BaseException], bool]"  [arg-type]
Comment thread lucidmotors/__init__.py Outdated

return response

def is_rate_limit_error(exception: RpcError) -> bool:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type also needs to change now to BaseException, then we should be good :)

@nshp nshp merged commit 9ec6576 into nshp:main Oct 11, 2025
0 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants