Skip to content

Fix Hive reauth loop by persisting device metadata; add debug 2FA toggle#193

Merged
KJonline merged 1 commit into
Pyhass:masterfrom
tamunro93:codex/hive-auth-device-metadata-debug-toggle
Feb 27, 2026
Merged

Fix Hive reauth loop by persisting device metadata; add debug 2FA toggle#193
KJonline merged 1 commit into
Pyhass:masterfrom
tamunro93:codex/hive-auth-device-metadata-debug-toggle

Conversation

@tamunro93

Copy link
Copy Markdown
Contributor

This PR addresses a reauth loop seen when Hive refresh token fallback occurs after an initially successful login.

In affected cases, login returns AuthenticationResult with NewDeviceMetadata, but device_data is not persisted in the config entry. Later fallback device auth then fails and repeatedly reauths.

This PR:

  • persists/registers device metadata immediately when login succeeds with NewDeviceMetadata
  • adds an optional Disable 2FA (debug) toggle in config flow for troubleshooting
  • adds sanitized auth payload logging (tokens/secrets masked)
  • updates dependency to pyhive-integration==1.0.8.dev10 (as currently tested)

Changes

  • config_flow.py
  • replaces passthrough flow with local flow implementation
  • on successful login, if AuthenticationResult.NewDeviceMetadata exists:
  • sets auth access/device fields
  • performs device_registration
  • persists self.data["device_data"] = await self.hive_auth.get_device_data()
  • adds optional debug toggle for bypassing MFA submission during diagnostics
  • adds sanitized debug/warn logging for auth payloads
  • const.py
  • adds CONF_DISABLE_2FA_DEBUG
  • strings.json
  • en.json
  • adds UI/error text for debug toggle path
  • manifest.json
  • pyhive-integration -> 1.0.8.dev10

Repro / Symptoms
Observed recurring errors before fix:

  • Refresh token is invalid or expired
  • Device login failed: expected DEVICE_SRP_AUTH challenge, got None
  • Config entry ... could not authenticate
  • Result

After this patch, device_data is persisted for successful login flows returning NewDeviceMetadata, and the reauth loop is resolved in my tested environment.

Notes:

I understand 1.0.8.dev10 is a dev dependency and may change before official 1.0.8. Happy to adjust dependency/version strategy based on maintainer preference. Also, thanks for the heads-up on the other 1.0.8 dev PR; happy to align/rebase this against it or reduce this PR to only the debug-toggle bits if preferred.

@KJonline

Copy link
Copy Markdown
Contributor

@tamunro93 i've just released the official version on 1.0.8 Do you want to update your PR to use that version please.

@KJonline KJonline merged commit 4c8bf45 into Pyhass:master Feb 27, 2026
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.

2 participants