Skip to content

Commit

Permalink
get from the evse controller the ac evse status (#146)
Browse files Browse the repository at this point in the history
* get from the evse controller the ac evse status

* removed unused iimport

* added test for charging status
  • Loading branch information
tropxy authored Oct 12, 2022
1 parent 29650e1 commit 15c3a5a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
17 changes: 4 additions & 13 deletions iso15118/secc/states/iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@
SupportedAppProtocolReq,
SupportedAppProtocolRes,
)
from iso15118.shared.messages.datatypes import (
DCEVSEChargeParameter,
DCEVSEStatus,
EVSENotification,
)
from iso15118.shared.messages.datatypes import DCEVSEChargeParameter, DCEVSEStatus
from iso15118.shared.messages.din_spec.msgdef import V2GMessage as V2GMessageDINSPEC
from iso15118.shared.messages.enums import (
AuthEnum,
Expand Down Expand Up @@ -1825,17 +1821,12 @@ async def process_message(

# We don't care about signed meter values from the EVCC, but if you
# do, then set receipt_required to True and set the field meter_info
evse_controller = self.comm_session.evse_controller
charging_status_res = ChargingStatusRes(
response_code=ResponseCode.OK,
evse_id=await self.comm_session.evse_controller.get_evse_id(
Protocol.ISO_15118_2
),
evse_id=await evse_controller.get_evse_id(Protocol.ISO_15118_2),
sa_schedule_tuple_id=self.comm_session.selected_schedule,
ac_evse_status=ACEVSEStatus(
notification_max_delay=0,
evse_notification=EVSENotification.NONE,
rcd=False,
),
ac_evse_status=await evse_controller.get_ac_evse_status(),
# TODO Could maybe request an OCPP setting that determines
# whether or not a receipt is required and when
# (probably only makes sense at the beginning and end of
Expand Down
39 changes: 37 additions & 2 deletions tests/secc/states/test_iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from iso15118.secc.states.iso15118_2_states import (
Authorization,
ChargeParameterDiscovery,
ChargingStatus,
CurrentDemand,
PaymentDetails,
PowerDelivery,
Expand All @@ -15,6 +16,7 @@
WeldingDetection,
)
from iso15118.secc.states.secc_state import StateSECC
from iso15118.shared.messages.datatypes import EVSENotification
from iso15118.shared.messages.enums import (
AuthEnum,
AuthorizationStatus,
Expand All @@ -23,10 +25,11 @@
EVSEProcessing,
)
from iso15118.shared.messages.iso15118_2.body import ResponseCode
from iso15118.shared.messages.iso15118_2.datatypes import CertificateChain
from iso15118.shared.messages.iso15118_2.datatypes import ACEVSEStatus, CertificateChain
from tests.secc.states.test_messages import (
get_charge_parameter_discovery_req_message_departure_time_one_hour,
get_charge_parameter_discovery_req_message_no_departure_time,
get_dummy_charging_status_req,
get_dummy_v2g_message_authorization_req,
get_dummy_v2g_message_payment_details_req,
get_dummy_v2g_message_power_delivery_req_charge_start,
Expand All @@ -39,7 +42,7 @@

@patch("iso15118.shared.states.EXI.to_exi", new=Mock(return_value=b"01"))
@pytest.mark.asyncio
class TestEvScenarios:
class TestV2GSessionScenarios:
@pytest.fixture(autouse=True)
def _comm_session(self, comm_secc_session_mock):
self.comm_session = comm_secc_session_mock
Expand Down Expand Up @@ -383,3 +386,35 @@ async def test_service_discovery_req_unexpected_state(self):
service_discovery.message.body.service_discovery_res.response_code
is ResponseCode.FAILED_SEQUENCE_ERROR
)

async def test_charging_status_evse_status(self):
charging_status = ChargingStatus(self.comm_session)
self.comm_session.writer = Mock()
self.comm_session.writer.get_extra_info = Mock()
self.comm_session.selected_schedule = 1
await charging_status.process_message(message=get_dummy_charging_status_req())

charging_status_res = charging_status.message.body.charging_status_res
assert charging_status_res.ac_evse_status == ACEVSEStatus(
notification_max_delay=0,
evse_notification=EVSENotification.NONE,
rcd=False,
)

async def test_charging_status_evse_status_altered(self):
charging_status = ChargingStatus(self.comm_session)
self.comm_session.writer = Mock()
self.comm_session.writer.get_extra_info = Mock()
self.comm_session.selected_schedule = 1

async def get_ac_evse_status_patch():
return ACEVSEStatus(
notification_max_delay=0,
evse_notification=EVSENotification.NONE,
rcd=True,
)

self.comm_session.evse_controller.get_ac_evse_status = get_ac_evse_status_patch
await charging_status.process_message(message=get_dummy_charging_status_req())
charging_status_res = charging_status.message.body.charging_status_res
assert charging_status_res.ac_evse_status == await get_ac_evse_status_patch()
9 changes: 9 additions & 0 deletions tests/secc/states/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
AuthorizationReq,
Body,
ChargeParameterDiscoveryReq,
ChargingStatusReq,
PaymentDetailsReq,
PowerDeliveryReq,
ServiceDiscoveryReq,
Expand Down Expand Up @@ -218,3 +219,11 @@ def get_dummy_v2g_message_service_discovery_req() -> V2GMessage:
header=MessageHeader(session_id=MOCK_SESSION_ID),
body=Body(service_discovery_req=service_discovery_req),
)


def get_dummy_charging_status_req() -> V2GMessage:
charging_status_req = ChargingStatusReq()
return V2GMessage(
header=MessageHeader(session_id=MOCK_SESSION_ID),
body=Body(charging_status_req=charging_status_req),
)

0 comments on commit 15c3a5a

Please sign in to comment.