Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh nest access token before before building subscriber Credentials #138259

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
15 changes: 8 additions & 7 deletions homeassistant/components/nest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ async def async_get_access_token(self) -> str:
return cast(str, self._oauth_session.token["access_token"])

async def async_get_creds(self) -> Credentials:
"""Return an OAuth credential for Pub/Sub Subscriber."""
# We don't have a way for Home Assistant to refresh creds on behalf
# of the google pub/sub subscriber. Instead, build a full
# Credentials object with enough information for the subscriber to
# handle this on its own. We purposely don't refresh the token here
# even when it is expired to fully hand off this responsibility and
# know it is working at startup (then if not, fail loudly).
"""Return an OAuth credential for Pub/Sub Subscriber.

The subscriber will call this when connecting to the stream to refresh
the token. We construct a credentials object using the underlying
OAuth2Session since the subscriber may expect the expiry fields to
be present.
"""
await self.async_get_access_token()
token = self._oauth_session.token
creds = Credentials( # type: ignore[no-untyped-call]
token=token["access_token"],
Expand Down