Initial commit
This commit is contained in:
commit
b8216f6ade
25 changed files with 1539 additions and 0 deletions
31
src/ocpp_proto/chargepoint_manager.py
Normal file
31
src/ocpp_proto/chargepoint_manager.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
import logging
|
||||
from typing import Any, Coroutine, Dict
|
||||
|
||||
from websockets import ConnectionClosed
|
||||
|
||||
from ocpp_proto.chargepoint import ChargePoint
|
||||
|
||||
__active_connections: Dict[str, ChargePoint] = {}
|
||||
|
||||
async def start(cp: ChargePoint):
|
||||
try:
|
||||
__active_connections[cp.id] = cp
|
||||
await cp.start()
|
||||
except ConnectionClosed:
|
||||
logging.info("Charging station '%s' disconnected", cp.id)
|
||||
__active_connections.pop(cp.id, None)
|
||||
|
||||
async def call(
|
||||
chargepoint_id: str,
|
||||
payload: Any,
|
||||
suppress: bool = True,
|
||||
unique_id: Any | None = None
|
||||
) -> Coroutine[Any, Any, Any | None]:
|
||||
try:
|
||||
cp = __active_connections[chargepoint_id]
|
||||
return cp.call(payload, suppress, unique_id)
|
||||
except KeyError as e:
|
||||
raise e
|
||||
|
||||
def is_connected(chargepoint_id: str):
|
||||
return chargepoint_id in __active_connections.keys()
|
Loading…
Add table
Add a link
Reference in a new issue