Skip to content

feat(car): raise the maximum supported cars from 4 to 8 - #4545

Merged
springfall2008 merged 2 commits into
mainfrom
feat/support-8-cars
Aug 16, 2026
Merged

springfall2008 merged 2 commits into
mainfrom
feat/support-8-cars

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

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_cars down to 4. This raises the supported maximum to 8.

Three things had to move together:

  • PREDBAT_MAX_CARS in const.py: 4 → 8 (single source of truth, already used by the fetch_config_options() clamp added in fix(car): clamp num_cars to supported maximum, exclude suspended Octopus devices #4533)
  • The C++ kernel's PK_MAX_CARS array size in prediction_kernel.cpp, with PK_PARITY_REVISION/KERNEL_PARITY_REVISION bumped 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 layout
  • New car_charging_rate_4..7 and car_charging_manual_soc(_kwh)_4..7 entries in config.py's CONFIG_ITEMS so cars 4-7 get real HA entities to configure (mirrors the existing 0-3 pattern exactly)

Bug caught during development

The Python-side ctypes.Structure fields (car_charging_limit, car_charging_soc, car_soc_next) hardcoded array size 4 directly instead of referencing KERNEL_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 reference KERNEL_MAX_CARS like everything else already did.

All 6 cross-compiled kernel binaries (prediction_kernel_lib_*.so) are rebuilt and committed directly in this PR (via build_kernel_cross.sh with 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_index resolution of all 8 cars
  • python3 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

Copilot AI lite review requested due to automatic review settings August 16, 2026 08:42

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

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_CARS to 8 and updated tests to assert the new clamp behavior.
  • Extended HA configuration (CONFIG_ITEMS) to include car_charging_rate_4..7 and car_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.

Comment thread apps/predbat/const.py
Comment thread apps/predbat/tests/test_infra.py
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
springfall2008 merged commit 2eb3466 into main Aug 16, 2026
2 checks passed
@springfall2008
springfall2008 deleted the feat/support-8-cars branch August 16, 2026 15: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