send_command_with_delay is now using http request

This commit is contained in:
Etienne Chassaing 2025-08-27 15:28:59 +02:00
parent ead7e3b647
commit 28ee78d055

18
main.py
View File

@ -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)