HomeAssistantAPI icon indicating copy to clipboard operation
HomeAssistantAPI copied to clipboard

Add async Websocket client

Open mj23000 opened this issue 3 months ago • 6 comments

This async version of the Websocket client is mostly just an async version of the existing client, though with the addition of a RawBaseWebsocketClient that is inherited from by both clients.

~~No clever handling of the client type has been implemented as with the REST API client with use_async. This does have the benefit of not being a breaking change.~~

A similar structure to the existing REST API client has been implemented.

Commits will be cleaned up when the PR is more ready to be merged.

mj23000 avatar Sep 11 '25 10:09 mj23000

I'm going to convert this to a draft PR, and then you'll convert it back when its ready to be reviewed and merged for real.

GrandMoff100 avatar Sep 24 '25 06:09 GrandMoff100

Looks really awesome! Thank you so much!!!

That just leaves the last thing to do which is to add tests for each of the async websocket methods.

That should be it. I can't see the coverage, but hopefully I've covered everything.

mj23000 avatar Sep 25 '25 13:09 mj23000

Codecov Report

:x: Patch coverage is 87.63441% with 46 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 96.49%. Comparing base (e3ea524) to head (9b905d9). :warning: Report is 4 commits behind head on dev.

Files with missing lines Patch % Lines
homeassistant_api/rawasyncwebsocket.py 85.02% 25 Missing :warning:
homeassistant_api/rawwebsocket.py 82.22% 16 Missing :warning:
homeassistant_api/rawbasewebsocket.py 92.00% 4 Missing :warning:
homeassistant_api/websocket.py 90.90% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #212      +/-   ##
==========================================
- Coverage   97.44%   96.49%   -0.96%     
==========================================
  Files          25       27       +2     
  Lines        1647     1883     +236     
==========================================
+ Hits         1605     1817     +212     
- Misses         42       66      +24     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

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

codecov[bot] avatar Sep 30 '25 16:09 codecov[bot]

I can't see the coverage

I finally figured out why. Codecov recently changed their behavior so that github actions running on forks now require a CODECOV_TOKEN to upload coverage reports (they say it was for ratelimiting purposes, but its annoying). We have a CODECOV_TOKEN secret setup to work with that. However, secrets are not passed to forked repo actions by default for security purposes. This repository is configured so that first time contributors require approval to run workflows, and I was under the impression that after approving it, that the workflows would be able to access the secrets for that workflow. But that is not the case, so I just decided to hardcode the token in a config file since this is a public repository, the token is not really sensitive, so it's not the best solution, but its fine for now.

GrandMoff100 avatar Sep 30 '25 16:09 GrandMoff100

@mj23000 I am happy to aid you in developing the tests we need to increase the coverage. There are some parts of the codebase that need some clever ideas to test them appropriately.

GrandMoff100 avatar Sep 30 '25 17:09 GrandMoff100

@mj23000 I am happy to aid you in developing the tests we need to increase the coverage. There are some parts of the codebase that need some clever ideas to test them appropriately.

Yes that sounds good!

mj23000 avatar Oct 01 '25 07:10 mj23000