Skip to content

Increase vehicle data refresh timeout from 10s to 30s#445

Open
chriscatuk wants to merge 1 commit into
DasBasti:mainfrom
chriscatuk:increase_timeout
Open

Increase vehicle data refresh timeout from 10s to 30s#445
chriscatuk wants to merge 1 commit into
DasBasti:mainfrom
chriscatuk:increase_timeout

Conversation

@chriscatuk

@chriscatuk chriscatuk commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Problem

My integration showed the car as unavailable almost permanently for the past few weeks. After checking the logs, the main culprit was timeouts.

The data update coordinator wraps account.get_vehicles() in asyncio.timeout(10). But a full successful refresh actually takes ~21s, because it's a long chain of sequential calls to Smart's cloud:

vehicle status → OTA info → journal authorisation → trip journal → ...

Debug log from a healthy refresh:

DEBUG [custom_components.smarthashtag] Finished fetching smarthashtag data in 21.144 seconds (success: True)

With the 10s timeout, this fetch reliably trips asyncio.timeout → raises UpdateFailed → all entities go unavailable, even when the API is perfectly healthy.

Change

Raise the timeout to 30s via a named API_TIMEOUT constant (matching the existing MAX_TRANSIENT_FAILURES style), so a normal refresh can complete and entities stay available.

Possible follow-up

Expose this as a configurable option in the options flow alongside scan_interval, since fetch time varies with how many sub-calls the backend performs.

Summary by CodeRabbit

  • Bug Fixes
    • Improved vehicle data refresh reliability by allowing more time for updates before timing out.
    • Standardized the refresh timeout to reduce unexpected interruptions during polling.

My integration showed the car as unavailable almost permanently for the
past few weeks. After checking the logs, the main culprit was timeouts:
increasing the timeout shows the full data fetch actually takes ~21s.

It's a long chain of sequential calls to Smart's cloud (vehicle status ->
OTA info -> journal authorisation -> trip journal -> ...). The old 10s
timeout tripped asyncio.timeout -> UpdateFailed -> entities went
unavailable even when the API was healthy. Raise the timeout to 30s via
a named API_TIMEOUT constant.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces a new API_TIMEOUT constant set to 30 seconds in the Smart vehicle coordinator, replacing the previous hardcoded 10-second timeout used in the _async_update_data refresh logic.

Changes

Coordinator Timeout Update

Layer / File(s) Summary
Introduce and apply API_TIMEOUT constant
custom_components/smarthashtag/coordinator.py
Adds a documented API_TIMEOUT = 30 constant and replaces the hardcoded asyncio.timeout(10) with asyncio.timeout(API_TIMEOUT) in _async_update_data.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: increasing the vehicle data refresh timeout from 10 seconds to 30 seconds.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
custom_components/smarthashtag/coordinator.py (1)

24-27: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider moving API_TIMEOUT to const.py.

The constant is well-named and documented, but per the repo's Python guidelines, constants should live in const.py rather than being defined inline in coordinator.py.

♻️ Suggested move
-# Timeout (seconds) for a full vehicle data refresh. A healthy refresh is a
-# chain of sequential Smart/Geely cloud calls that can legitimately take ~20s.
-API_TIMEOUT = 30
+from .const import API_TIMEOUT

And in const.py:

# Timeout (seconds) for a full vehicle data refresh. A healthy refresh is a
# chain of sequential Smart/Geely cloud calls that can legitimately take ~20s.
API_TIMEOUT = 30

As per coding guidelines, "Use constants from const.py instead of magic strings/numbers."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@custom_components/smarthashtag/coordinator.py` around lines 24 - 27, Move the
API_TIMEOUT constant out of coordinator.py and into const.py to match the repo’s
constant placement guidelines. Update the SmartHashtag coordinator to import
API_TIMEOUT from const.py, and remove the inline definition so the Coordinator
logic continues using the same symbol without changing behavior.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@custom_components/smarthashtag/coordinator.py`:
- Around line 24-27: Move the API_TIMEOUT constant out of coordinator.py and
into const.py to match the repo’s constant placement guidelines. Update the
SmartHashtag coordinator to import API_TIMEOUT from const.py, and remove the
inline definition so the Coordinator logic continues using the same symbol
without changing behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 38b88dfa-d6dc-4b28-b1b9-09704943c405

📥 Commits

Reviewing files that changed from the base of the PR and between 1805f8e and 4b4cb92.

📒 Files selected for processing (1)
  • custom_components/smarthashtag/coordinator.py

@chriscatuk

Copy link
Copy Markdown
Contributor Author

after a couple of days, I can say it never worked that well for so long. Never unavailable.

Could it be because I have 3 cars it was always slower than everyone else so I had more timeouts?

@chriscatuk

chriscatuk commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

after a couple of days, I can say it never worked that well for so long. Never unavailable.

Could it be because I have 3 cars it was always slower than everyone else so I had more timeouts?

I shouldn't have posted this... tonight I got back to the usual hours of "unavailable". But this time just reloading the integration was enough like it used to be. I think it proves this is a fix in itself already

I am working on a different branch to test improvement to the login journey resilence. I think this is the main issue but this timeout in this PR is already helping.

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.

1 participant