diff --git a/README.md b/README.md index db3e8eb..32ada45 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 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/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 eaa994f..faea442 100644 --- a/src/vehicle_info.py +++ b/src/vehicle_info.py @@ -91,6 +91,22 @@ 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: + # 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: + 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: 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 ef3653e..3e5cb59 100644 --- a/tests/test_vehicle_info.py +++ b/tests/test_vehicle_info.py @@ -63,6 +63,42 @@ def test_custom_capacity_overrides_lookup(self) -> None: assert vi.real_battery_capacity == 54.0 +class TestPowerTailgate: + @staticmethod + 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: + 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 + + 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_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 + + class TestMg4UrbanCapacityHint: @staticmethod def _info(series: str, custom: float | None = None) -> VehicleInfo: