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

Add NotImplemented exception #494

Merged
merged 24 commits into from
Nov 3, 2023
Merged
Changes from 4 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
47 changes: 39 additions & 8 deletions ocpp/charge_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
from dataclasses import asdict
from typing import Dict, List, Union

from ocpp.exceptions import NotSupportedError, OCPPError
from ocpp.exceptions import NotImplementedError, NotSupportedError, OCPPError
from ocpp.messages import Call, MessageType, unpack, validate_payload
from ocpp.routing import create_route_map
from ocpp.v16.enums import Action as v16_Action
from ocpp.v201.enums import Action as v201_Action

LOGGER = logging.getLogger("ocpp")

Expand Down Expand Up @@ -165,17 +167,32 @@ async def _handle_call(self, msg):

First the '_on_action' hook is executed and its response is returned to
the client. If there is no '_on_action' hook for Action in the message
a CallError with a NotSupportedError is returned.
a CallError with a NotImplementedError is returned. If the Action is
not supported by the OCPP version a NotSupportedError is returned.

Next the '_after_action' hook is executed.

"""
try:
handlers = self.route_map[msg.action]
except KeyError:
raise NotSupportedError(
details={"cause": f"No handler for {msg.action} registered."}
)
if self._ocpp_version == "1.6":
if hasattr(v16_Action, msg.action):
raise NotImplementedError(
details={"cause": f"No handler for {msg.action} registered."}
)
elif self._ocpp_version in ["2.0", "2.0.1"]:
if hasattr(v201_Action, msg.action):
raise NotImplementedError(
details={"cause": f"No handler for {msg.action} registered."}
)
else:
raise NotSupportedError(
details={
"cause": f"{msg.action} not supported by OCPP"
"{self._ocpp_version}."
}
)
drc38 marked this conversation as resolved.
Show resolved Hide resolved

if not handlers.get("_skip_schema_validation", False):
validate_payload(msg, self._ocpp_version)
Expand All @@ -190,9 +207,23 @@ async def _handle_call(self, msg):
try:
handler = handlers["_on_action"]
except KeyError:
raise NotSupportedError(
details={"cause": f"No handler for {msg.action} registered."}
)
if self._ocpp_version == "1.6":
if hasattr(v16_Action, msg.action):
raise NotImplementedError(
details={"cause": f"No handler for {msg.action} registered."}
)
elif self._ocpp_version in ["2.0", "2.0.1"]:
if hasattr(v201_Action, msg.action):
raise NotImplementedError(
details={"cause": f"No handler for {msg.action} registered."}
)
else:
raise NotSupportedError(
details={
"cause": f"{msg.action} not supported by OCPP"
"{self._ocpp_version}."
}
)

try:
response = handler(**snake_case_payload)
Expand Down
Loading