From 806272b429dd5125621407b4d8f08bd3afff4ae4 Mon Sep 17 00:00:00 2001 From: Giovanni Condello Date: Sat, 14 Nov 2026 11:23:15 +0100 Subject: [PATCH 1/3] feat: enable the power tailgate cover by default on the MG S6 EV Nothing in the model configuration tells which cars have a power tailgate, so detect it by series (MIS3E). Other cars keep the cover published but disabled by default. --- README.md | 2 +- src/integrations/home_assistant/discovery.py | 7 ++++--- src/vehicle_info.py | 6 ++++++ .../test_discovery_power_tailgate.py | 11 +++++++++-- tests/test_vehicle_info.py | 17 +++++++++++++++++ 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 7f828a4..49a7e9f 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ with the default vehicle prefix: `saic//vehicles/` | /drivetrain/batteryHeating/set | true/false | Start (true) or stop (false) battery heating. The car may refuse the command if it is deemed unnecessary | | /drivetrain/batteryHeatingSchedule/set | JSON Payload. Fields are startTime and mode | Set the battery heating schedule. Mode can be either on or off | | /doors/boot/set | true/false | Lock or unlock boot | -| /doors/boot/powerTailgate/set | open/close | Open or close the power tailgate. Sent to every car; the Home Assistant cover is disabled by default. Tested on an MG S6 EV only; cars without a power tailgate are expected to refuse it. The state is reported on `/doors/boot`. | +| /doors/boot/powerTailgate/set | open/close | Open or close the power tailgate. Sent to every car; the Home Assistant cover is enabled by default on the MG S6 EV and disabled on other models. Tested on an MG S6 EV only; cars without a power tailgate are expected to refuse it. The state is reported on `/doors/boot`. | | /doors/locked/set | true/false | Lock or unlock your car. This is not always working. It might take some time until it takes effect. Don't trust this feature. Use your car key! | | /climate/remoteTemperature/set | temperature | Set A/C temperature | | /climate/remoteClimateState/set | on/off/front/blowingonly | Turn A/C on or off, activate A/C blowing (front) or blowing only (blowingonly) | diff --git a/src/integrations/home_assistant/discovery.py b/src/integrations/home_assistant/discovery.py index e37ecc7..5d70317 100644 --- a/src/integrations/home_assistant/discovery.py +++ b/src/integrations/home_assistant/discovery.py @@ -686,13 +686,14 @@ def __publish_doors_sensors(self) -> None: def __publish_power_tailgate(self) -> None: # Nothing in the vehicle data tells which cars have a power tailgate, - # so the cover is offered to every car but disabled by default. Cars - # without one are expected to refuse the command. + # so it is enabled only for known series (e.g. MG S6 EV). Every other + # car gets the cover disabled by default, and is expected to refuse + # the command if it has no power tailgate. self._publish_cover( mqtt_topics.DOORS_BOOT, mqtt_topics.DOORS_BOOT_POWER_TAILGATE, "Power Tailgate", - enabled=False, + enabled=self.__vin_info.has_power_tailgate, # No static icon: HA then shows an open or closed door icon device_class="door", ) diff --git a/src/vehicle_info.py b/src/vehicle_info.py index e98ffbb..aa14829 100644 --- a/src/vehicle_info.py +++ b/src/vehicle_info.py @@ -90,6 +90,12 @@ def has_fossil_fuel(self) -> bool: def has_sunroof(self) -> bool: return self.__get_property_by_code("S35") != "0" + @property + def has_power_tailgate(self) -> bool: + # Nothing in the model configuration tells which cars have a power + # tailgate, so it is known by series. MIS3E is the MG S6 EV. + return self.series.startswith("MIS3E") + @property def has_on_off_heated_seats(self) -> bool: return self.__get_property_by_code("HeatedSeat") == "2" diff --git a/tests/integrations/home_assistant/test_discovery_power_tailgate.py b/tests/integrations/home_assistant/test_discovery_power_tailgate.py index 10993ce..9f18108 100644 --- a/tests/integrations/home_assistant/test_discovery_power_tailgate.py +++ b/tests/integrations/home_assistant/test_discovery_power_tailgate.py @@ -15,14 +15,14 @@ COVER_TOPIC = f"homeassistant/cover/{VIN}_mg/{VIN}_power_tailgate/config" -def _publish_discovery() -> MessageCapturingConsolePublisher: +def _publish_discovery(series: str = "EH32 S") -> MessageCapturingConsolePublisher: config = Configuration() config.anonymized_publishing = False config.ha_discovery_prefix = "homeassistant" publisher = MessageCapturingConsolePublisher(config) vin_info = VinInfo() vin_info.vin = VIN - vin_info.series = "EH32 S" + vin_info.series = series vin_info.modelName = "MG4 Electric" vin_info.modelYear = "2022" vehicle_info = VehicleInfo(vin_info, None) @@ -57,6 +57,13 @@ def test_power_tailgate_cover_published_for_every_car() -> None: assert payload["enabled_by_default"] is False +def test_power_tailgate_enabled_by_default_on_mg_s6() -> None: + publisher = _publish_discovery("MIS3E S") + + payload = json.loads(publisher.map[COVER_TOPIC]) + assert payload["enabled_by_default"] is True + + def test_boot_lock_unchanged() -> None: publisher = _publish_discovery() diff --git a/tests/test_vehicle_info.py b/tests/test_vehicle_info.py index d1d4121..3f533d4 100644 --- a/tests/test_vehicle_info.py +++ b/tests/test_vehicle_info.py @@ -55,3 +55,20 @@ def test_custom_capacity_overrides_lookup(self) -> None: "AH4EM L", model="MG4 EV URBAN", custom_battery_capacity=54.0 ) assert vi.real_battery_capacity == 54.0 + + +class TestPowerTailgate: + @staticmethod + def _info(series: str) -> VehicleInfo: + vin_info = VinInfo() + vin_info.vin = VIN + vin_info.series = series + vin_info.modelName = "x" + vin_info.modelYear = "2025" + return VehicleInfo(vin_info, None) + + def test_mg_s6_has_power_tailgate(self) -> None: + assert self._info("MIS3E S").has_power_tailgate + + def test_other_series_has_no_power_tailgate(self) -> None: + assert not self._info("EH32 S").has_power_tailgate From 8933be075eed91356aea0fb5d353fe0c3719ca25 Mon Sep 17 00:00:00 2001 From: Giovanni Condello Date: Sat, 14 Nov 2026 11:25:45 +0100 Subject: [PATCH 2/3] feat: detect the power tailgate from the CTRLBOOT code --- README.md | 2 +- src/vehicle_info.py | 7 +++++-- tests/test_vehicle_info.py | 13 ++++++++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 49a7e9f..fc9d2db 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ with the default vehicle prefix: `saic//vehicles/` | /drivetrain/batteryHeating/set | true/false | Start (true) or stop (false) battery heating. The car may refuse the command if it is deemed unnecessary | | /drivetrain/batteryHeatingSchedule/set | JSON Payload. Fields are startTime and mode | Set the battery heating schedule. Mode can be either on or off | | /doors/boot/set | true/false | Lock or unlock boot | -| /doors/boot/powerTailgate/set | open/close | Open or close the power tailgate. Sent to every car; the Home Assistant cover is enabled by default on the MG S6 EV and disabled on other models. Tested on an MG S6 EV only; cars without a power tailgate are expected to refuse it. The state is reported on `/doors/boot`. | +| /doors/boot/powerTailgate/set | open/close | Open or close the power tailgate. Sent to every car; the Home Assistant cover is enabled by default on cars reporting a `CTRLBOOT` code other than 0 and on the MG S6 EV, disabled on other models. Tested on an MG S6 EV only; cars without a power tailgate are expected to refuse it. The state is reported on `/doors/boot`. | | /doors/locked/set | true/false | Lock or unlock your car. This is not always working. It might take some time until it takes effect. Don't trust this feature. Use your car key! | | /climate/remoteTemperature/set | temperature | Set A/C temperature | | /climate/remoteClimateState/set | on/off/front/blowingonly | Turn A/C on or off, activate A/C blowing (front) or blowing only (blowingonly) | diff --git a/src/vehicle_info.py b/src/vehicle_info.py index aa14829..a635d03 100644 --- a/src/vehicle_info.py +++ b/src/vehicle_info.py @@ -92,8 +92,11 @@ def has_sunroof(self) -> bool: @property def has_power_tailgate(self) -> bool: - # Nothing in the model configuration tells which cars have a power - # tailgate, so it is known by series. MIS3E is the MG S6 EV. + # CTRLBOOT is a tri-state: absent or 0 means no power tailgate. + ctrl_boot = self.__get_property_by_code("CTRLBOOT") + if ctrl_boot is not None and ctrl_boot.strip() not in ("", "0"): + return True + # The MG S6 EV (MIS3E) has one but reports no CTRLBOOT code return self.series.startswith("MIS3E") @property diff --git a/tests/test_vehicle_info.py b/tests/test_vehicle_info.py index 3f533d4..aa29110 100644 --- a/tests/test_vehicle_info.py +++ b/tests/test_vehicle_info.py @@ -59,12 +59,16 @@ def test_custom_capacity_overrides_lookup(self) -> None: class TestPowerTailgate: @staticmethod - def _info(series: str) -> VehicleInfo: + def _info(series: str, ctrl_boot: str | None = None) -> VehicleInfo: vin_info = VinInfo() vin_info.vin = VIN vin_info.series = series vin_info.modelName = "x" vin_info.modelYear = "2025" + if ctrl_boot is not None: + vin_info.vehicleModelConfiguration = [ + VehicleModelConfiguration("CTRLBOOT", "CTRLBOOT", ctrl_boot) + ] return VehicleInfo(vin_info, None) def test_mg_s6_has_power_tailgate(self) -> None: @@ -72,3 +76,10 @@ def test_mg_s6_has_power_tailgate(self) -> None: def test_other_series_has_no_power_tailgate(self) -> None: assert not self._info("EH32 S").has_power_tailgate + + def test_ctrlboot_absent_or_zero_means_no_power_tailgate(self) -> None: + assert not self._info("EH32 S", "0").has_power_tailgate + + def test_ctrlboot_non_zero_means_power_tailgate(self) -> None: + assert self._info("EH32 S", "1").has_power_tailgate + assert self._info("EH32 S", "2").has_power_tailgate From d20eba45191770f0401f2742e0f4b12f1698bd1e Mon Sep 17 00:00:00 2001 From: Giovanni Condello Date: Sat, 14 Nov 2026 13:16:04 +0100 Subject: [PATCH 3/3] fix: follow the app's CTRLBOOT semantics for the power tailgate CTRLBOOT=2 adds it, 0 removes it, and when absent the series decides. The MG S6 EV long variant (MIS3E L) has no power tailgate. --- README.md | 2 +- src/vehicle_info.py | 17 ++++++++++++----- tests/test_vehicle_info.py | 14 +++++++++++--- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index fc9d2db..793d4dc 100644 --- a/README.md +++ b/README.md @@ -221,7 +221,7 @@ with the default vehicle prefix: `saic//vehicles/` | /drivetrain/batteryHeating/set | true/false | Start (true) or stop (false) battery heating. The car may refuse the command if it is deemed unnecessary | | /drivetrain/batteryHeatingSchedule/set | JSON Payload. Fields are startTime and mode | Set the battery heating schedule. Mode can be either on or off | | /doors/boot/set | true/false | Lock or unlock boot | -| /doors/boot/powerTailgate/set | open/close | Open or close the power tailgate. Sent to every car; the Home Assistant cover is enabled by default on cars reporting a `CTRLBOOT` code other than 0 and on the MG S6 EV, disabled on other models. Tested on an MG S6 EV only; cars without a power tailgate are expected to refuse it. The state is reported on `/doors/boot`. | +| /doors/boot/powerTailgate/set | open/close | Open or close the power tailgate. Sent to every car; the Home Assistant cover is enabled by default on cars reporting `CTRLBOOT=2` and on the MG S6 EV (`MIS3E`), disabled on other models. Tested on an MG S6 EV only; cars without a power tailgate are expected to refuse it. The state is reported on `/doors/boot`. | | /doors/locked/set | true/false | Lock or unlock your car. This is not always working. It might take some time until it takes effect. Don't trust this feature. Use your car key! | | /climate/remoteTemperature/set | temperature | Set A/C temperature | | /climate/remoteClimateState/set | on/off/front/blowingonly | Turn A/C on or off, activate A/C blowing (front) or blowing only (blowingonly) | diff --git a/src/vehicle_info.py b/src/vehicle_info.py index a635d03..bbc0408 100644 --- a/src/vehicle_info.py +++ b/src/vehicle_info.py @@ -92,12 +92,19 @@ def has_sunroof(self) -> bool: @property def has_power_tailgate(self) -> bool: - # CTRLBOOT is a tri-state: absent or 0 means no power tailgate. + # Mirrors the iSmart app: CTRLBOOT=2 adds the power tailgate, CTRLBOOT=0 + # removes it, and when the code is absent the car's series decides. ctrl_boot = self.__get_property_by_code("CTRLBOOT") - if ctrl_boot is not None and ctrl_boot.strip() not in ("", "0"): - return True - # The MG S6 EV (MIS3E) has one but reports no CTRLBOOT code - return self.series.startswith("MIS3E") + if ctrl_boot is not None: + value = ctrl_boot.strip() + if value == "2": + return True + if value == "0": + return False + # Only the MG S6 EV (MIS3E) has one by default, not its long variant. + # The app strips " S" and treats any remaining "L" as the long variant. + normalized = self.series.replace(" S", "") + return "MIS3E" in normalized and "L" not in normalized @property def has_on_off_heated_seats(self) -> bool: diff --git a/tests/test_vehicle_info.py b/tests/test_vehicle_info.py index aa29110..7a47b5f 100644 --- a/tests/test_vehicle_info.py +++ b/tests/test_vehicle_info.py @@ -77,9 +77,17 @@ def test_mg_s6_has_power_tailgate(self) -> None: def test_other_series_has_no_power_tailgate(self) -> None: assert not self._info("EH32 S").has_power_tailgate - def test_ctrlboot_absent_or_zero_means_no_power_tailgate(self) -> None: + def test_mg_s6_long_variant_has_no_power_tailgate(self) -> None: + assert not self._info("MIS3E L").has_power_tailgate + + def test_ctrlboot_zero_removes_power_tailgate(self) -> None: assert not self._info("EH32 S", "0").has_power_tailgate + assert not self._info("MIS3E S", "0").has_power_tailgate - def test_ctrlboot_non_zero_means_power_tailgate(self) -> None: - assert self._info("EH32 S", "1").has_power_tailgate + def test_ctrlboot_two_adds_power_tailgate(self) -> None: assert self._info("EH32 S", "2").has_power_tailgate + assert self._info("MIS3E L", "2").has_power_tailgate + + def test_ctrlboot_one_falls_back_to_series(self) -> None: + assert not self._info("EH32 S", "1").has_power_tailgate + assert self._info("MIS3E S", "1").has_power_tailgate