Skip to content

feat: gate HA entities on the vehicle model configuration - #499

Merged
nanomad merged 4 commits into
developfrom
feat/model-config-feature-gating
Nov 14, 2026
Merged

nanomad merged 4 commits into
developfrom
feat/model-config-feature-gating

Conversation

@nanomad

@nanomad nanomad commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Use the vehicle model configuration (vehicleModelConfiguration) to decide which Home Assistant entities a vehicle actually has.

  • Doors (DOOR, 4-char positional mask: driver, passenger, rear left, rear right): rear door entities are disabled by default on 2-door vehicles such as the MG Cyberster (DOOR=1100).
  • Boot (BOOT), tyre pressures (J17) and interior temperature (INTEMP) are enabled by default only when declared.
  • Entities that are not supported stay published but are disabled by default, so a wrong code never removes an entity and owners can enable it by hand.
  • Sunroof (S35) is now read as an integer: the value 2 alone does not denote a sunroof.

Codes deliberately not used

Real vehicles report these as 0 while still sending the data, so gating on them would hide working entities:

Code Example
WINDOW MG4, MG5 and ZS EV report 0000 but send state for all 4 windows
EXTEMP 0 on MG3, ZS, HS, S9 and MG4 Urban
BATTERY 0 on HS and MG4 Urban, missing on one ZS EV
BONNUT 0 on an MG3 2023 but 1 on an MG3 2025

Comments in vehicle_info.py and next to the window sensors record this so nobody re-adds them.

Tests

  • tests/fixtures/vehicle_model_configurations.json: 18 real model configurations (MG4, MG4 Urban, MG3, MG5, ZS EV, ZS Hybrid+, HS PHEV, AS33, S9 PHEV, Cyberster). They come from public townsmcp/mg-saic-ha issue reports plus one captured MG4, and contain no VINs.
  • tests/test_vehicle_info_features.py: flag and mask parsing, and the expected features for every real configuration.
  • tests/test_ha_discovery_feature_gating.py: discovery publishes or unpublishes the gated entities, and keeps the ungated ones even when their codes are 0.

ruff check, ruff format, mypy and pytest tests (413 passed) pass locally.

nanomad and others added 2 commits November 12, 2026 17:21
Publish door, boot, tyre pressure and interior temperature entities only
when the vehicle model configuration declares them (DOOR, BOOT, J17,
INTEMP), and unpublish them otherwise. This removes the rear door
entities on 2-door vehicles such as the MG Cyberster (DOOR=1100).

Read S35 as an integer when detecting a sunroof: the value 2 alone does
not denote a sunroof.

WINDOW, BONNUT, BATTERY and EXTEMP are deliberately ignored: real
vehicles report 0 for them while still sending the data (e.g. the MG4
reports WINDOW=0000). Add 18 real model configurations as test fixtures.
@nanomad
nanomad force-pushed the feat/model-config-feature-gating branch from ec93bad to 6d7785e Compare November 12, 2026 16:22
… them

A wrong model configuration code no longer removes an entity: it stays published, disabled by default, so owners can enable it and existing installs keep what they have.
@nanomad
nanomad merged commit caa93bb into develop Nov 14, 2026
11 checks passed
@nanomad
nanomad deleted the feat/model-config-feature-gating branch November 14, 2026 13:39
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.

1 participant