Skip to content

fix: read saving session available_events from configured entity, not rewritten one - #4585

Merged
springfall2008 merged 2 commits into
mainfrom
fix/octopus-saving-session-entity-rewrite-4573
Aug 19, 2026
Merged

fix: read saving session available_events from configured entity, not rewritten one#4585
springfall2008 merged 2 commits into
mainfrom
fix/octopus-saving-session-entity-rewrite-4573

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Summary

Fixes #4573.

The octopus_saving_session binary_sensor -> event entity rewrite (a fallback for legacy configs) rebound entity_id unconditionally whenever joined_events was empty on the configured entity. The following available_events read then used the rewritten entity name instead of the one the user configured. If the rewritten entity didn't exist (e.g. custom entity names with no _sessions substring, or the newer flexibility API naming), available_events came back empty and saving-session auto-join silently stopped working - with nothing logged, since the "auto-join is disabled" message also requires available_events to be truthy.

Fix

available_events and joined_events are now both read from the configured entity first. The rewrite to the event.* entity is only attempted - and only adopted - when the configured entity has neither attribute and the rewritten entity actually returns data. This preserves the legacy binary_sensor path (where entity_id genuinely needs to be rebound so a later join-service call targets the correct entity) while fixing the case where the configured entity already has the data needed.

Test plan

  • Added test_saving_session_custom_entity_no_rewrite_match, reproducing the issue's scenario (custom entity name, empty joined_events, populated available_events, no matching rewritten entity). Confirmed it fails on the pre-fix code (0 join calls) and passes with the fix.
  • All existing saving-session tests still pass (saving_session, saving_session_null, saving_session_notify, saving_session_default_rate, saving_session_axle_conflict, saving_session_auto_join_toggle).
  • Full ./run_all --quick suite passes.
  • pre-commit (ruff, black, cspell) passes on changed files.

🤖 Generated with Claude Code

… rewritten one

The binary_sensor -> event entity rewrite used as a fallback for legacy
configs rebound entity_id unconditionally whenever joined_events was
empty, so the following available_events read used the rewritten name
instead of the configured entity. If the rewritten entity didn't exist
(e.g. custom entity names with no '_sessions' substring), available_events
came back empty and saving-session auto-join silently stopped working
with nothing logged.

Fixes #4573
Copilot AI lite review requested due to automatic review settings August 19, 2026 06:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in Octopus Saving Session auto-join by ensuring available_events is read from the user-configured saving-session entity, and only falling back to the legacy binary_sensor.*_sessions -> event.*_session_events rewrite when the configured entity provides no relevant attributes.

Changes:

  • Read both joined_events and available_events from the configured octopus_saving_session entity before attempting any entity-id rewrite.
  • Gate the entity-id rewrite so it’s only adopted when the rewritten entity actually returns usable data.
  • Add a regression test covering custom entity names that do not match the rewrite pattern.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
apps/predbat/octopus.py Fixes saving-session attribute reads so available_events isn’t accidentally read from a rewritten/nonexistent entity.
apps/predbat/tests/test_saving_session.py Adds regression coverage for a custom configured entity name where rewrite would not resolve.
apps/predbat/unit_test.py Registers the new saving-session regression test in the test runner.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread apps/predbat/octopus.py Outdated
Comment thread apps/predbat/tests/test_saving_session.py Outdated
- Distinguish "attribute genuinely missing" from "attribute present but
  an empty list" using a sentinel, so the binary_sensor -> event fallback
  no longer misfires when the configured entity is valid but currently
  has no events (a normal, common state).
- Isolate the new regression test's mutation of my_predbat.args behind a
  save/restore, matching the pattern used by other tests in this suite.

Addresses Copilot review comments on PR #4585.
@springfall2008
springfall2008 merged commit 004f298 into main Aug 19, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/octopus-saving-session-entity-rewrite-4573 branch August 19, 2026 07:43
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.

Saving session auto-join reads available_events from a rewritten entity_id, silently disabling auto-join

2 participants