From 7fff7b7fe85e2d3935b7771b8629f365a81beda3 Mon Sep 17 00:00:00 2001 From: Shalin Nijel <89510971+shalinnijel2@users.noreply.github.com> Date: Thu, 16 May 2024 20:00:07 +0100 Subject: [PATCH] start_cable_check is called now as we enter the state. --- iso15118/secc/states/din_spec_states.py | 41 ++++++++++-------- iso15118/secc/states/iso15118_20_states.py | 43 +++++++++++-------- iso15118/secc/states/iso15118_2_states.py | 39 +++++++++-------- .../dinspec/secc/test_dinspec_secc_states.py | 1 + .../secc/states/test_iso15118_2_states.py | 1 + .../secc/test_iso15118_20_dc_states.py | 1 + 6 files changed, 72 insertions(+), 54 deletions(-) diff --git a/iso15118/secc/states/din_spec_states.py b/iso15118/secc/states/din_spec_states.py index 6e4aed85..d132c5d7 100644 --- a/iso15118/secc/states/din_spec_states.py +++ b/iso15118/secc/states/din_spec_states.py @@ -438,6 +438,7 @@ class CableCheck(StateSECC): def __init__(self, comm_session: SECCCommunicationSession): super().__init__(comm_session, Timeouts.V2G_SECC_SEQUENCE_TIMEOUT) + self.contactors_closed: bool = False self.cable_check_started: bool = False async def process_message( @@ -470,26 +471,12 @@ async def process_message( evse_processing: EVSEProcessing = EVSEProcessing.ONGOING response_code: ResponseCode = ResponseCode.OK next_state = None - if not self.cable_check_started: - # Requirement in 6.4.3.106 of the IEC 61851-23 - # Any relays in the DC output circuit of the DC station shall - # be closed during the insulation test - contactors_closed_for_cable_check: Optional[ - bool - ] = await self.comm_session.evse_controller.is_contactor_closed() - if contactors_closed_for_cable_check is not None: - if not contactors_closed_for_cable_check: - self.stop_state_machine( - "Contactor didnt close for Cable Check", - message, - ResponseCode.FAILED, - ) - return + if not self.cable_check_started: + await self.comm_session.evse_controller.start_cable_check() + self.cable_check_started = True - await self.comm_session.evse_controller.start_cable_check() - self.cable_check_started = True - else: + if self.contactors_closed: isolation_level = ( await self.comm_session.evse_controller.get_cable_check_status() ) # noqa @@ -516,6 +503,24 @@ async def process_message( ResponseCode.FAILED, ) return + else: + # Requirement in 6.4.3.106 of the IEC 61851-23 + # Any relays in the DC output circuit of the DC station shall + # be closed during the insulation test + contactors_closed_for_cable_check: Optional[ + bool + ] = await self.comm_session.evse_controller.is_contactor_closed() + + if contactors_closed_for_cable_check is not None: + if not contactors_closed_for_cable_check: + self.stop_state_machine( + "Contactor didnt close for Cable Check", + message, + ResponseCode.FAILED, + ) + return + else: + self.contactors_closed = True self.comm_session.evse_controller.ev_data_context.present_soc = ( cable_check_req.dc_ev_status.ev_ress_soc diff --git a/iso15118/secc/states/iso15118_20_states.py b/iso15118/secc/states/iso15118_20_states.py index 27ca607e..c7d438b9 100644 --- a/iso15118/secc/states/iso15118_20_states.py +++ b/iso15118/secc/states/iso15118_20_states.py @@ -1585,6 +1585,7 @@ class DCCableCheck(StateSECC): def __init__(self, comm_session: SECCCommunicationSession): super().__init__(comm_session, Timeouts.V2G_EVCC_COMMUNICATION_SETUP_TIMEOUT) + self.contactors_closed = False self.cable_check_started = False async def process_message( @@ -1612,26 +1613,11 @@ async def process_message( processing = EVSEProcessing.ONGOING if not self.cable_check_started: - # Requirement in 6.4.3.106 of the IEC 61851-23 - # Any relays in the DC output circuit of the DC station shall - # be closed during the insulation test - contactors_closed_for_cable_check: Optional[ - bool - ] = await self.comm_session.evse_controller.is_contactor_closed() - - if contactors_closed_for_cable_check is not None: - if not contactors_closed_for_cable_check: - self.stop_state_machine( - "Contactor didnt close for Cable Check", - message, - ResponseCode.FAILED, - ) - return + # Start cable check as contactors are now closed. + await self.comm_session.evse_controller.start_cable_check() + self.cable_check_started = True - # Start cable check as contactors are now closed. - await self.comm_session.evse_controller.start_cable_check() - self.cable_check_started = True - else: + if self.contactors_closed: isolation_level = ( await self.comm_session.evse_controller.get_cable_check_status() ) @@ -1650,6 +1636,25 @@ async def process_message( ResponseCode.FAILED, ) return + else: + if not self.contactors_closed: + # Requirement in 6.4.3.106 of the IEC 61851-23 + # Any relays in the DC output circuit of the DC station shall + # be closed during the insulation test + contactors_closed_for_cable_check: Optional[ + bool + ] = await self.comm_session.evse_controller.is_contactor_closed() + + if contactors_closed_for_cable_check is not None: + if not contactors_closed_for_cable_check: + self.stop_state_machine( + "Contactor didnt close for Cable Check", + message, + ResponseCode.FAILED, + ) + return + else: + self.contactors_closed = True dc_cable_check_res = DCCableCheckRes( header=MessageHeader( diff --git a/iso15118/secc/states/iso15118_2_states.py b/iso15118/secc/states/iso15118_2_states.py index 8179daa8..7e1f9d83 100644 --- a/iso15118/secc/states/iso15118_2_states.py +++ b/iso15118/secc/states/iso15118_2_states.py @@ -2187,6 +2187,7 @@ class CableCheck(StateSECC): def __init__(self, comm_session: SECCCommunicationSession): super().__init__(comm_session, Timeouts.V2G_SECC_SEQUENCE_TIMEOUT) self.cable_check_started = False + self.contactors_closed = False async def process_message( self, @@ -2218,24 +2219,10 @@ async def process_message( evse_processing = EVSEProcessing.ONGOING if not self.cable_check_started: - # Requirement in 6.4.3.106 of the IEC 61851-23 - # Any relays in the DC output circuit of the DC station shall - # be closed during the insulation test - contactors_closed_for_cable_check = ( - await self.comm_session.evse_controller.is_contactor_closed() - ) + await self.comm_session.evse_controller.start_cable_check() + self.cable_check_started = True - if contactors_closed_for_cable_check is not None: - if not contactors_closed_for_cable_check: - self.stop_state_machine( - "Contactor didnt close for Cable Check", - message, - ResponseCode.FAILED, - ) - return - await self.comm_session.evse_controller.start_cable_check() - self.cable_check_started = True - else: + if self.contactors_closed: isolation_level = ( await self.comm_session.evse_controller.get_cable_check_status() ) # noqa @@ -2263,6 +2250,24 @@ async def process_message( ResponseCode.FAILED, ) return + else: + # Requirement in 6.4.3.106 of the IEC 61851-23 + # Any relays in the DC output circuit of the DC station shall + # be closed during the insulation test + contactors_closed_for_cable_check = ( + await self.comm_session.evse_controller.is_contactor_closed() + ) + + if contactors_closed_for_cable_check is not None: + if not contactors_closed_for_cable_check: + self.stop_state_machine( + "Contactor didnt close for Cable Check", + message, + ResponseCode.FAILED, + ) + return + else: + self.contactors_closed = True self.comm_session.evse_controller.ev_data_context.present_soc = ( cable_check_req.dc_ev_status.ev_ress_soc diff --git a/tests/dinspec/secc/test_dinspec_secc_states.py b/tests/dinspec/secc/test_dinspec_secc_states.py index 3ab51b4a..c93cef89 100644 --- a/tests/dinspec/secc/test_dinspec_secc_states.py +++ b/tests/dinspec/secc/test_dinspec_secc_states.py @@ -196,6 +196,7 @@ async def test_15118_dinspec_dc_cable_check( dc_cable_check = CableCheck(self.comm_session) dc_cable_check.cable_check_started = cable_check_started + dc_cable_check.contactors_closed = is_contactor_closed contactor_status = AsyncMock(return_value=is_contactor_closed) self.comm_session.evse_controller.is_contactor_closed = contactor_status cable_check_status = AsyncMock(return_value=cable_check_status) diff --git a/tests/iso15118_2/secc/states/test_iso15118_2_states.py b/tests/iso15118_2/secc/states/test_iso15118_2_states.py index bbe16fea..785831d6 100644 --- a/tests/iso15118_2/secc/states/test_iso15118_2_states.py +++ b/tests/iso15118_2/secc/states/test_iso15118_2_states.py @@ -1165,6 +1165,7 @@ async def test_15118_2_dc_cable_check( ): dc_cable_check = CableCheck(self.comm_session) dc_cable_check.cable_check_started = cable_check_started + dc_cable_check.contactors_closed = is_contactor_closed contactor_status = AsyncMock(return_value=is_contactor_closed) self.comm_session.evse_controller.is_contactor_closed = contactor_status cable_check_status = AsyncMock(return_value=cable_check_status) diff --git a/tests/iso15118_20/secc/test_iso15118_20_dc_states.py b/tests/iso15118_20/secc/test_iso15118_20_dc_states.py index 32f83dfa..62bc9c37 100644 --- a/tests/iso15118_20/secc/test_iso15118_20_dc_states.py +++ b/tests/iso15118_20/secc/test_iso15118_20_dc_states.py @@ -256,6 +256,7 @@ async def test_15118_20_dc_cable_check( ): dc_cable_check = DCCableCheck(self.comm_session) dc_cable_check.cable_check_started = cable_check_started + dc_cable_check.contactors_closed = is_contactor_closed contactor_status = AsyncMock(return_value=is_contactor_closed) self.comm_session.evse_controller.is_contactor_closed = contactor_status cable_check_status = AsyncMock(return_value=cable_check_status)