🐛 Show invalid_auth for rejected credentials in the config flow #38

Merged
mat merged 1 commit from config-flow-typed-exceptions into main 2026-07-10 14:39:48 +00:00
Owner

Problem

validate_input maps every authenticate() failure to cannot_connect, so a wrong password shows the user a misleading error. Its InvalidAuth branch (the cwt_session cookie check) is dead code: since comwatt-client 0.3.x, authenticate() itself raises when the cookie is missing.

Change

  • ComwattAuthError (credentials rejected, 401/403) → invalid_auth
  • any other exception (5xx outage, network) → cannot_connect, as before
  • removed the dead cookie check + the now-unused _FakeCookie/_FakeCookieJar test plumbing

Tests

  • test_invalid_auth_when_credentials_rejected (401 → invalid_auth) — replaces the cookie-based test
  • New test_cannot_connect_on_server_error (503 → cannot_connect, guards against outages being misreported as bad passwords)
  • Reauth flow test updated the same way
  • 30/30, mypy clean, ruff clean

⚠️ Merge after #37 (bump to comwatt-client 0.3.4): the ComwattAuthError ⇒ "credentials rejected" guarantee only holds from 0.3.4.

## Problem `validate_input` maps **every** `authenticate()` failure to `cannot_connect`, so a wrong password shows the user a misleading error. Its `InvalidAuth` branch (the `cwt_session` cookie check) is dead code: since comwatt-client 0.3.x, `authenticate()` itself raises when the cookie is missing. ## Change - `ComwattAuthError` (credentials rejected, 401/403) → `invalid_auth` - any other exception (5xx outage, network) → `cannot_connect`, as before - removed the dead cookie check + the now-unused `_FakeCookie`/`_FakeCookieJar` test plumbing ## Tests - `test_invalid_auth_when_credentials_rejected` (401 → `invalid_auth`) — replaces the cookie-based test - New `test_cannot_connect_on_server_error` (503 → `cannot_connect`, guards against outages being misreported as bad passwords) - Reauth flow test updated the same way - 30/30, mypy clean, ruff clean ⚠️ **Merge after #37** (bump to comwatt-client 0.3.4): the `ComwattAuthError` ⇒ "credentials rejected" guarantee only holds from 0.3.4.
mat force-pushed config-flow-typed-exceptions from 5efc458b43 to 24a97d89dc
All checks were successful
Validate / lint-ruff (push) Successful in 7s
Validate / test-pytest (push) Successful in 3m0s
Validate / type-check-mypy (push) Successful in 3m9s
Validate / lint-ruff (pull_request) Successful in 8s
Validate / test-pytest (pull_request) Successful in 3m1s
Validate / type-check-mypy (pull_request) Successful in 3m8s
2026-07-10 14:35:35 +00:00
Compare
mat changed title from WIP: 🐛 Show invalid_auth for rejected credentials in the config flow to 🐛 Show invalid_auth for rejected credentials in the config flow 2026-07-10 14:39:42 +00:00
mat merged commit 23407b374c into main 2026-07-10 14:39:48 +00:00
mat deleted branch config-flow-typed-exceptions 2026-07-10 14:39:48 +00:00
mat referenced this pull request from a commit 2026-07-10 14:55:15 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
mat/homeassistant-comwatt!38
No description provided.