Repository navigation
fix(car): clamp num_cars to supported maximum, exclude suspended Octopus devices - #4533
Merged
springfall2008 merged 2 commits intoAug 15, 2026
Merged
Conversation
…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>
Contributor
There was a problem hiding this comment.
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 = 4as a single source of truth and reuses it in the prediction kernel. - Clamps
num_carsduring config fetch and surfaces the clamp via logs/status. - Filters Octopus Intelligent device auto-discovery to ignore
suspendeddevices, 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
springfall2008
deleted the
fix/clamp-num-cars-and-filter-suspended-devices
branch
August 15, 2026 14:54
This was referenced Aug 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
num_carshad no upper bound - an Octopus account with more than 4 registered Intelligent devices auto-bumpednum_carspast that limit with no clamp.car_charging_rate_Nconfig entity, soget_car_charging_planned()crashed every cycle withTypeError: 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, inflatingnum_carsfurther for accounts with old devices still linked.Changes
PREDBAT_MAX_CARS = 4toconst.pyas the single source of truth (also used byprediction_kernel.py'sKERNEL_MAX_CARS, replacing the previously duplicated literal).fetch_config_options()now clampsnum_carstoPREDBAT_MAX_CARSregardless 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 withsuspended: Truefrom both the entity lists (octopus_intelligent_slot/ready_time/charge_limit) and thenum_carsauto-bump.num_carsclamp test intest_fetch_config_options.py, and a newtest_octopus_automatic_config_num_carsintest_octopus_misc.pycovering suspended-device filtering and that auto-discovery never lowers an existing highernum_cars.MockConfigProvider's default test config (test_infra.py) withcar_charging_rate_2/_3so 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