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

JTT-112 Feat: Enable mypy support #294

Merged
merged 26 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
878c9b7
refactor: code-quality
santiagosalamandri Sep 7, 2023
d4bf400
refactor: code-quality
santiagosalamandri Sep 7, 2023
0cfffd5
fix: arg name
santiagosalamandri Sep 7, 2023
e626e1d
fix: param type
santiagosalamandri Sep 7, 2023
e4ab3f2
feat: add annotations
santiagosalamandri Sep 7, 2023
ff4bace
refactor: add checks for code quality
santiagosalamandri Sep 7, 2023
6bcacad
feat: remove annotation
santiagosalamandri Sep 7, 2023
ccf31c1
fix: add annotation and remove hardcoded value
santiagosalamandri Sep 7, 2023
302695d
chore: ignore wrong mypy issue
santiagosalamandri Sep 7, 2023
6db3835
refactor: code quality
santiagosalamandri Sep 7, 2023
4bc7935
feat: check types and add annotatios
santiagosalamandri Sep 7, 2023
46d7919
fix: remove stop_state_machine and annotations
santiagosalamandri Sep 7, 2023
3712d8f
fix: code quality and fix types
santiagosalamandri Sep 7, 2023
e177a9f
fix: types
santiagosalamandri Sep 7, 2023
fc75705
refactor: code quality
santiagosalamandri Sep 7, 2023
d840e1a
fix: types and return values
santiagosalamandri Sep 7, 2023
806491f
feat: enable mypy on GHA
santiagosalamandri Sep 7, 2023
418ba56
feat: enable --check-untyped-defs on mypy
santiagosalamandri Sep 7, 2023
f8a97c2
feat: add myp-extensions and types-toml
santiagosalamandri Sep 7, 2023
10bac29
feat: update poetry.lock
santiagosalamandri Sep 7, 2023
e2b664b
fix: change log level back to trace
santiagosalamandri Sep 12, 2023
834983f
fix: raise CertAttributeError exc when no BasicContrains extension is…
santiagosalamandri Sep 12, 2023
819b1a5
feat: add py.typed to module
santiagosalamandri Sep 12, 2023
e3dae25
fix: return filtered list
santiagosalamandri Sep 12, 2023
3a14df8
chore: code quality
santiagosalamandri Sep 12, 2023
8f9c5da
fix: conditional order
santiagosalamandri Sep 12, 2023
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
5 changes: 2 additions & 3 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ jobs:
- name: Install dependencies
run: make install-local

# TODO: Fix MyPy issues https://github.com/SwitchEV/iso15118/issues/93
# - name: Mypy
# run: make mypy
- name: Mypy
run: make mypy

- name: Black
run: make black
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ test:

# Run mypy checks
mypy:
poetry run mypy --config-file mypy.ini iso15118 tests
poetry run mypy --config-file mypy.ini --check-untyped-defs iso15118 tests

# Reformat with isort and black
reformat:
Expand Down
24 changes: 12 additions & 12 deletions iso15118/evcc/comm_session_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import logging
from asyncio.streams import StreamReader, StreamWriter
from ipaddress import IPv6Address
from typing import List, Optional, Tuple, Union
from typing import Coroutine, List, Optional, Tuple, Union

from pydantic.error_wrappers import ValidationError

Expand Down Expand Up @@ -106,7 +106,7 @@ def __init__(
self.service_details_to_request: List[int] = []
# Protocols supported by the EVCC as sent to the SECC via
# the SupportedAppProtocolReq message
self.supported_protocols: List[Protocol] = []
self.supported_app_protocols: List[AppProtocol] = []
# The Ongoing timer (given in seconds) starts running once the EVCC
# receives a response with the field EVSEProcessing set to 'Ongoing'.
# Once the timer is up, the EV will terminate the communication session.
Expand Down Expand Up @@ -197,8 +197,8 @@ def create_sap(self) -> Union[SupportedAppProtocolReq, None]:
)
app_protocols.append(app_protocol_entry)

self.supported_protocols = app_protocols
sap_req = SupportedAppProtocolReq(app_protocol=self.supported_protocols)
self.supported_app_protocols = app_protocols
sap_req = SupportedAppProtocolReq(app_protocol=self.supported_app_protocols)

return sap_req

Expand Down Expand Up @@ -269,21 +269,21 @@ def __init__(
codec: IEXICodec,
ev_controller: EVControllerInterface,
):
self.list_of_tasks = []
self.udp_client = None
self.tcp_client = None
self.tls_client = None
self.config = config
self.iface = iface
self.ev_controller = ev_controller
self.list_of_tasks: List[Coroutine] = []
self.udp_client: UDPClient = None
self.tcp_client: TCPClient = None
self.tls_client: bool = None
self.config: EVCCConfig = config
self.iface: str = iface
self.ev_controller: EVControllerInterface = ev_controller
self.sdp_retries_number = SDP_MAX_REQUEST_COUNTER
self._sdp_retry_cycles = self.config.sdp_retry_cycles

# Set the selected EXI codec implementation
EXI().set_exi_codec(codec)

# Receiving queue for UDP client to notify about incoming datagrams
self._rcv_queue = asyncio.Queue(0)
self._rcv_queue: asyncio.Queue = asyncio.Queue(0)

# The communication session is a tuple containing the session itself
# and the associated task, so we can cancel the task when needed
Expand Down
6 changes: 3 additions & 3 deletions iso15118/evcc/controller/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,13 @@ async def select_vas_services_v20(
matched_vas_services = [
service for service in services if not service.is_energy_service
]
selected_vas_services: List[MatchedService] = []
selected_vas_services: List[SelectedVAS] = []
for vas_service in matched_vas_services:
selected_vas_services.append(
SelectedVAS(
service=vas_service,
service=vas_service.service,
is_free=vas_service.is_free,
parameter_set=selected_vas_services.parameter_sets[0],
parameter_set=vas_service.parameter_sets[0],
)
)
return selected_vas_services
Expand Down
3 changes: 2 additions & 1 deletion iso15118/evcc/evcc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class EVCCConfig(BaseModel):
raw_supported_energy_services: List[str] = Field(
_default_supported_energy_services, max_items=4, alias="supportedEnergyServices"
)
supported_energy_services: Optional[List[ServiceV20]] = None
supported_energy_services: List[ServiceV20] = None
is_cert_install_needed: bool = Field(False, alias="isCertInstallNeeded")
# Indicates the security level (either TCP (unencrypted) or TLS (encrypted))
# the EVCC shall send in the SDP request
Expand Down Expand Up @@ -119,3 +119,4 @@ async def load_from_file(file_name: str) -> EVCCConfig:
return ev_config
except Exception as err:
logger.debug(f"Error on loading evcc config file:{err}")
return EVCCConfig()
21 changes: 11 additions & 10 deletions iso15118/evcc/states/evcc_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
SupportedAppProtocolReq,
SupportedAppProtocolRes,
)
from iso15118.shared.messages.din_spec.body import BodyBase as BodyBaseDINSPEC
from iso15118.shared.messages.din_spec.body import Response as ResponseDINSPEC
from iso15118.shared.messages.din_spec.body import (
SessionSetupRes as SessionSetupResDINSPEC,
)
from iso15118.shared.messages.din_spec.msgdef import V2GMessage as V2GMessageDINSPEC
from iso15118.shared.messages.enums import ISOV20PayloadTypes, Namespace
from iso15118.shared.messages.iso15118_2.body import BodyBase as BodyBaseV2
from iso15118.shared.messages.iso15118_2.body import Response as ResponseV2
from iso15118.shared.messages.iso15118_2.body import (
SessionSetupRes as SessionSetupResV2,
Expand Down Expand Up @@ -132,9 +130,14 @@ def check_msg_v20(
V2GMessageV20,
V2GMessageDINSPEC,
],
expected_msg_type: Type[T],
) -> Optional[T]:
return self.check_msg(message, expected_msg_type, expected_msg_type)
expected_msg_type: Union[
Type[SupportedAppProtocolRes],
Type[ResponseV2],
Type[V2GResponseV20],
Type[ResponseDINSPEC],
],
) -> Optional[V2GMessageV20]:
return self.check_msg(message, V2GMessageV20, expected_msg_type)

def check_msg(
self,
Expand Down Expand Up @@ -184,12 +187,9 @@ def check_msg(
)
return None

msg_body: Union[
SupportedAppProtocolRes, BodyBaseV2, V2GResponseV20, BodyBaseDINSPEC
]
if isinstance(message, V2GMessageV2) or isinstance(message, V2GMessageDINSPEC):
# ISO 15118-2 or DIN SPEC 72101
msg_body = message.body.get_message()
msg_body = message.body.get_message() # type: ignore
else:
# SupportedAppProtocolReq, V2GRequest (ISO 15118-20)
msg_body = message
Expand All @@ -208,7 +208,8 @@ def check_msg(
return None

if (
not isinstance(
message is not None
and not isinstance(
msg_body,
(
SupportedAppProtocolRes,
Expand Down
Loading