Skip to content

Commit

Permalink
0.5.3: Initial V2X support
Browse files Browse the repository at this point in the history
  • Loading branch information
nanomad committed Dec 8, 2024
1 parent 4ad0c9b commit 6ff597c
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,7 @@ fabric.properties

tests/test_saic_api_no_mock.py
run_decoder.sh
junit/
junit/

# CodeBuddy
.codebuddy/
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[tool.poetry]
name = "saic_ismart_client_ng"
homepage = "https://github.com/SAIC-iSmart-API/saic-python-client-ng"
version = "0.5.2"
version = "0.5.3"
description = "SAIC next gen client library (MG iSMART)"
authors = [
"Giovanni Condello <[email protected]>",
Expand Down
30 changes: 30 additions & 0 deletions src/saic_ismart_client_ng/api/vehicle_charging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ async def control_charging(self, vin: str, *, stop_charging: bool) -> ChargingCo
)
return await self.send_vehicle_charging_control(vin, body)

async def control_v2x(self, vin: str, *, stop_v2x: bool) -> ChargingControlResp:
body = ChargingControlRequest(
chrgCtrlReq=0,
tboxV2XReq=2 if stop_v2x else 1,
tboxEleccLckCtrlReq=0,
)
return await self.send_vehicle_charging_control(vin, body)

async def send_vehicle_charging_reservation(
self,
vin: str,
Expand Down Expand Up @@ -170,6 +178,15 @@ async def send_vehicle_charging_settings(self, vin: str, body: ChargingSettingRe
out_type=ChargingSettingResp
)

async def get_vehicle_charging_settings(self, vin: str) -> ChargingSettingResp:
body = ChargingSettingRequest(
altngChrgCrntReq=0,
onBdChrgTrgtSOCReq=0,
tboxV2XSpSOCReq=0,
vin=sha256_hex_digest(vin)
)
return await self.send_vehicle_charging_settings(vin, body)

async def set_target_battery_soc(
self,
vin: str,
Expand All @@ -183,3 +200,16 @@ async def set_target_battery_soc(
vin=sha256_hex_digest(vin)
)
return await self.send_vehicle_charging_settings(vin, body)

async def set_v2x_target_battery_soc(
self,
vin: str,
target_soc: TargetBatteryCode
) -> ChargingSettingResp:
body = ChargingSettingRequest(
onBdChrgTrgtSOCReq=0,
altngChrgCrntReq=0,
tboxV2XSpSOCReq=target_soc.value,
vin=sha256_hex_digest(vin)
)
return await self.send_vehicle_charging_settings(vin, body)
50 changes: 50 additions & 0 deletions src/saic_ismart_client_ng/api/vehicle_charging/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def to_code(code: int):


class TargetBatteryCode(Enum):
P_IGNORE = 0
P_40 = 1
P_50 = 2
P_60 = 3
Expand Down Expand Up @@ -257,6 +258,14 @@ def charge_target_soc(self) -> Optional[TargetBatteryCode]:
except ValueError:
return None

@property
def charge_current_limit(self) -> Optional[ChargeCurrentLimitCode]:
raw_charge_current_limit = self.bmsAltngChrgCrntDspCmd
try:
return ChargeCurrentLimitCode(raw_charge_current_limit)
except ValueError:
return None

@property
def is_battery_heating(self) -> bool:
return self.bmsPTCHeatReqDspCmd == 1
Expand Down Expand Up @@ -349,6 +358,30 @@ class ChargingSettingResp:
def rvc_req_sts_decoded(self) -> Optional[bytes]:
return decode_bytes(input_value=self.rvcReqSts, field_name='rvcReqSts')

@property
def charge_target_soc(self) -> Optional[TargetBatteryCode]:
raw_target_soc = self.bmsOnBdChrgTrgtSOCDspCmd
try:
return TargetBatteryCode(raw_target_soc)
except ValueError:
return None

@property
def charge_current_limit(self) -> Optional[ChargeCurrentLimitCode]:
raw_charge_current_limit = self.bmsAltngChrgCrntDspCmd
try:
return ChargeCurrentLimitCode(raw_charge_current_limit)
except ValueError:
return None

@property
def v2x_target_soc(self) -> Optional[TargetBatteryCode]:
raw_target_soc = self.imcuDschrgTrgtSOCDspCmd
try:
return TargetBatteryCode(raw_target_soc)
except ValueError:
return None


@dataclass
class ScheduledChargingRequest:
Expand Down Expand Up @@ -399,6 +432,7 @@ def heating_stop_reason(self) -> HeatingStopReason | None:
return HeatingStopReason.to_code(self.ptcHeatResp)
return None


@dataclass
class ChargingControlRequest:
chrgCtrlReq: int = None
Expand Down Expand Up @@ -477,6 +511,22 @@ def charge_target_soc(self) -> Optional[TargetBatteryCode]:
except ValueError:
return None

@property
def charge_current_limit(self) -> Optional[ChargeCurrentLimitCode]:
raw_charge_current_limit = self.bmsAltngChrgCrntDspCmd
try:
return ChargeCurrentLimitCode(raw_charge_current_limit)
except ValueError:
return None

@property
def v2x_target_soc(self) -> Optional[TargetBatteryCode]:
raw_target_soc = self.imcuDschrgTrgtSOCDspCmd
try:
return TargetBatteryCode(raw_target_soc)
except ValueError:
return None

@property
def is_battery_heating(self) -> bool:
return self.bmsPTCHeatReqDspCmd == 1
Expand Down

0 comments on commit 6ff597c

Please sign in to comment.