Skip to content

Fix timeout type in has_v2_api using ClientTimeout - #640

Merged
hoefnageltom merged 3 commits into
homewizard:mainfrom
Livyon:patch-1
Nov 25, 2026
Merged

hoefnageltom merged 3 commits into
homewizard:mainfrom
Livyon:patch-1

Conversation

@Livyon

@Livyon Livyon commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Proposed change

Fix timeout type in has_v2_api using ClientTimeout

This PR updates has_v2_api to pass ClientTimeout(total=5) instead of an int (timeout=5) to websession.get().

aiohttp expects a ClientTimeout instance for the timeout parameter. Passing an integer causes an error inside aiohttp (such as AttributeError), which is silently caught by the broad except Exception: block and causes has_v2_api to return False.

Using ClientTimeout(total=5) fixes the timeout handling as intended.

Type of change

  • Bugfix
  • New feature
  • Breaking change

Refactor API call to include timeout handling.
@Livyon

Livyon commented Nov 14, 2026

Copy link
Copy Markdown
Contributor Author

Hi maintainers, could someone please approve and run the GitHub Actions workflows for this PR? The runs expired while awaiting approval, so the checks have not actually run. If the expired runs can’t be approved anymore, could you please trigger new runs? Thanks!

@hoefnageltom hoefnageltom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologies for the late response.

For the change. I currently don't see your reasoning, asyncio.timeout() works by cancelling the task, which only happens when the event loop gets control back. If something is really blocking the loop with synchronous work, the timeout can't fire either. So this change can't fix "blocking the main event loop".

Comment thread homewizard_energy/__init__.py Resolved
Comment thread homewizard_energy/__init__.py Resolved
Updated the API request to use ClientTimeout for better timeout handling.
@Livyon Livyon changed the title Fix event-loop blocking in has_v2_api by using asyncio.timeout Fix timeout type in has_v2_api using ClientTimeout Nov 24, 2026
@Livyon

Livyon commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review and feedback, @hoefnageltom! You are completely right on both points:

  1. asyncio.timeout() wouldn't resolve synchronous blocking, and asyncio wasn't imported in init.py.
  2. Passing timeout=5 as an int instead of ClientTimeout(total=5) is indeed the actual bug here (causing an AttributeError in aiohttp which gets swallowed by the broad except Exception).

I've updated the PR to use ClientTimeout(total=5) as suggested and will update the PR description accordingly.

@Livyon
Livyon requested a review from hoefnageltom November 24, 2026 21:31
@codecov

codecov Bot commented Nov 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.28%. Comparing base (9b891cc) to head (858c888).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #640   +/-   ##
=======================================
  Coverage   99.28%   99.28%           
=======================================
  Files           9        9           
  Lines         704      704           
  Branches       70       70           
=======================================
  Hits          699      699           
  Misses          2        2           
  Partials        3        3           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hoefnageltom hoefnageltom left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for your contribution! Looks good now

@hoefnageltom
hoefnageltom merged commit ebe44f7 into homewizard:main Nov 25, 2026
32 checks passed
lexpostma added a commit that referenced this pull request Nov 25, 2026
Keep this branch's has_v2_api. It no longer sends the aiohttp request that
#640 fixed the timeout of; the TLS connection and the GET /api response use
asyncio.wait_for with a 5 second timeout instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Livyon
Livyon deleted the patch-1 branch November 25, 2026 17:02
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