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

Fixes for issue where the saved session context wasn't found on waking up. #388

Merged
merged 1 commit into from
Mar 20, 2024
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
33 changes: 24 additions & 9 deletions iso15118/secc/comm_session_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def __init__(
config: Config,
evse_controller: EVSEControllerInterface,
evse_id: str,
ev_session_context: Optional[EVSessionContext15118] = None,
):
# Need to import here to avoid a circular import error
# pylint: disable=import-outside-toplevel
Expand All @@ -93,6 +94,10 @@ def __init__(
self.evse_controller = evse_controller
# EVSE ID associated with this session
self.evse_id = evse_id
# EV Session context associated if available.
self.ev_session_context: EVSessionContext15118 = (
ev_session_context or EVSessionContext15118()
)
# 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 @@ -133,7 +138,6 @@ def __init__(
# CurrentDemandRes. The SECC must send a copy in the MeteringReceiptReq
# TODO Add support for ISO 15118-20 MeterInfo
self.sent_meter_info: Optional[MeterInfoV2] = None
self.ev_session_context: EVSessionContext15118 = EVSessionContext15118()
self.is_tls = self._is_tls(transport)

def save_session_info(self):
Expand Down Expand Up @@ -283,8 +287,16 @@ async def get_from_rcv_queue(self, queue: asyncio.Queue):
)

try:
comm_session, task = self.comm_sessions[notification.ip_address]
comm_session.resume()
comm_session, _ = self.comm_sessions[notification.ip_address[0]]
ev_context = comm_session.ev_session_context
comm_session = SECCCommunicationSession(
notification.transport,
self._rcv_queue,
self.config,
self.evse_controller,
await self.evse_controller.get_evse_id(Protocol.UNKNOWN),
ev_context,
)
except (KeyError, ConnectionResetError) as e:
if isinstance(e, ConnectionResetError):
logger.info("Can't resume session. End and start new one.")
Expand All @@ -304,7 +316,10 @@ async def get_from_rcv_queue(self, queue: asyncio.Queue):
Timeouts.V2G_EVCC_COMMUNICATION_SETUP_TIMEOUT
)
)
self.comm_sessions[notification.ip_address] = (comm_session, task)
self.comm_sessions[notification.ip_address[0]] = (
comm_session,
task,
)
self._current_peer_ip = notification.ip_address
elif isinstance(notification, StopNotification):
try:
Expand Down Expand Up @@ -339,19 +354,19 @@ def close_session(self):
logger.warning(f"Error while indicating EOF to transport reader: {e}")

async def end_current_session(
self, peer_ip_address: str, session_stop_action: SessionStopAction
self, peer_ip_address: Any, session_stop_action: SessionStopAction
):
try:
await cancel_task(self.tcp_server_handler)
await cancel_task(self.comm_sessions[peer_ip_address][1])
await cancel_task(self.comm_sessions[peer_ip_address[0]][1])
except Exception as e:
logger.warning(f"Unexpected error ending current session: {e}")
finally:
if session_stop_action == SessionStopAction.TERMINATE:
del self.comm_sessions[peer_ip_address]
del self.comm_sessions[peer_ip_address[0]]
else:
logger.debug(
f"Preserved session state: {self.comm_sessions[peer_ip_address][0].ev_session_context}" # noqa
logger.info(
f"Preserved session state: {self.comm_sessions[peer_ip_address[0]][0].ev_session_context}" # noqa
)

self.tcp_server_handler = None
Expand Down
2 changes: 1 addition & 1 deletion iso15118/secc/states/iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ async def process_message(
and msg.header.session_id == self.comm_session.ev_session_context.session_id
):
# The EV wants to resume the previously paused charging session
session_id = self.comm_session.session_id
session_id = self.comm_session.ev_session_context.session_id
self.response_code = ResponseCode.OK_OLD_SESSION_JOINED
else:
# False session ID from EV, gracefully assigning new session ID
Expand Down