- # If delay is not None, sleep for delay seconds
- if delay:
- await asyncio.sleep(delay)
-
- # If period is not None, send command repeatedly with period interval
- if period:
- async def send_command_repeatedly():
- while True:
- command_name = await cp.receive_command()
- try:
- match command_name:
- case Action.ClearCache:
- logging.info("ClearCache parser working")
- await cp.send_clear_cache()
- case Action.GetBaseReport:
- logging.info("GetBaseReport parser working")
- await cp.send_get_base_report()
- case _:
- logging.warning(f"Unsupported command {command_name}")
- except Exception as e:
- logging.exception(f"Failure while processing command {command_name}")
- finally:
- await asyncio.sleep(period)
-
- timer = RepeatTimer(period, send_command_repeatedly)
- await timer.start()
- await timer.wait_closed() # Wait for timer to finish before exiting
-
- else:
- if command_name == "GetBaseReport":
- await cp.send_get_base_report()
+ try:
+ if delay:
+ await asyncio.sleep(delay)
+ cp.send_command(command_name)
+ if period:
+ command_timer = RepeatTimer(
+ period,
+ cp.send_command,
+ [command_name],
+ )
+ command_timer.start()
+ except ConnectionClosed:
+ logging.info("ChargePoint %s closed connection", cp.id)
+ ChargePoints.remove(cp)
+ logging.debug("Connected ChargePoint(s): %d", len(ChargePoints))