From 28ee78d055dfbc464456ae0dac2f6054f69e9d2c Mon Sep 17 00:00:00 2001 From: Etienne Chassaing <60154720+cetiennec@users.noreply.github.com> Date: Wed, 27 Aug 2025 15:28:59 +0200 Subject: [PATCH] send_command_with_delay is now using http request --- main.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index a01400d..023df5d 100644 --- a/main.py +++ b/main.py @@ -427,11 +427,25 @@ async def record_data_loop(): ## AUTOMATIC TESTING async def send_command_with_delay( - state: str, pu: int, delay_s: int = 0, ploop_setpoint: float = 2.5, qperm_setpoint:float = 1200.0 + state: str, + pu: int, + delay_s: int = 0, + ploop_setpoint: float = 2.5, + qperm_setpoint: float = 1200.0, ): await asyncio.sleep(delay_s) logging.info(f"[AUTO TEST] Sending {state} to PU{pu} after {delay_s}s") - can_backend.send_state_command(state, pu, ploop_setpoint, qperm_setpoint) + + url = f"http://127.0.0.1:8000/command/{state}/pu/{pu}?ploop_setpoint={ploop_setpoint}&qperm_setpoint={qperm_setpoint}" + try: + async with httpx.AsyncClient(timeout=5.0) as client: + response = await client.post(url) + response.raise_for_status() + logging.info(f"[AUTO TEST] Command {state} sent successfully to PU{pu}: {response.json()}") + return response.json() + except Exception as e: + logging.error(f"[AUTO TEST] Failed to send {state} to PU{pu}: {e}") + return {"status": "error", "detail": str(e)} async def set_patients_with_delay(count: int, delay_s: int): await asyncio.sleep(delay_s)