Prepare monorepo
This commit is contained in:
parent
a1ddb43ed0
commit
938582155d
61 changed files with 5 additions and 5 deletions
33
backend/app/ocpp_proto/chargepoint_manager.py
Normal file
33
backend/app/ocpp_proto/chargepoint_manager.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import logging
|
||||
from typing import Any, Coroutine, Dict
|
||||
from uuid import UUID
|
||||
|
||||
from websockets import ConnectionClosed
|
||||
from starlette.websockets import WebSocketDisconnect
|
||||
|
||||
from app.ocpp_proto.chargepoint import ChargePoint
|
||||
|
||||
__active_connections: Dict[UUID, ChargePoint] = {}
|
||||
|
||||
async def start(id: UUID, cp: ChargePoint):
|
||||
try:
|
||||
__active_connections[id] = cp
|
||||
await cp.start()
|
||||
except (ConnectionClosed, WebSocketDisconnect):
|
||||
logging.info("Charging station '%s' (%s) disconnected", cp.id, id)
|
||||
__active_connections.pop(id, None)
|
||||
|
||||
async def call(
|
||||
chargepoint_id: UUID,
|
||||
payload: Any,
|
||||
suppress: bool = True,
|
||||
unique_id: Any | None = None
|
||||
) -> Coroutine[Any, Any, Any | None]:
|
||||
try:
|
||||
cp = __active_connections[chargepoint_id]
|
||||
return await cp.call(payload, suppress, unique_id)
|
||||
except KeyError as e:
|
||||
raise e
|
||||
|
||||
def is_connected(chargepoint_id: UUID):
|
||||
return chargepoint_id in __active_connections.keys()
|
Loading…
Add table
Add a link
Reference in a new issue