You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current routing API provides very little flexibility. The current approach with the @on() decorator has a few limitations.
Issues
The interface of a handlers is limited to receive primitive types like str, int, list or dict. It would be great if the framework allow handlers taking composite types. Compare the first 'old' style of routing with the second example that uses composite types.
Handlers only receive data that's available in the Call's payload. It would be great if also other dependencies could be injected into a handler. For example, the unique id of message. See Add call unique id to handler kwargs #545 . Or maybe a database connection. Or the IP address of the charger.
Handlers are tightly coupled an instance of ocpp.v16.ChargePoint or ocpp.v201.ChargePoint. You can't register plain function as handlers. E.g., this is not possible:
FastAPI allows handlers to receive any type, as long as that type can be constructed from an HTTP request. This library could implement a similar approach. Below are three examples of how dependency injection could look like:
# Filter the unique_id from a calldefunique_id(call: Call) ->str:
...
classChargePoint():
@on("heartbeat")asyncdefon_heartbeat(
self,
unique_id: str=Depends(unique_id),
):
...
# Returns the EVSE ID of a connectiondefevse_id(...) ->str:
...
# Returns a connection to a databasedefget_db() ->DbConnection:
...
@on("BootNotification")asyncdefon_boot_notification(
evse_id: str=Depends(evse_id),
db: DbConnection=Depends(get_db),
):
""" Look up EVSE ID in database and to verify if it is allowed to connect. """
...
The text was updated successfully, but these errors were encountered:
The current routing API provides very little flexibility. The current approach with the
@on()
decorator has a few limitations.Issues
str
,int
,list
ordict
. It would be great if the framework allow handlers taking composite types. Compare the first 'old' style of routing with the second example that uses composite types.Handlers only receive data that's available in the Call's payload. It would be great if also other dependencies could be injected into a handler. For example, the unique id of message. See Add call unique id to handler kwargs #545 . Or maybe a database connection. Or the IP address of the charger.
Handlers are tightly coupled an instance of
ocpp.v16.ChargePoint
orocpp.v201.ChargePoint
. You can't register plain function as handlers. E.g., this is not possible:In my experience, binding the handlers to a a class leads to large and complex classes. Where each handler mutates a piece of state within the class.
Possible solution
I'm wondering if we can implement a dependency mechanism that allows users a lot more flexibility. FastAPI has an interesting Dependency Injection mechanism. And I'm keen to figure out if we can implement something similar.
FastAPI allows handlers to receive any type, as long as that type can be constructed from an HTTP request. This library could implement a similar approach. Below are three examples of how dependency injection could look like:
The text was updated successfully, but these errors were encountered: