Repository navigation
feat(car): raise the maximum supported cars from 4 to 8 - #4545
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Raises Predbat’s supported EV/charger count from 4 to 8 by updating the single source-of-truth maximum, extending Home Assistant config entities for the additional cars, and expanding the C++ prediction kernel’s struct/array sizes with a parity revision bump to safely reject stale binaries.
Changes:
- Increased
PREDBAT_MAX_CARSto 8 and updated tests to assert the new clamp behavior. - Extended HA configuration (
CONFIG_ITEMS) to includecar_charging_rate_4..7andcar_charging_manual_soc(_kwh)_4..7. - Updated prediction kernel parity revision and car array sizing on both Python (
ctypes.Structure) and C++ sides.
Reviewed changes
Copilot reviewed 7 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/predbat/tests/test_octopus_misc.py | Updates test commentary around device counting behavior. |
| apps/predbat/tests/test_infra.py | Extends mocked default config with car_charging_rate_4..7. |
| apps/predbat/tests/test_fetch_config_options.py | Updates clamp test for 8 cars and adds a regression test ensuring all 8 car rates resolve via real config_index. |
| apps/predbat/prediction_kernel.py | Bumps parity revision and fixes ctypes car-array fields to size by KERNEL_MAX_CARS. |
| apps/predbat/prediction_kernel.cpp | Bumps parity revision and increases PK_MAX_CARS to 8. |
| apps/predbat/const.py | Raises PREDBAT_MAX_CARS to 8. |
| apps/predbat/config.py | Adds HA config items for car indices 4–7 (rate + manual SOC controls). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Some users have more than 4 EVs/chargers registered (e.g. multiple Octopus Intelligent devices), which the previous 4-car ceiling (CONFIG_ITEMS entities, KERNEL_MAX_CARS) rejected outright by clamping num_cars down. Doubling the limit to 8 needs three things kept in lockstep: the shared PREDBAT_MAX_CARS constant, the C++ kernel's PK_MAX_CARS array size (with PK_PARITY_REVISION/ KERNEL_PARITY_REVISION bumped 5 -> 6, on top of the ABI 4 already on main, so a stale 4-car binary is safely rejected rather than corrupting the ctypes struct layout), and the matching ctypes.Structure array sizes on the Python side (previously hardcoded to 4 independently of KERNEL_MAX_CARS - this mismatch caused a segfault before the fix). - const.py: PREDBAT_MAX_CARS 4 -> 8 - prediction_kernel.cpp / .py: PK_MAX_CARS/KERNEL_MAX_CARS -> 8, parity revision bumped 5 -> 6, ctypes array fields now reference KERNEL_MAX_CARS instead of a hardcoded 4 (car_charging_limit, car_charging_soc, car_soc_next) - config.py: added car_charging_rate_4..7 and car_charging_manual_soc(_kwh)_4..7 CONFIG_ITEMS entries so cars 4-7 have HA entities to configure - Regression tests for the new ceiling: kernel parity, 8-car config resolution via the real config_index, MockConfigProvider car rate defaults, and reset_inverter's car_charging_limit/soc arrays sized from PREDBAT_MAX_CARS instead of a hardcoded 4 (Copilot review catch) Kernel binaries are intentionally not included - CI's kernel-binaries job cross-builds and auto-commits all 6 platform binaries once this merges. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
springfall2008
force-pushed
the
feat/support-8-cars
branch
from
August 16, 2026 15:48
0393c88 to
82b599f
Compare
4 tasks done
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
Follow-up to #4533. Some users have more than 4 EVs/chargers on their account (e.g. multiple Octopus Intelligent devices), which the previous 4-car ceiling rejected by clamping
num_carsdown to 4. This raises the supported maximum to 8.Three things had to move together:
PREDBAT_MAX_CARSinconst.py: 4 → 8 (single source of truth, already used by thefetch_config_options()clamp added in fix(car): clamp num_cars to supported maximum, exclude suspended Octopus devices #4533)PK_MAX_CARSarray size inprediction_kernel.cpp, withPK_PARITY_REVISION/KERNEL_PARITY_REVISIONbumped 5 → 6 so a stale (still-4-car) binary is safely rejected at load time and falls back to the Python engine instead of corrupting the ctypes struct layoutcar_charging_rate_4..7andcar_charging_manual_soc(_kwh)_4..7entries inconfig.py'sCONFIG_ITEMSso cars 4-7 get real HA entities to configure (mirrors the existing 0-3 pattern exactly)Bug caught during development
The Python-side
ctypes.Structurefields (car_charging_limit,car_charging_soc,car_soc_next) hardcoded array size4directly instead of referencingKERNEL_MAX_CARS. Bumping only the constant caused a segfault in the kernel parity test - the C++ side wrote 8-car arrays into a struct Python had only sized for 4. Fixed by making those three fields referenceKERNEL_MAX_CARSlike everything else already did.All 6 cross-compiled kernel binaries (
prediction_kernel_lib_*.so) are rebuilt and committed directly in this PR (viabuild_kernel_cross.shwith zig), so CI's binary-verification step should pass on the first run rather than depending on the auto-fix job's follow-up commit.Test plan
./run_all --test kernel_parity- passes with a genuinely rebuilt kernel loaded (not the Python fallback), 450-configuration random sweep included./run_all --test fetch_config_options --test octopus_misc- new/updated tests pass, including a real (non-mocked)config_indexresolution of all 8 carspython3 verify_kernel_binary.py prediction_kernel_lib_darwin_arm64.so- the cross-built binary (same compiler/flags as the Linux targets, different triple) loads and passes the full parity suite locally./run_all --quick- full suite passes./run_pre_commit- passes🤖 Generated with Claude Code