__main__.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """python -m hth_sdk demo|doctor"""
  2. from __future__ import annotations
  3. import sys
  4. def main(argv: list[str] | None = None) -> int:
  5. args = list(sys.argv[1:] if argv is None else argv)
  6. cmd = args[0] if args else "demo"
  7. rest = args[1:]
  8. if cmd in {"doctor", "self-test", "selftest"}:
  9. from hth_sdk.doctor import main as doctor_main
  10. return doctor_main(rest)
  11. if cmd in {"demo", "quickstart"}:
  12. from hth_sdk import HTH
  13. with HTH.demo() as hth:
  14. state = hth.read()
  15. print(state.max_temperature_c)
  16. result = hth.set(fan=20, heater=30, door=0)
  17. print(result.ok)
  18. return 0
  19. if cmd in {"policy"}:
  20. from hth_sdk import HTH
  21. with HTH.demo(scenario="coupled_4chamber", seed=1, speed=20) as hth:
  22. for state in hth.watch(period=0.05, count=6):
  23. if not state.ready or not state.fresh:
  24. continue
  25. heat = 25 if (state.max_temperature_c or 0) < 45 else 0
  26. result = hth.set(fan=20, heater=heat, door=0)
  27. print(state.max_temperature_c, result.ok)
  28. return 0
  29. sys.stderr.write("usage: python -m hth_sdk [demo|doctor|policy]\n")
  30. return 2
  31. if __name__ == "__main__":
  32. raise SystemExit(main())