From 16870546a01b4443b01cba2cbd3c7de7e1e87ae2 Mon Sep 17 00:00:00 2001 From: Ibrahim KARATAS <89934937+ikaratass@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:40:10 +0100 Subject: [PATCH] is_ready_to_charge control added for Authorization (#227) * is_ready_to_charge control added for Authorization * evse_ready check added for -20 --- iso15118/secc/controller/interface.py | 8 ++++++ iso15118/secc/controller/simulator.py | 6 +++++ iso15118/secc/states/iso15118_20_states.py | 7 ++++-- iso15118/secc/states/iso15118_2_states.py | 5 +++- tests/secc/states/test_iso15118_2_states.py | 28 +++++++++++++++++++-- 5 files changed, 49 insertions(+), 5 deletions(-) diff --git a/iso15118/secc/controller/interface.py b/iso15118/secc/controller/interface.py index bdd4172a..2f29481d 100644 --- a/iso15118/secc/controller/interface.py +++ b/iso15118/secc/controller/interface.py @@ -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 diff --git a/iso15118/secc/controller/simulator.py b/iso15118/secc/controller/simulator.py index edab1899..ebbd583c 100644 --- a/iso15118/secc/controller/simulator.py +++ b/iso15118/secc/controller/simulator.py @@ -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 diff --git a/iso15118/secc/states/iso15118_20_states.py b/iso15118/secc/states/iso15118_20_states.py index e825b253..e784a7b5 100644 --- a/iso15118/secc/states/iso15118_20_states.py +++ b/iso15118/secc/states/iso15118_20_states.py @@ -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() == ( diff --git a/iso15118/secc/states/iso15118_2_states.py b/iso15118/secc/states/iso15118_2_states.py index 0dca4554..86732ee1 100644 --- a/iso15118/secc/states/iso15118_2_states.py +++ b/iso15118/secc/states/iso15118_2_states.py @@ -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: diff --git a/tests/secc/states/test_iso15118_2_states.py b/tests/secc/states/test_iso15118_2_states.py index a9ba242a..7ee4376a 100644 --- a/tests/secc/states/test_iso15118_2_states.py +++ b/tests/secc/states/test_iso15118_2_states.py @@ -136,7 +136,7 @@ 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, @@ -144,6 +144,15 @@ async def test_payment_details_next_state_on_payment_details_req_auth( ChargeParameterDiscovery, ResponseCode.OK, EVSEProcessing.FINISHED, + True, + ), + ( + AuthEnum.EIM, + AuthorizationStatus.ACCEPTED, + None, + ResponseCode.OK, + EVSEProcessing.ONGOING, + False, ), ( AuthEnum.EIM, @@ -151,6 +160,7 @@ async def test_payment_details_next_state_on_payment_details_req_auth( None, ResponseCode.OK, EVSEProcessing.ONGOING, + True, ), ( AuthEnum.EIM, @@ -158,6 +168,7 @@ async def test_payment_details_next_state_on_payment_details_req_auth( Terminate, ResponseCode.FAILED, EVSEProcessing.FINISHED, + True, ), ( AuthEnum.PNC_V2, @@ -165,6 +176,15 @@ async def test_payment_details_next_state_on_payment_details_req_auth( ChargeParameterDiscovery, ResponseCode.OK, EVSEProcessing.FINISHED, + True, + ), + ( + AuthEnum.PNC_V2, + AuthorizationStatus.ACCEPTED, + None, + ResponseCode.OK, + EVSEProcessing.ONGOING, + False, ), ( AuthEnum.PNC_V2, @@ -172,6 +192,7 @@ async def test_payment_details_next_state_on_payment_details_req_auth( None, ResponseCode.OK, EVSEProcessing.ONGOING, + True, ), ( AuthEnum.PNC_V2, @@ -179,6 +200,7 @@ async def test_payment_details_next_state_on_payment_details_req_auth( Terminate, ResponseCode.FAILED, EVSEProcessing.FINISHED, + True, ), ], ) @@ -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