Skip to content

fix: short-circuit get_master_token() when master_token already stored - #1042

Open
githubhjs wants to merge 1 commit into
leikoilja:masterfrom
githubhjs:fix/master-token-password-none-bug
Open

fix: short-circuit get_master_token() when master_token already stored#1042
githubhjs wants to merge 1 commit into
leikoilja:masterfrom
githubhjs:fix/master-token-password-none-bug

Conversation

@githubhjs

Copy link
Copy Markdown

Problem

glocaltokens 0.7.6 has an early-return guard in get_master_token():

if self.username is None or self.password is None:
    return None  # (simplified)

This fires before the method checks whether master_token is already populated. As a result, when the integration is configured with a valid aas_et/... master token but an empty password (which is the case when users obtain the token via the browser OAuth / gpsoauth.exchange_token() workaround), every call to get_master_token() returns None and raises InvalidMasterToken — even though the token is sitting right there in self._client.master_token.

Fix

Short-circuit before delegating to the library: if self._client.master_token already holds a valid aas_et token, return it directly.

if self._client.master_token and is_aas_et(self._client.master_token):
    return self._client.master_token
return self._client.get_master_token()

is_aas_et is already imported in this file, so no new imports are needed.

Repro

  1. Obtain a master token via gpsoauth.exchange_token() (needed because the standard Android login endpoint now returns BadAuthentication)
  2. Configure the integration with master_token=<aas_et/...>, password=""
  3. Without this fix: every coordinator refresh raises InvalidMasterToken
  4. With this fix: token is returned correctly, devices are discovered and sensors update normally

Notes

  • The root cause lives in glocaltokens — a fix there would be cleaner. This is a targeted workaround in api.py that unblocks users until the dependency is updated.
  • Tested on ha-google-home v1.13.3 with glocaltokens 0.7.6.

glocaltokens 0.7.6 has a guard `if self.username is None or self.password
is None` that returns early before checking whether master_token is already
populated. When the integration is configured with a master token but no
password (e.g. via the manual token flow), get_master_token() always returns
None, causing every auth attempt to raise InvalidMasterToken.

Fix: check self._client.master_token directly first; only fall through to
the library when no valid aas_et token is present.

Co-Authored-By: Claude Sonnet 4.6 <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