Skip to content

Commit

Permalink
is_ready_to_charge control added for Authorization (#227)
Browse files Browse the repository at this point in the history
* is_ready_to_charge control added for Authorization

* evse_ready check added for -20
  • Loading branch information
ikaratass authored Apr 25, 2023
1 parent e1c27e5 commit 1687054
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 5 deletions.
8 changes: 8 additions & 0 deletions iso15118/secc/controller/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,3 +810,11 @@ async def update_data_link(self, action: SessionStopAction) -> None:
- ISO 15118-20 and ISO 15118-2
"""
raise NotImplementedError

@abstractmethod
def ready_to_charge(self) -> bool:
"""
Used by Authorization state to indicate if we are
ready to start charging.
"""
raise NotImplementedError
6 changes: 6 additions & 0 deletions iso15118/secc/controller/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1051,3 +1051,9 @@ async def update_data_link(self, action: SessionStopAction) -> None:
Overrides EVSEControllerInterface.update_data_link().
"""
pass

def ready_to_charge(self) -> bool:
"""
Overrides EVSEControllerInterface.ready_to_charge().
"""
return True
7 changes: 5 additions & 2 deletions iso15118/secc/states/iso15118_20_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,11 @@ async def process_message(
if auth_req.pnc_params.gen_challenge != self.comm_session.gen_challenge:
response_code = ResponseCode.WARN_CHALLENGE_INVALID

if await self.comm_session.evse_controller.is_authorized() == (
AuthorizationStatus.ACCEPTED
auth_status = Processing.ONGOING
if (
await self.comm_session.evse_controller.is_authorized()
== AuthorizationStatus.ACCEPTED
and self.comm_session.evse_controller.ready_to_charge()
):
auth_status = Processing.FINISHED
elif await self.comm_session.evse_controller.is_authorized() == (
Expand Down
5 changes: 4 additions & 1 deletion iso15118/secc/states/iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,10 @@ async def process_message(
),
)

if authorization_result == AuthorizationStatus.ACCEPTED:
if (
authorization_result == AuthorizationStatus.ACCEPTED
and self.comm_session.evse_controller.ready_to_charge()
):
auth_status = EVSEProcessing.FINISHED
next_state = ChargeParameterDiscovery
elif authorization_result == AuthorizationStatus.REJECTED:
Expand Down
28 changes: 26 additions & 2 deletions tests/secc/states/test_iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,49 +136,71 @@ async def test_payment_details_next_state_on_payment_details_req_auth(

@pytest.mark.parametrize(
"auth_type, is_authorized_return_value, expected_next_state,"
"expected_response_code, expected_evse_processing",
"expected_response_code, expected_evse_processing, is_ready_to_charge",
[
(
AuthEnum.EIM,
AuthorizationStatus.ACCEPTED,
ChargeParameterDiscovery,
ResponseCode.OK,
EVSEProcessing.FINISHED,
True,
),
(
AuthEnum.EIM,
AuthorizationStatus.ACCEPTED,
None,
ResponseCode.OK,
EVSEProcessing.ONGOING,
False,
),
(
AuthEnum.EIM,
AuthorizationStatus.ONGOING,
None,
ResponseCode.OK,
EVSEProcessing.ONGOING,
True,
),
(
AuthEnum.EIM,
AuthorizationStatus.REJECTED,
Terminate,
ResponseCode.FAILED,
EVSEProcessing.FINISHED,
True,
),
(
AuthEnum.PNC_V2,
AuthorizationStatus.ACCEPTED,
ChargeParameterDiscovery,
ResponseCode.OK,
EVSEProcessing.FINISHED,
True,
),
(
AuthEnum.PNC_V2,
AuthorizationStatus.ACCEPTED,
None,
ResponseCode.OK,
EVSEProcessing.ONGOING,
False,
),
(
AuthEnum.PNC_V2,
AuthorizationStatus.ONGOING,
None,
ResponseCode.OK,
EVSEProcessing.ONGOING,
True,
),
(
AuthEnum.PNC_V2,
AuthorizationStatus.REJECTED,
Terminate,
ResponseCode.FAILED,
EVSEProcessing.FINISHED,
True,
),
],
)
Expand All @@ -189,8 +211,10 @@ async def test_authorization_next_state_on_authorization_request(
expected_next_state: StateSECC,
expected_response_code: ResponseCode,
expected_evse_processing: EVSEProcessing,
is_ready_to_charge: bool,
):

mock_is_ready_to_charge = Mock(return_value=is_ready_to_charge)
self.comm_session.evse_controller.ready_to_charge = mock_is_ready_to_charge
self.comm_session.selected_auth_option = auth_type
mock_is_authorized = AsyncMock(return_value=is_authorized_return_value)
self.comm_session.evse_controller.is_authorized = mock_is_authorized
Expand Down

0 comments on commit 1687054

Please sign in to comment.