Skip to content

fix(octopus): keep the last planned dispatches when Octopus returns them as null (#5492) - #5493

Merged
springfall2008 merged 3 commits into
mainfrom
fix/octopus-keep-dispatches-on-fetch-error-5492
Oct 12, 2026
Merged

springfall2008 merged 3 commits into
mainfrom
fix/octopus-keep-dispatches-on-fetch-error-5492

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Fixes #5492

Summary

Octopus sometimes answers the Intelligent dispatch query with an error for the planned dispatches alone (KT-CT-4340, "Unable to fetch planned dispatches"): HTTP 200, flexPlannedDispatches: null, the rest of the data intact. The query is made with errors ignored, so the null was read as an empty list and the car's plan was dropped until the next poll. With a car_charging_now sensor that showed as Hold for car with no car charging on the plan.

async_get_intelligent_devices() already keeps the last known planned dispatches when the whole dispatch query fails (since v9.3.1). This PR sends a null planned list down the same path:

  • The last known planned dispatches for the device are kept.
  • Each is dropped once its end time has passed, and the one in progress is re-trimmed to the time left, so nothing outlives its own end. This is the existing fallback's behaviour, unchanged.
  • Completed dispatches in the same answer are still taken.
  • An empty list still means Octopus has no planned dispatches, and still clears them.

Telling the error from "none planned"

Across four log files from one IOG site (616 dispatch polls), "none planned" was always an empty list (606 polls) and the planned list was null on 10 polls, every one of them carrying the KT-CT-4340 error. So null is the failure and [] is the real answer.

Behaviour change to check

If Octopus ever returns a null planned list without an error to mean "none planned", a dispatch it had withdrawn would now stay until its own end time instead of being dropped at once. That shape did not appear in the logs above.

Testing

  • New Test 15 in test_octopus_intelligent_devices.py: a dispatch answer with the planned list null keeps the cached dispatches (ended one dropped, running one re-trimmed, cache not modified in place) and still takes the completed dispatch; an empty list clears them.
  • ./run_all --test octopus_intelligent_devices fails without the fix (Expected the last known planned dispatches kept ... got []) and passes with it.
  • ./run_pre_commit passes, including the quick suite.

Notes

  • The issue text says a failed fetch was indistinguishable from no dispatches; that was only true of this partial failure. The whole-query failure was already handled.
  • Adds a row to tools/debug-journal.md for the symptom and the log shape.
  • Not addressed: while the plan was dropped, the "charging now outside its plan" model used the 22 kW rate Octopus reports rather than the configured 7.4 kW. With this fix that path is no longer reached on this error.

🤖 Generated with Claude Code

CI and others added 2 commits October 11, 2026 22:20
…hem as null (#5492)

Octopus can answer the dispatch query with an error for the planned dispatches alone
(KT-CT-4340, "Unable to fetch planned dispatches") and flexPlannedDispatches null beside
otherwise good data. The query ignores errors, so the null was read as an empty list and
the car's plan was dropped until the next poll. A null planned list is now treated as a
failed fetch: the last known planned dispatches are kept, each dropped once its end has
passed and the one in progress re-trimmed, as when the whole query fails. An empty list
still means no dispatches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@springfall2008 springfall2008 self-assigned this Oct 11, 2026
@springfall2008
springfall2008 marked this pull request as ready for review October 12, 2026 06:55
Copilot AI balanced review requested due to automatic review settings October 12, 2026 06:55

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.

🟢 Approval recommended

The focused implementation matches the reported API behavior and includes comprehensive regression coverage.

0 open findings

What changed in this PR

Preserves cached Octopus Intelligent planned dispatches when the API returns null for that field.

Changes:

  • Treats null planned dispatches as a partial fetch failure while retaining completed dispatches.
  • Adds regression coverage distinguishing null from an explicit empty list.
File Description
apps/​predbat/​octopus.py Reuses valid cached planned dispatches on partial API failure.
apps/​predbat/​tests/​test_octopus_intelligent_devices.py Tests null fallback, cache immutability, expiry, trimming, and empty-list clearing.

🧠 Review effort: Balanced


💡 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
@springfall2008
springfall2008 merged commit 0bca948 into main Oct 12, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/octopus-keep-dispatches-on-fetch-error-5492 branch October 12, 2026 07:02
springfall2008 added a commit that referenced this pull request Oct 13, 2026
…s); mark GH#5438/#5492 fixed (#5439/#5493), GH#5472 and the GH#4900 compare-plan leak fixed (#5488/#5465), sigenergy docs split fixed (#5464), ML retrain interval configurable (#5433) (#5528)

Co-authored-by: CI <ci@example.com>
Co-authored-by: Claude Code <noreply@anthropic.com>
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.

Octopus Intelligent: a failed planned-dispatch fetch (KT-CT-4340) is read as no dispatches and drops the car plan

2 participants