Skip to content

Refactor/pass auth to library - #1099

Open
ic-dev21 wants to merge 5 commits into
mainfrom
refactor/pass-auth-to-library
Open

ic-dev21 wants to merge 5 commits into
mainfrom
refactor/pass-auth-to-library

Conversation

@ic-dev21

Copy link
Copy Markdown
Collaborator

Why

python-hilo used to import Home Assistant directly so it could take an OAuth2Session. A library depending on its host framework fails the dependency-transparency rule of the Integration Quality Scale, and it ties python-hilo releases to HA internals.

python-hilo now defines an AbstractAuth interface instead (dvd-dev/python-hilo#460). The library only asks for a valid access token. The integration decides how to get one.

What changed

  • custom_components/hilo/api.py: new HiloAuth class. It implements AbstractAuth by wrapping HA's OAuth2Session: it calls async_ensure_token_valid() and then returns the current access token. Token refresh therefore stays with HA's OAuth2 helper, as it did before.
  • __init__.py: API gets auth=HiloAuth(...) instead of oauth_session=....
  • quality_scale.yaml: dependency-transparency is now marked done.
  • tests/test_api.py: checks that the token is refreshed before it is returned.

Dependency

This needs a python-hilo release that includes AbstractAuth. The latest tag, 2026.10.1, doesn't have it. Before merging, manifest.json and pyproject.toml both need to be bumped to the same new version.

Testing

  • uv run pytest
  • Manual check against a local HA instance (scripts/develop) with the editable python-hilo install: setup works and tokens still refresh.

🤖 Generated with Claude Code

@ic-dev21

Copy link
Copy Markdown
Collaborator Author

CI failure is normal, python-hilo isn't released.

HiloAuth implements the AbstractAuth interface, which first ships in
python-hilo 2026.10.2. With the old pin, CI installed 2026.10.1 and every
test failed at import time while loading conftest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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