Implement transaction handling
This commit is contained in:
parent
161c6aa027
commit
a65dee8962
16 changed files with 331 additions and 94 deletions
|
@ -7,19 +7,19 @@ from app.util.websocket_wrapper import WebSocketWrapper
|
|||
|
||||
router = APIRouter()
|
||||
|
||||
@router.websocket("/{charging_station_friendly_name}")
|
||||
@router.websocket("/{chargepoint_identity}")
|
||||
async def websocket_endpoint(
|
||||
*,
|
||||
websocket: WebSocket,
|
||||
charging_station_friendly_name: str,
|
||||
chargepoint_identity: str,
|
||||
):
|
||||
""" For every new charging station that connects, create a ChargePoint
|
||||
instance and start listening for messages.
|
||||
"""
|
||||
if (websocket.user.friendly_name != charging_station_friendly_name):
|
||||
if (websocket.user.identity != chargepoint_identity):
|
||||
raise WebSocketException(code=1008, reason="Username doesn't match chargepoint identifier")
|
||||
|
||||
logging.info("Charging station '%s' (%s) connected", charging_station_friendly_name, websocket.user.id)
|
||||
logging.info("Charging station '%s' (%s) connected", chargepoint_identity, websocket.user.id)
|
||||
|
||||
# Check protocols
|
||||
try:
|
||||
|
@ -43,5 +43,5 @@ async def websocket_endpoint(
|
|||
|
||||
# Accept connection and begin communication
|
||||
await websocket.accept(subprotocol="ocpp2.0.1")
|
||||
cp = ChargePoint(charging_station_friendly_name, WebSocketWrapper(websocket))
|
||||
cp = ChargePoint(chargepoint_identity, WebSocketWrapper(websocket))
|
||||
await chargepoint_manager.start(websocket.user.id, cp)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue