♻️ Rely on the client's auto-reauth instead of coordinator-level re-auth #39

Merged
mat merged 1 commit from coordinator-client-auto-reauth into main 2026-07-10 14:20:55 +00:00
Owner

Problem

The coordinator predates the client's auto_reauth: it detects credential failures by string-matching "401"/"403" in exception messages (internal _AuthError) and re-authenticates + retries the whole fetch on any exception. Since comwatt-client 0.3.x the client re-authenticates expired sessions itself, and since 0.3.4 ComwattAuthError reliably means credentials rejected (401/403) or session invalid.

The broad per-device except Exception blocks also swallowed a ComwattAuthError (password changed mid-cycle → entities silently None for a cycle instead of triggering the reauth flow).

Change

  • Deleted _AuthError, the string matching, and the re-auth + retry block — the client owns session recovery now
  • _async_update_data: ComwattAuthErrorConfigEntryAuthFailed (reauth flow), anything else → UpdateFailed (retry next cycle)
  • Initial authenticate() inlined in _fetch_all (still needed once so the client can auto-reauth later)
  • The 4 per-device/site fetch guards re-raise ComwattAuthError instead of swallowing it

Net: -12 lines in the coordinator, no more message parsing.

Tests

  • test_setup_starts_reauth_on_bad_credentials: 401 → SETUP_ERROR + reauth flow started
  • test_auth_error_mid_fetch_is_not_swallowed: auth error from a device fetch propagates (no silent None data) and authenticate.call_count == 1 proves no coordinator-level re-auth
  • test_setup_retry_on_transient_network_error unchanged (generic errors still → SETUP_RETRY)
  • 29/29, mypy clean, ruff clean

Depends on comwatt-client 0.3.4 (#37, merged). Independent of #38 (config_flow).

## Problem The coordinator predates the client's `auto_reauth`: it detects credential failures by string-matching `"401"/"403"` in exception messages (internal `_AuthError`) and re-authenticates + retries the whole fetch on **any** exception. Since comwatt-client 0.3.x the client re-authenticates expired sessions itself, and since **0.3.4** `ComwattAuthError` reliably means *credentials rejected (401/403) or session invalid*. The broad per-device `except Exception` blocks also swallowed a `ComwattAuthError` (password changed mid-cycle → entities silently `None` for a cycle instead of triggering the reauth flow). ## Change - Deleted `_AuthError`, the string matching, and the re-auth + retry block — the client owns session recovery now - `_async_update_data`: `ComwattAuthError` → `ConfigEntryAuthFailed` (reauth flow), anything else → `UpdateFailed` (retry next cycle) - Initial `authenticate()` inlined in `_fetch_all` (still needed once so the client can auto-reauth later) - The 4 per-device/site fetch guards re-raise `ComwattAuthError` instead of swallowing it Net: **-12 lines** in the coordinator, no more message parsing. ## Tests - `test_setup_starts_reauth_on_bad_credentials`: 401 → `SETUP_ERROR` + reauth flow started - `test_auth_error_mid_fetch_is_not_swallowed`: auth error from a device fetch propagates (no silent `None` data) and `authenticate.call_count == 1` proves no coordinator-level re-auth - `test_setup_retry_on_transient_network_error` unchanged (generic errors still → `SETUP_RETRY`) - 29/29, mypy clean, ruff clean Depends on comwatt-client 0.3.4 (#37, merged). Independent of #38 (config_flow).
mat changed title from WIP: ♻️ Rely on the client's auto-reauth instead of coordinator-level re-auth to ♻️ Rely on the client's auto-reauth instead of coordinator-level re-auth 2026-07-10 14:19:24 +00:00
mat merged commit f2567652ca into main 2026-07-10 14:20:55 +00:00
mat deleted branch coordinator-client-auto-reauth 2026-07-10 14:20:56 +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!39
No description provided.