Skip to content

Fix notification flow by removing backwards dependency chain#571

Merged
danieldotnl merged 1 commit intomasterfrom
feature/553-fix-notification-flow
Mar 13, 2026
Merged

Fix notification flow by removing backwards dependency chain#571
danieldotnl merged 1 commit intomasterfrom
feature/553-fix-notification-flow

Conversation

@danieldotnl
Copy link
Copy Markdown
Owner

@danieldotnl danieldotnl commented Mar 13, 2026

Summary

  • Replaces the 4-layer notify_scrape_exception() backwards chain (Entity → Coordinator → ContentRequestManager → HttpSession → FormAuthenticator) with a forward-only flow
  • The coordinator now owns a _force_reauth flag and passes it forward via get_content(force_reauth=...) at request time
  • Renamed methods to reflect their purpose: invalidate() on FormAuthenticator, invalidate_auth() on HttpSession, request_reauth() on Coordinator

Test plan

  • All 307 tests pass (pytest tests/)
  • New integration test verifies full flag lifecycle: request_reauth()force_reauth=Trueinvalidate_auth() called → flag reset
  • Zero references to old notify_scrape_exception remain in source code
  • Pre-commit hooks (ruff, codespell, isort, pytest) all pass

Closes #553

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of authentication failures during data scraping operations with automatic re-authentication on next update cycle
    • Enhanced session state recovery for more reliable error handling

Replace the 4-layer notify_scrape_exception() chain with a forward-only
flow where the coordinator owns a _force_reauth flag and passes it to
ContentRequestManager.get_content() at request time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 991aa075-c0ef-4409-9d1b-a7a05b3c035c

📥 Commits

Reviewing files that changed from the base of the PR and between e07c4e0 and d74082d.

📒 Files selected for processing (8)
  • custom_components/multiscrape/binary_sensor.py
  • custom_components/multiscrape/coordinator.py
  • custom_components/multiscrape/form_auth.py
  • custom_components/multiscrape/http_session.py
  • custom_components/multiscrape/sensor.py
  • tests/conftest.py
  • tests/test_coordinator.py
  • tests/test_http_session.py

📝 Walkthrough

Walkthrough

The PR replaces a backwards notify_scrape_exception() notification chain with a forward-facing re-authentication request mechanism. High-level components (sensor, binary_sensor) now call request_reauth() on the coordinator, which sets an internal flag to trigger session invalidation on the next update cycle.

Changes

Cohort / File(s) Summary
Coordinator Re-auth Logic
custom_components/multiscrape/coordinator.py
Introduced _force_reauth flag and request_reauth() method to coordinate re-authentication. Modified ContentRequestManager.get_content() to accept force_reauth parameter and call invalidate_auth() when needed. Removed legacy notify_scrape_exception() method and replaced it with explicit re-auth signaling on update failure.
High-level Error Handlers
custom_components/multiscrape/binary_sensor.py, custom_components/multiscrape/sensor.py
Updated exception handling paths to call coordinator.request_reauth() instead of coordinator.notify_scrape_exception().
Session & Form Auth Layer
custom_components/multiscrape/http_session.py, custom_components/multiscrape/form_auth.py
Renamed notify_scrape_exception() to invalidate_auth() in HttpSession and invalidate() in FormAuthenticator. Updated internal call sites to use new method names.
Test Updates
tests/conftest.py, tests/test_coordinator.py, tests/test_http_session.py
Updated mock setup and test assertions to reflect new re-auth flow. Added integration tests for request_reauth() flag behavior and invalidate_auth() invocation during coordinator updates.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • PR #561: Modifies the same authentication and error-handling surfaces (ContentRequestManager, coordinator, and HTTP session scrape-exception/auth invalidation flows), suggesting parallel or dependent work on the re-auth architecture.

Poem

🐰 Hops with glee at flows refined,
No more backwards chains to find!
Request, then validate, then reset—
Forward-facing is the best!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/553-fix-notification-flow
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

CodeRabbit can approve the review once all CodeRabbit's comments are resolved.

Enable the reviews.request_changes_workflow setting to automatically approve the review once all CodeRabbit's comments are resolved.

@danieldotnl danieldotnl merged commit 37e9d4b into master Mar 13, 2026
5 of 6 checks passed
@danieldotnl danieldotnl deleted the feature/553-fix-notification-flow branch March 13, 2026 15:51
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.

Fix Notification Flow (remove backwards dependency)

1 participant