Prepare monorepo

This commit is contained in:
Oliver Traber 2025-03-13 22:11:20 +01:00
parent a1ddb43ed0
commit 938582155d
Signed by: Bluemedia
GPG key ID: C0674B105057136C
61 changed files with 5 additions and 5 deletions

View 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()