Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_ready_to_charge control added for Authorization #227

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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