11from __future__ import annotations
22
33from saic_ismart_client_ng .api .vehicle import SaicVehicleApi
4- from saic_ismart_client_ng .api .vehicle .locks .schema import VehicleLockId
4+ from saic_ismart_client_ng .api .vehicle .locks .schema import (
5+ TailgateAction ,
6+ VehicleLockId ,
7+ )
58from saic_ismart_client_ng .api .vehicle .schema import (
69 RvcParams ,
710 RvcParamsId ,
1215from saic_ismart_client_ng .crypto_utils import sha256_hex_digest
1316from saic_ismart_client_ng .exceptions import SaicApiException
1417
15- __all__ = ["VehicleLockId" ]
18+ __all__ = ["TailgateAction" , " VehicleLockId" ]
1619
1720
1821class SaicVehicleLocksApi (SaicVehicleApi ):
@@ -25,10 +28,38 @@ async def unlock_vehicle(self, vin: str) -> VehicleControlResp:
2528 )
2629
2730 async def open_tailgate (self , vin : str ) -> VehicleControlResp :
31+ """Unlock the tailgate (lock 2), which releases its latch.
32+
33+ The iSmart app calls this "Unlock Tailgate". On a car with a power
34+ tailgate, ``control_tailgate`` opens and closes it instead.
35+ """
2836 return await self .control_vehicle_locks (
2937 vin , should_lock = False , lock_id = VehicleLockId .TAILGATE
3038 )
3139
40+ async def control_tailgate (
41+ self , vin : str , * , action : TailgateAction
42+ ) -> VehicleControlResp :
43+ """Open or close a power tailgate.
44+
45+ Matches what the iSmart app sends (decrypted MG S6 EV traffic, UK):
46+ request type 9 with a single parameter, 31 = 1 (open) or 2 (close),
47+ and no end-of-parameters marker. On that car both were accepted, the
48+ tailgate moved, and ``BasicVehicleStatus.bootStatus`` then read 1
49+ (open) and 0 (closed). Only the S6 EV has been checked; cars without a
50+ power tailgate are expected to refuse it.
51+ """
52+ command = VehicleControlReq (
53+ rvc_req_type = RvcReqType .TAILGATE ,
54+ rvc_params = [
55+ RvcParams (
56+ RvcParamsId .TAILGATE , action .value .to_bytes (1 , byteorder = "big" )
57+ )
58+ ],
59+ vin = sha256_hex_digest (vin ),
60+ )
61+ return await self .send_vehicle_control_command (command , vin )
62+
3263 async def control_vehicle_locks (
3364 self ,
3465 vin : str ,
0 commit comments