Repository navigation
Decouple from Home Assistant with an AbstractAuth interface - #460
Open
Moustachauve wants to merge 3 commits into
Open
Moustachauve wants to merge 3 commits into
Moustachauve wants to merge 3 commits into
Conversation
pyhilo.api imported homeassistant.helpers.config_entry_oauth2_flow at module level, but homeassistant is not (and should not be) a dependency. Importing pyhilo outside Home Assistant failed with ModuleNotFoundError, and the test suite only passed because conftest.py injected fake homeassistant modules into sys.modules. API now takes an auth argument implementing pyhilo.auth.AbstractAuth, following Home Assistant's recommended pattern for API libraries: the library defines the interface, and the integration wraps its own OAuth2Session. The URN is decoded from the last token returned by the auth provider instead of reading the session directly. The oauth_session argument is still accepted, adapted internally and logged as deprecated, because already-released integration versions declare python-hilo>= and would otherwise break on a fresh install. It should be removed after a couple of releases. The raw access token is no longer logged at DEBUG level, since it ended up in Home Assistant logs.
Custom test stub classes have been replaced with standard unittest.mock fixtures and AsyncMock/MagicMock assertions to eliminate boilerplate. Edge cases for URN claim extraction and invalid auth initialization parameters are now parametrized with matching error assertions.
Moustachauve
marked this pull request as ready for review
October 5, 2026 03:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace Home Assistant OAuth2Session dependency with AbstractAuth.
pyhilo.apiimportedhomeassistantat module level, buthomeassistantis not declared as a package dependency. This causedModuleNotFoundErrorwhenever importingpyhiloin standard Python environments (such as CLI tools or isolated tests), and required artificial monkey-patching inconftest.pyfor local tests to pass.To eliminate this circular coupling,
APInow relies on anAbstractAuthprotocol following Home Assistant's library guidance. For compatibility with existing integration releases, passingoauth_sessionis temporarily retained and adapted via duck-typing, but logs a deprecation warning and should be removed after a couple of releases.