Skip to content

Commit

Permalink
improvements from Andres review
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaslombriserdesignwerk committed Sep 20, 2022
1 parent df39f54 commit 84cf7f1
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 66 deletions.
7 changes: 4 additions & 3 deletions iso15118/secc/states/din_spec_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class PreCharge(StateSECC):

def __init__(self, comm_session: SECCCommunicationSession):
super().__init__(comm_session, Timeouts.V2G_SECC_SEQUENCE_TIMEOUT)
self.expect_pre_charge_req = True
self.expecting_pre_charge_req = True

async def process_message(
self,
Expand All @@ -530,7 +530,7 @@ async def process_message(
message_exi: bytes = None,
):
msg = self.check_msg_dinspec(
message, [PreChargeReq, PowerDeliveryReq], self.expect_pre_charge_req
message, [PreChargeReq, PowerDeliveryReq], self.expecting_pre_charge_req
)
if not msg:
return
Expand Down Expand Up @@ -578,7 +578,6 @@ async def process_message(
await self.comm_session.evse_controller.set_precharge(
precharge_req.ev_target_voltage, precharge_req.ev_target_current
)
self.expect_pre_charge_req = False

dc_charger_state = await self.comm_session.evse_controller.get_dc_evse_status()
evse_present_voltage = (
Expand All @@ -598,6 +597,8 @@ async def process_message(
Namespace.DIN_MSG_DEF,
)

self.expecting_pre_charge_req = False


class PowerDelivery(StateSECC):
"""
Expand Down
7 changes: 4 additions & 3 deletions iso15118/secc/states/iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,7 +1934,7 @@ class PreCharge(StateSECC):

def __init__(self, comm_session: SECCCommunicationSession):
super().__init__(comm_session, Timeouts.V2G_SECC_SEQUENCE_TIMEOUT)
self.precharge_req_was_reveived = False
self.expecting_precharge_req = False

async def process_message(
self,
Expand All @@ -1950,7 +1950,7 @@ async def process_message(
msg = self.check_msg_v2(
message,
[PreChargeReq, PowerDeliveryReq],
not self.precharge_req_was_reveived,
not self.expecting_precharge_req,
)
if not msg:
return
Expand Down Expand Up @@ -1998,7 +1998,6 @@ async def process_message(
await self.comm_session.evse_controller.set_precharge(
precharge_req.ev_target_voltage, precharge_req.ev_target_current
)
self.precharge_req_was_reveived = True

dc_charger_state = await self.comm_session.evse_controller.get_dc_evse_status()
evse_present_voltage = (
Expand All @@ -2019,6 +2018,8 @@ async def process_message(
Namespace.ISO_V2_MSG_DEF,
)

self.expecting_precharge_req = True


class CurrentDemand(StateSECC):
"""
Expand Down
133 changes: 95 additions & 38 deletions iso15118/shared/messages/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,135 +329,192 @@ class PVStartValue(PhysicalValue):


class PVEVEnergyCapacityDin(PVEVEnergyCapacity):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVEnergyCapacity)
unit: Literal[UnitSymbol.WATT_HOURS] = Field(None, alias="Unit")


class PVEVEnergyRequestDin(PVEVEnergyRequest):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVEnergyRequest)
unit: Literal[UnitSymbol.WATT_HOURS] = Field(None, alias="Unit")


class PVEVMaxCurrentLimitDin(PVEVMaxCurrentLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVMaxCurrentLimit)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVMaxPowerLimitDin(PVEVMaxPowerLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVMaxPowerLimit)
unit: Literal[UnitSymbol.WATT] = Field(None, alias="Unit")


class PVEVMaxVoltageLimitDin(PVEVMaxVoltageLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVMaxVoltageLimit)
unit: Literal[UnitSymbol.VOLTAGE] = Field(None, alias="Unit")


class PVEVSECurrentRegulationToleranceDin(PVEVSECurrentRegulationTolerance):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSECurrentRegulationTolerance)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVSEEnergyToBeDeliveredDin(PVEVSEEnergyToBeDelivered):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEEnergyToBeDelivered)
unit: Literal[UnitSymbol.WATT_HOURS] = Field(None, alias="Unit")


