Skip to content

Add Lead Hours Configuration for Octopus Saving Session Auto Join - #5010

Open
TCWORLD wants to merge 8 commits into
springfall2008:mainfrom
TCWORLD:octopus-lead-hours
Open

TCWORLD wants to merge 8 commits into
springfall2008:mainfrom
TCWORLD:octopus-lead-hours

Conversation

@TCWORLD

@TCWORLD TCWORLD commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Adds a new configuration option "octopus_saving_auto_join_lead_hours" which allows the user to specify that Predbat should wait until the configured number of hours before the start of a given saving session event before trying to join it.

The default (0) maintains the existing behaviour of auto-joining as soon as an event becomes available.

Setting a positive integer allows specifying that predbat should delay joining the session until the set number of hours before the start of the event.

Fix for #4985.

@TCWORLD

TCWORLD commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

This will probably need additional tests adding but I've not got the dev environment set up to run said tests at the moment.
Test cases now added.

@springfall2008
springfall2008 marked this pull request as ready for review September 9, 2026 07:23
Copilot AI lite review requested due to automatic review settings September 9, 2026 07:23

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.

🟡 Changes recommended

The new lead-hours auto-join behavior needs unit test coverage (and there is also a small docs grammar fix to apply).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adds a new user-configurable “lead time” for Octopus Saving Session auto-join so Predbat can delay joining until closer to the event start, reducing the chance of later-announced conflicts (e.g., Axle short-notice events).

Changes:

  • Introduces octopus_saving_auto_join_lead_hours configuration (0–12 hours) gated by octopus_saving_auto_join.
  • Updates Octopus saving-session auto-join logic to skip joining until within the configured lead window.
  • Documents the new option and its rationale in the energy rates documentation.
File summaries
File Description
docs/energy-rates.md Documents the new lead-hours behavior for saving-session auto-join.
apps/predbat/octopus.py Adds lead-time gating before attempting to auto-join available saving sessions.
apps/predbat/config.py Adds a new input_number config item for lead hours, enabled when auto-join is on.
Review details
  • Files reviewed: 3/3 changed files
  • Comments generated: 2
  • Review effort level: Lite

💡 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
Comment thread docs/energy-rates.md Outdated
This will be used to configure how soon Predbat is allowed to join a saving session event before the start of the event (default 0 = join immediately).
Add a check to ensure that if the lead hours configuration has been set to non-zero, that we do not try to join a given saving session until we are within the specified number of hours of the session start.
1. Checks that auto-join proceeds when lead_hours is both unset and set to 0 to mimic current default behaviour
2. Checks that auto-join is skipped when we are more than lead_hours before the start of the event
2. Checks that auto-join proceeds when we are less than lead_hours before the start of the event

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.

🟡 Changes recommended

The updated saving-session test mutates my_predbat.now_utc without restoring it, which can leak state across the shared test instance and cause order-dependent failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

apps/predbat/tests/test_saving_session.py:1175

  • The test sets a fixed my_predbat.now_utc earlier but never restores it, which can cause test-order dependence because the suite reuses the same PredBat instance. Restore now_utc alongside the other restored config state.
    # Restore default state so we do not leak it to other tests
    my_predbat.expose_config("octopus_saving_auto_join", True, quiet=True)
    my_predbat.expose_config("octopus_saving_auto_join_lead_hours", 0, quiet=True)
    my_predbat.octopus_last_joined_try = None
  • Files reviewed: 5/5 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread apps/predbat/tests/test_saving_session.py
Comment thread apps/predbat/tests/test_saving_session.py Outdated
Backup at start and restore at end of test.
Copy-paste error not updated to match actual test.
Should always be the case regardless, but worth adding a test to make sure the lead hours doesn't accidentally cause a join when auto join is disabled.
@TCWORLD

TCWORLD commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

This is ready for review. Doesn't give me the option to request another review from the bot.

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.

Copilot review overview

🟢 Approval recommended

All reviewed changes are covered by the final review with no unresolved issues.

Review effort: Lite
Findings: None

Resolved since last review (2)

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.

2 participants