Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions custom_components/hilo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
from pyhilo.util import from_utc_timestamp, time_diff
from pysignalr.exceptions import ServerError as SignalRServerError

from .api import HiloAuth
from .config_flow import STEP_OPTION_SCHEMA, HiloFlowHandler
from .const import (
CONF_APPRECIATION_PHASE,
Expand Down Expand Up @@ -212,8 +213,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: HiloConfigEntry) -> bool
session=async_create_clientsession(
hass, cookie_jar=CookieJar(quote_cookie=False)
),
oauth_session=config_entry_oauth2_flow.OAuth2Session(
hass, entry, implementation
auth=HiloAuth(
config_entry_oauth2_flow.OAuth2Session(hass, entry, implementation)
),
log_traces=current_options.get(CONF_LOG_TRACES, DEFAULT_LOG_TRACES),
state_yaml=hass.config.path("hilo_state.yaml"),
Expand Down
17 changes: 17 additions & 0 deletions custom_components/hilo/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""API for Hilo bound to Home Assistant OAuth."""

from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session
from pyhilo import AbstractAuth


class HiloAuth(AbstractAuth):
"""Provide Hilo authentication tied to an OAuth2 based config entry."""

def __init__(self, oauth_session: OAuth2Session) -> None:
"""Initialize."""
self._oauth_session = oauth_session

async def async_get_access_token(self) -> str:
"""Return a valid access token, refreshing it first if it expired."""
await self._oauth_session.async_ensure_token_valid()
return str(self._oauth_session.token["access_token"])
2 changes: 1 addition & 1 deletion custom_components/hilo/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"documentation": "https://github.com/dvd-dev/hilo",
"iot_class": "cloud_push",
"issue_tracker": "https://github.com/dvd-dev/hilo/issues",
"requirements": ["python-hilo==2026.10.1"],
"requirements": ["python-hilo==2026.10.2"],
"version": "2026.10.3"
}
4 changes: 1 addition & 3 deletions custom_components/hilo/quality_scale.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ rules:
comment: entity.py exists; coordinator.py does not.
config-flow-test-coverage: todo
config-flow: done
dependency-transparency:
status: todo
comment: python-hilo imports homeassistant; fixed by python-hilo PR 460.
dependency-transparency: done
docs-actions:
status: exempt
comment: The integration does not register actions.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ test = [
"pytest",
"pytest-cov",
"pytest-homeassistant-custom-component>=0.13.0",
"python-hilo==2026.10.1",
"python-hilo==2026.10.2",
"bandit>=1.7.1",
"ruff>=0.17.2",
"pre-commit>=4.7.0",
Expand Down
19 changes: 19 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Tests for the Hilo auth bridge."""

from unittest.mock import AsyncMock, MagicMock

from homeassistant.helpers.config_entry_oauth2_flow import OAuth2Session

from custom_components.hilo.api import HiloAuth


async def test_access_token_refreshed_before_return() -> None:
"""The session is asked to refresh before its token is read."""
oauth_session = MagicMock(spec=OAuth2Session)
oauth_session.async_ensure_token_valid = AsyncMock()
oauth_session.token = {"access_token": "fresh-token"}

token = await HiloAuth(oauth_session).async_get_access_token()

oauth_session.async_ensure_token_valid.assert_awaited_once()
assert token == "fresh-token"
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading