Skip to content

Commit

Permalink
Minor logging improvement. (#162)
Browse files Browse the repository at this point in the history
* Minor logging improvement.

* Fixed tests.

* Updated hasattr() to use evse_id
  • Loading branch information
shalinnijel2 authored Nov 22, 2022
1 parent 43bd4a7 commit 90247c6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
4 changes: 4 additions & 0 deletions iso15118/secc/comm_session_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def __init__(
session_handler_queue: asyncio.Queue,
config: Config,
evse_controller: EVSEControllerInterface,
evse_id: str,
):
# Need to import here to avoid a circular import error
# pylint: disable=import-outside-toplevel
Expand All @@ -82,6 +83,8 @@ def __init__(
self.config = config
# The EVSE controller that implements the interface EVSEControllerInterface
self.evse_controller = evse_controller
# EVSE ID associated with this session
self.evse_id = evse_id
# The authorization option(s) offered with ServiceDiscoveryRes in
# ISO 15118-2 and with AuthorizationSetupRes in ISO 15118-20
self.offered_auth_options: Optional[List[AuthEnum]] = []
Expand Down Expand Up @@ -274,6 +277,7 @@ async def get_from_rcv_queue(self, queue: asyncio.Queue):
self._rcv_queue,
self.config,
self.evse_controller,
await self.evse_controller.get_evse_id(Protocol.UNKNOWN),
)

task = asyncio.create_task(
Expand Down
10 changes: 6 additions & 4 deletions iso15118/shared/comm_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,12 @@ async def process_message(self, message: bytes):
v2gtp_msg.payload, self.get_exi_ns(v2gtp_msg.payload_type)
)

logger.trace(
f"{v2gtp_msg.payload.hex()}:::"
f"{self.get_exi_ns(v2gtp_msg.payload_type).value}"
)
if hasattr(self.comm_session, "evse_id"):
logger.trace(
f"{self.comm_session.evse_id}:::"
f"{v2gtp_msg.payload.hex()}:::"
f"{self.get_exi_ns(v2gtp_msg.payload_type).value}"
)

except V2GMessageValidationError as exc:
self.comm_session.current_state.stop_state_machine(
Expand Down
8 changes: 7 additions & 1 deletion iso15118/shared/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,13 @@ def create_next_message(
# Step 3
try:
exi_payload = EXI().to_exi(to_be_exi_encoded, namespace)
logger.trace(f"{exi_payload.hex()}:::{namespace.value}")

if hasattr(self.comm_session, "evse_id"):
logger.trace(
f"{self.comm_session.evse_id}:::"
f"{exi_payload.hex()}:::"
f"{namespace.value}"
)
except EXIEncodingError as exc:
logger.error(f"{exc}")
self.next_state = Terminate
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ def comm_secc_session_mock():
comm_session_mock.stop_reason = StopNotification(False, "pytest")
comm_session_mock.evse_controller = SimEVSEController()
comm_session_mock.protocol = Protocol.UNKNOWN
comm_session_mock.evse_id = "UK123E1234"
return comm_session_mock
1 change: 1 addition & 0 deletions tests/dinspec/secc/test_dinspec_secc_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def _comm_session(self):
self.comm_session.stop_reason = StopNotification(False, "pytest")
self.comm_session.evse_controller = SimEVSEController()
self.comm_session.protocol = Protocol.UNKNOWN
self.comm_session.evse_id = "UK123E1234"
self.comm_session.writer = MockWriter()

async def test_sap_to_billing(self):
Expand Down

0 comments on commit 90247c6

Please sign in to comment.