From 868f704868994e12728772ab4e7400dadb1749b2 Mon Sep 17 00:00:00 2001 From: Shalin Nijel <89510971+shalinnijel2@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:17:16 +0100 Subject: [PATCH] Simulate soc in -2, -20 and din. (#393) * Move contactor close check to be after cable check is complete. * Added display params to AC/DC charge requests in -20 * Fixed formatting errors * Removed contactor status related changes * Fixed contactor status check in DIN * set ev_ress_soc to _soc in simulator * considered missed chargeLoopCycle * Fixed mypy issues * simple guard against 0 charging loop cycles --- iso15118/evcc/controller/interface.py | 14 +++++++++++++- iso15118/evcc/controller/simulator.py | 20 ++++++++++++++++---- iso15118/evcc/states/iso15118_20_states.py | 4 ++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/iso15118/evcc/controller/interface.py b/iso15118/evcc/controller/interface.py index e16c4cae..a9afd268 100644 --- a/iso15118/evcc/controller/interface.py +++ b/iso15118/evcc/controller/interface.py @@ -52,7 +52,10 @@ SelectedEnergyService, SelectedVAS, ) -from iso15118.shared.messages.iso15118_20.common_types import RationalNumber +from iso15118.shared.messages.iso15118_20.common_types import ( + DisplayParameters, + RationalNumber, +) from iso15118.shared.messages.iso15118_20.dc import ( BPTDCChargeParameterDiscoveryReqParams, BPTDynamicDCChargeLoopReqParams, @@ -670,3 +673,12 @@ async def enable_charging(self, enabled: bool) -> None: - ISO 15118-2 - ISO 15118-20 """ + + @abstractmethod + async def get_display_params(self) -> DisplayParameters: + """ + Enables charging for the EVCC. + Can be used as an indication to go to state C + Relevant for: + - ISO 15118-20 + """ diff --git a/iso15118/evcc/controller/simulator.py b/iso15118/evcc/controller/simulator.py index 34cc8872..4c6c1671 100644 --- a/iso15118/evcc/controller/simulator.py +++ b/iso15118/evcc/controller/simulator.py @@ -93,7 +93,10 @@ SelectedEnergyService, SelectedVAS, ) -from iso15118.shared.messages.iso15118_20.common_types import RationalNumber +from iso15118.shared.messages.iso15118_20.common_types import ( + DisplayParameters, + RationalNumber, +) from iso15118.shared.messages.iso15118_20.dc import ( BPTDCChargeParameterDiscoveryReqParams, BPTDynamicDCChargeLoopReqParams, @@ -114,7 +117,8 @@ class SimEVController(EVControllerInterface): def __init__(self, evcc_config: EVCCConfig): self.config = evcc_config - self.charging_loop_cycles: int = evcc_config.charge_loop_cycle + self.charging_loop_cycles: int = max(evcc_config.charge_loop_cycle, 1) + self.increment = (1 / self.charging_loop_cycles) * 100 self.precharge_loop_cycles: int = 0 self.welding_detection_cycles: int = 0 self._charging_is_completed = False @@ -532,6 +536,7 @@ async def continue_charging(self) -> bool: return False else: self.charging_loop_cycles -= 1 + self._soc = min(int(self._soc + self.increment), 100) # The line below can just be called once process_message in all states # are converted to async calls # await asyncio.sleep(0.5) @@ -659,14 +664,14 @@ async def get_dc_ev_status_dinspec(self) -> DCEVStatusDINSPEC: return DCEVStatusDINSPEC( ev_ready=True, ev_error_code=DCEVErrorCode.NO_ERROR, - ev_ress_soc=60, + ev_ress_soc=self._soc, ) async def get_dc_ev_status(self) -> DCEVStatus: return DCEVStatus( ev_ready=True, ev_error_code=DCEVErrorCode.NO_ERROR, - ev_ress_soc=60, + ev_ress_soc=self._soc, ) async def get_scheduled_dc_charge_loop_params( @@ -727,3 +732,10 @@ async def get_target_voltage(self) -> RationalNumber: async def enable_charging(self, enabled: bool) -> None: """Overrides EVControllerInterface.enable_charging().""" pass + + async def get_display_params(self) -> DisplayParameters: + """Overrides EVControllerInterface.get_display_params().""" + return DisplayParameters( + present_soc=self._soc, + charging_complete=await self.is_charging_complete(), + ) diff --git a/iso15118/evcc/states/iso15118_20_states.py b/iso15118/evcc/states/iso15118_20_states.py index 39233bc3..0be31299 100644 --- a/iso15118/evcc/states/iso15118_20_states.py +++ b/iso15118/evcc/states/iso15118_20_states.py @@ -1000,6 +1000,7 @@ async def process_message( session_id=self.comm_session.session_id, timestamp=time.time(), ), + display_parameters=await self.comm_session.ev_controller.get_display_params(), # noqa scheduled_params=scheduled_params, dynamic_params=dynamic_params, bpt_scheduled_params=bpt_scheduled_params, @@ -1040,6 +1041,7 @@ async def process_message( session_id=self.comm_session.session_id, timestamp=time.time(), ), + display_parameters=await ev_controller.get_display_params(), ev_present_voltage=await ev_controller.get_present_voltage(), scheduled_params=scheduled_params, dynamic_params=dynamic_params, @@ -1322,6 +1324,7 @@ async def process_message( session_id=self.comm_session.session_id, timestamp=time.time(), ), + display_parameters=await self.comm_session.ev_controller.get_display_params(), # noqa scheduled_params=scheduled_params, dynamic_params=dynamic_params, bpt_scheduled_params=bpt_scheduled_params, @@ -1695,6 +1698,7 @@ async def build_current_demand_data(self): session_id=self.comm_session.session_id, timestamp=time.time(), ), + display_parameters=await self.comm_session.ev_controller.get_display_params(), # noqa ev_present_voltage=await self.comm_session.ev_controller.get_present_voltage(), # noqa scheduled_params=scheduled_params, dynamic_params=dynamic_params,