Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
shalinnijel2 committed Apr 30, 2024
1 parent 35447c4 commit 0f864d6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
40 changes: 20 additions & 20 deletions iso15118/secc/states/iso15118_20_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -1631,28 +1631,28 @@ async def process_message(
)
return

await self.comm_session.evse_controller.start_cable_check()
self.cable_check_started = True

if self.cable_check_started:
isolation_level = (
await self.comm_session.evse_controller.get_cable_check_status()
)
if self.cable_check_started:
isolation_level = (
await self.comm_session.evse_controller.get_cable_check_status()
)

if isolation_level in [IsolationLevel.VALID, IsolationLevel.WARNING]:
if isolation_level == IsolationLevel.WARNING:
logger.warning(
"Isolation resistance measured by EVSE is in Warning range"
if isolation_level in [IsolationLevel.VALID, IsolationLevel.WARNING]:
if isolation_level == IsolationLevel.WARNING:
logger.warning(
"Isolation resistance measured by EVSE is in Warning range"
)
next_state = DCPreCharge
processing = EVSEProcessing.FINISHED
elif isolation_level in [IsolationLevel.INVALID, IsolationLevel.FAULT]:
self.stop_state_machine(
f"Isolation Failure: {isolation_level}",
message,
ResponseCode.FAILED,
)
next_state = DCPreCharge
processing = EVSEProcessing.FINISHED
elif isolation_level in [IsolationLevel.INVALID, IsolationLevel.FAULT]:
self.stop_state_machine(
f"Isolation Failure: {isolation_level}",
message,
ResponseCode.FAILED,
)
return
return
else:
await self.comm_session.evse_controller.start_cable_check()
self.cable_check_started = True

dc_cable_check_res = DCCableCheckRes(
header=MessageHeader(
Expand Down
15 changes: 11 additions & 4 deletions tests/iso15118_20/secc/test_iso15118_20_dc_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,32 +209,37 @@ async def test_15118_20_schedule_exchange_res(
@pytest.mark.parametrize(
"cable_check_req_received, "
"is_contactor_closed, "
"cable_check_started, "
"cable_check_status, "
"expected_state",
[
(False, None, None, None), # First request.
(True, None, None, None), # Not first request. Contactor status unknown.
(True, True, None, None), # Not first request. Contactor closed.
(True, False, None, Terminate), # Contactor close failed.
(False, None, False, None, None), # First request.
(True, None, False, None, None), # Not first request. Contactor status unknown.
(True, True, False, None, None), # Not first request. Contactor closed.
(True, False, False, None, Terminate), # Contactor close failed.
(
True,
True,
True,
IsolationLevel.VALID,
DCPreCharge,
), # noqa Contactor closed. Isolation response received - Valid. Next stage Precharge.
(
True,
True,
True,
IsolationLevel.INVALID,
Terminate,
), # noqa Contactor closed. Isolation response received - Invalid. Terminate.
(
True,
True,
True,
IsolationLevel.WARNING,
DCPreCharge,
), # noqa Contactor closed. Isolation response received - Warning. Next stage Precharge.
(
True,
True,
True,
IsolationLevel.FAULT,
Expand All @@ -246,12 +251,14 @@ async def test_15118_20_dc_cable_check(
self,
cable_check_req_received: bool,
is_contactor_closed: bool,
cable_check_started: bool,
cable_check_status: IsolationLevel,
expected_state: Type[State],
):
dc_cable_check = DCCableCheck(self.comm_session)
dc_cable_check.cable_check_req_was_received = cable_check_req_received
dc_cable_check.contactors_closed_for_cable_check = is_contactor_closed
dc_cable_check.cable_check_started = cable_check_started
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 0f864d6

Please sign in to comment.