class PVEVSEMaxCurrentLimitDin(PVEVSEMaxCurrentLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEMaxCurrentLimit)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVSEMaxPowerLimitDin(PVEVSEMaxPowerLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEMaxPowerLimit)
unit: Literal[UnitSymbol.WATT] = Field(None, alias="Unit")


class PVEVSEMaxVoltageLimitDin(PVEVSEMaxVoltageLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEMaxVoltageLimit)
unit: Literal[UnitSymbol.VOLTAGE] = Field(None, alias="Unit")


class PVEVSEMinCurrentLimitDin(PVEVSEMinCurrentLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEMinCurrentLimit)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVSEMinVoltageLimitDin(PVEVSEMinVoltageLimit):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEMinVoltageLimit)
unit: Literal[UnitSymbol.VOLTAGE] = Field(None, alias="Unit")


class PVEVSEPeakCurrentRippleDin(PVEVSEPeakCurrentRipple):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEPeakCurrentRipple)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVSEPresentCurrentDin(PVEVSEPresentCurrent):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEPresentCurrent)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVSEPresentVoltageDin(PVEVSEPresentVoltage):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVSEPresentVoltage)
unit: Literal[UnitSymbol.VOLTAGE] = Field(None, alias="Unit")


class PVEVTargetCurrentDin(PVEVTargetCurrent):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVTargetCurrent)
unit: Literal[UnitSymbol.AMPERE] = Field(None, alias="Unit")


class PVEVTargetVoltageDin(PVEVTargetVoltage):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVEVTargetVoltage)
unit: Literal[UnitSymbol.VOLTAGE] = Field(None, alias="Unit")


class PVRemainingTimeToFullSOCDin(PVRemainingTimeToFullSOC):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVRemainingTimeToFullSOC)
unit: Literal[UnitSymbol.SECONDS] = Field(None, alias="Unit")


class PVRemainingTimeToBulkSOCDin(PVRemainingTimeToBulkSOC):
"""See section 9.5.2.4 in DIN SPEC 70121"""
"""
See section 9.5.2.4 in DIN SPEC 70121
In DIN the Element unit is optional, in ISO it is mandatory.
"""

super(PVRemainingTimeToBulkSOC)
unit: Literal[UnitSymbol.SECONDS] = Field(None, alias="Unit")


Expand Down
22 changes: 0 additions & 22 deletions tests/shared/messages/test_din_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,6 @@ class TestMessage:
json_str='{"V2G_Message": {"Header": {"SessionID": "4FF877E9B597CC1C"},'
'"Body": {"SessionStopRes": {"ResponseCode": "OK"}}}}',
),
]


DIN_REAL_WORLD_MESSAGES = [
TestMessage(
message_name="ChargeParameterDiscoveryReq",
json_str='{"V2G_Message": {"Header": {"SessionID": "C427C77F5FAA1DD5"},'
Expand Down Expand Up @@ -263,21 +259,3 @@ def test_common_v2g_messages_can_be_parsed_and_created(self, message: TestMessag

message = V2GMessageDINSPEC.parse_obj(decoded_dict["V2G_Message"])
assert isinstance(message, V2GMessageDINSPEC)


class TestDinSpec_RealWorldMessageCreation:
# This test is used to ensure the compatibility with
# vehicles in field which might behave not always according to standard

@pytest.mark.parametrize(
"message",
DIN_REAL_WORLD_MESSAGES,
ids=[f"parse_and_create_{msg.message_name}" for msg in DIN_REAL_WORLD_MESSAGES],
)
def test_real_world_v2g_messages_can_be_parsed_and_created(
self, message: TestMessage
):
decoded_dict = json.loads(message.json_str, cls=CustomJSONDecoder)

message = V2GMessageDINSPEC.parse_obj(decoded_dict["V2G_Message"])
assert isinstance(message, V2GMessageDINSPEC)

0 comments on commit 84cf7f1

Please sign in to comment.