api command reference doc added
This commit is contained in:
@@ -318,6 +318,30 @@ async def reset_measurement(unit_id: str, db: Session = Depends(get_db)):
|
||||
raise HTTPException(status_code=502, detail=str(e))
|
||||
|
||||
|
||||
@router.get("/{unit_id}/measurement-state")
|
||||
async def get_measurement_state(unit_id: str, db: Session = Depends(get_db)):
|
||||
"""Get current measurement state (Start/Stop)."""
|
||||
cfg = db.query(NL43Config).filter_by(unit_id=unit_id).first()
|
||||
if not cfg:
|
||||
raise HTTPException(status_code=404, detail="NL43 config not found")
|
||||
|
||||
if not cfg.tcp_enabled:
|
||||
raise HTTPException(status_code=403, detail="TCP communication is disabled for this device")
|
||||
|
||||
client = NL43Client(cfg.host, cfg.tcp_port, ftp_username=cfg.ftp_username, ftp_password=cfg.ftp_password)
|
||||
try:
|
||||
state = await client.get_measurement_state()
|
||||
is_measuring = state == "Start"
|
||||
return {
|
||||
"status": "ok",
|
||||
"measurement_state": state,
|
||||
"is_measuring": is_measuring
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to get measurement state for {unit_id}: {e}")
|
||||
raise HTTPException(status_code=502, detail=str(e))
|
||||
|
||||
|
||||
@router.post("/{unit_id}/sleep")
|
||||
async def sleep_device(unit_id: str, db: Session = Depends(get_db)):
|
||||
"""Put the device into sleep mode for battery conservation."""
|
||||
|
||||
Reference in New Issue
Block a user