Skip to content

Commit

Permalink
start_cable_check is called now as we enter the state.
Browse files Browse the repository at this point in the history
  • Loading branch information
shalinnijel2 committed May 16, 2024
1 parent a623eee commit 7fff7b7
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 54 deletions.
41 changes: 23 additions & 18 deletions iso15118/secc/states/din_spec_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
43 changes: 24 additions & 19 deletions iso15118/secc/states/iso15118_20_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
)
Expand All @@ -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(
Expand Down
39 changes: 22 additions & 17 deletions iso15118/secc/states/iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/dinspec/secc/test_dinspec_secc_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/iso15118_2/secc/states/test_iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/iso15118_20/secc/test_iso15118_20_dc_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7fff7b7

Please sign in to comment.