5 Commits
Author SHA1 Message Date
rickandCursor fe880f8f72 Config flow tests: assert only the reason placeholder
Reauth forms also carry Home Assistant's own name placeholder.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-07 11:27:25 +01:00
rickandCursor ec9347baac Test harness: pytest-homeassistant-custom-component 0.13.375 (core 2026.10.4)
The dev host has only Python 3.14; the 0.13.205 pin needs 3.12 (its numpy has no 3.14 wheel). The pycares 4.5.0 workaround is no longer needed: verify_cleanup passes with pycares 5.2.1.

Core 2026.x no longer treats a parked reauth flow as in progress for a new user flow with the same unique ID, so that path now aborts already_configured instead of already_in_progress. Both are translated; the test accepts either.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-07 11:27:25 +01:00
rickandCursor 20ed62b963 Sign in via Cognito directly so PerfectDraft gets the domain
PerfectDraft's Cognito PreAuthentication Lambda now requires a "domain"
field in ClientMetadata. The api.perfectdraft.com /authentication/sign-in
gateway does not forward it, so every setup and reauth failed with
"PreAuthentication failed with error 'domain'" (#11, #12, #13).
authenticate() now calls Cognito InitiateAuth (USER_PASSWORD_AUTH)
itself, the endpoint token refresh already uses.

A failed sign-in now says what was rejected and why. A wrong email or
password returns to the credentials form; a rejected token stays on the
token step; both show Cognito's reason instead of the old blanket "token
may have expired", which hid this outage.

The README snippet copies the token to the clipboard. It captures copy()
up front because Chromium removes it once the console command returns.

Root cause and fix by @cesa030 in #11; confirmed in @brettjenkins' fork.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-07 11:20:47 +01:00
rickandCursor 5d049c5529 fix: translate the already_in_progress abort, derive the reason set
Verification caught this change violating its own requirement that every
abort reason the flow can emit has a translation. async_set_unique_id()
defaults to raise_on_progress=True and raises already_in_progress when
another flow holds the same unique ID. That is reachable, and reachable
by exactly the users this change is for: park a reauth flow, give up,
try Add Integration for the same account, and the raw key surfaces.

The coverage test was hardcoded to three reasons, so it checked a "for
every" requirement against a list written by hand and passed anyway.
Replace it with an AST scan of config_flow.py that resolves each
aborting helper call to the reason it raises, honouring explicit reason=
and the raise_on_progress=False opt-out, plus a sanity test so a scanner
that goes blind fails instead of silently passing. Confirmed the new
check fails against the pre-fix translation files.

Also adds a regression test for the concurrent-flow path, which is the
evidence that this abort is real rather than theoretical.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-06 15:39:13 +02:00
rickandCursor 0f3b4c20af fix: make reauth update the existing entry instead of aborting
async_step_token is shared by the user and reauth sources but was written
only for the former. It called _abort_if_unique_id_configured() on every
path, and during reauth the unique ID belongs to the entry being repaired,
so the duplicate guard fired by design: authentication succeeded, the flow
aborted with already_configured, the new tokens were discarded, and the
coordinator's next poll re-raised the reauth repair. The integration was
unrecoverable through the UI short of delete-and-re-add, which costs entity
history and the restored keg-freshness baseline.

Branch on self.source at the terminal step, per HA's documented pattern for
flows shared between setup and reauth: reauth now guards with
_abort_if_unique_id_mismatch() and persists through
async_update_reload_and_abort(), which merges the new tokens into the
existing entry, keeps email and machine ID, reloads, and aborts with
reauth_successful. The user path keeps _abort_if_unique_id_configured()
unchanged.

Reauth also stops re-fetching /api/me when the entry already records a
machine ID, removing a round trip from a flow the user waits on and a
failure mode where a transient /api/me error turned a successful sign-in
into cannot_connect.

The helpers require core 2024.11, so declare that floor in hacs.json —
otherwise older cores would AttributeError mid-flow, which is worse than
the bug being fixed.

Adds the repo's first HA test harness (requirements-test.txt, opt-in) with
regression tests covering token persistence, entry reload, account
mismatch, case-insensitive email, and the explicit assertion that reauth
never aborts as already_configured. tests/test_keg_detection.py still runs
standalone under python3 -m unittest.

Version set to 0.3.1 rather than the 0.4.0 that PR #2 introduced; no
v0.4.0 tag was ever cut, so nothing was released under that number.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-06 15:26:48 +02:00