Skip to content

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

Open
nanomad wants to merge 1 commit into
developfrom
feat/model-config-feature-gating
Open

nanomad wants to merge 1 commit 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 no longer published on 2-door vehicles such as the MG Cyberster (DOOR=1100).
  • Boot (BOOT), tyre pressures (J17) and interior temperature (INTEMP) are published only when declared.
  • Entities that are not supported are unpublished, the same way the sunroof already was.
  • 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.

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.
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