Skip to content

fix(car): clamp num_cars to supported maximum, exclude suspended Octopus devices - #4533

Merged
springfall2008 merged 2 commits into
mainfrom
fix/clamp-num-cars-and-filter-suspended-devices
Aug 15, 2026
Merged

springfall2008 merged 2 commits into
mainfrom
fix/clamp-num-cars-and-filter-suspended-devices

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Summary

  • Predbat only supports 4 cars (car_charging_rate/_1/_2/_3 in CONFIG_ITEMS, KERNEL_MAX_CARS=4 in the prediction kernel), but num_cars had no upper bound - an Octopus account with more than 4 registered Intelligent devices auto-bumped num_cars past that limit with no clamp.
  • Car indices beyond 4 have no car_charging_rate_N config entity, so get_car_charging_planned() crashed every cycle with TypeError: float() argument must be a string or a real number, not 'NoneType' once triggered.
  • automatic_config()'s device auto-discovery also counted suspended (e.g. decommissioned/replaced) chargers as active cars, inflating num_cars further for accounts with old devices still linked.

Changes

  • Added PREDBAT_MAX_CARS = 4 to const.py as the single source of truth (also used by prediction_kernel.py's KERNEL_MAX_CARS, replacing the previously duplicated literal).
  • fetch_config_options() now clamps num_cars to PREDBAT_MAX_CARS regardless of where it came from (apps.yaml, HA override, or auto-discovery), logging a warning and recording status so the clamp is visible rather than silent.
  • OctopusAPI.automatic_config() now excludes devices with suspended: True from both the entity lists (octopus_intelligent_slot/ready_time/charge_limit) and the num_cars auto-bump.
  • Added regression tests: a num_cars clamp test in test_fetch_config_options.py, and a new test_octopus_automatic_config_num_cars in test_octopus_misc.py covering suspended-device filtering and that auto-discovery never lowers an existing higher num_cars.
  • Extended MockConfigProvider's default test config (test_infra.py) with car_charging_rate_2/_3 so tests can exercise up to the full 4-car range.

Test plan

  • ./run_all --test fetch_config_options --test octopus_misc - new and existing tests pass
  • ./run_all --quick - full quick suite passes (59.65s, 3 slow tests skipped as usual)
  • ./run_pre_commit - passes

🤖 Generated with Claude Code

…ed Octopus devices

An Octopus account with more than 4 registered Intelligent devices (including
suspended/decommissioned chargers) auto-bumped num_cars with no upper bound,
past what CONFIG_ITEMS and the prediction kernel (KERNEL_MAX_CARS) actually
support. Car indices beyond 4 have no car_charging_rate_N config entity, so
get_car_charging_planned() crashed every cycle with TypeError: float()
argument must be a string or a real number, not 'NoneType'.

Clamp num_cars to PREDBAT_MAX_CARS in fetch_config_options() regardless of
source, and exclude suspended devices from automatic_config()'s device count
and entity lists so a stale/decommissioned charger no longer counts as a car.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 15, 2026 14:09

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

This PR hardens Predbat’s multi-car handling by enforcing the project’s 4-car ceiling and improving Octopus Intelligent device auto-discovery so decommissioned/suspended devices don’t inflate num_cars and trigger downstream crashes.

Changes:

  • Introduces PREDBAT_MAX_CARS = 4 as a single source of truth and reuses it in the prediction kernel.
  • Clamps num_cars during config fetch and surfaces the clamp via logs/status.
  • Filters Octopus Intelligent device auto-discovery to ignore suspended devices, with regression tests for both clamp and filtering.

Reviewed changes

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

Show a summary per file
File Description
apps/predbat/const.py Adds PREDBAT_MAX_CARS constant to centralize the supported maximum.
apps/predbat/prediction_kernel.py Replaces the duplicated KERNEL_MAX_CARS literal with PREDBAT_MAX_CARS.
apps/predbat/fetch.py Clamps num_cars during fetch_config_options() and records a warning status when clamped.
apps/predbat/octopus.py Excludes suspended Intelligent devices from entity lists and num_cars auto-bump.
apps/predbat/tests/test_fetch_config_options.py Adds regression test ensuring num_cars is clamped to 4.
apps/predbat/tests/test_octopus_misc.py Adds regression test for suspended-device filtering and non-decreasing auto-discovery behaviour.
apps/predbat/tests/test_infra.py Extends mock default config with additional car_charging_rate_2/_3 entries to exercise up to 4 cars in tests.

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

Comment thread apps/predbat/fetch.py
Comment thread apps/predbat/tests/test_infra.py Outdated
Comment thread apps/predbat/tests/test_octopus_misc.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@springfall2008
springfall2008 merged commit 7ae4318 into main Aug 15, 2026
2 checks passed
@springfall2008
springfall2008 deleted the fix/clamp-num-cars-and-filter-suspended-devices branch August 15, 2026 14:54
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