test_proto_packing.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import annotations
  2. from hth_sdk.constants import API_VERSION
  3. from hth_sdk.profiles import prod2u
  4. from hth_sdk.stubs import stubs_available
  5. from hth_sdk.types import ActionBatch
  6. def test_unix_target_helper():
  7. from hth_sdk.client import unix_target
  8. assert unix_target("/run/hth/observe.sock") == "unix:///run/hth/observe.sock"
  9. assert unix_target("unix:///run/hth/control.sock") == "unix:///run/hth/control.sock"
  10. def test_batch_to_proto_if_stubs_exist():
  11. if not stubs_available():
  12. return
  13. from hth_sdk.proto_codec import batch_to_proto
  14. from hth_sdk.stubs import load_stubs
  15. pb2, _ = load_stubs()
  16. batch = (
  17. prod2u.builder("hood.0", allow_unverified=True)
  18. .command_id("p1")
  19. .lease("L", 1)
  20. .set_fan(1, 10)
  21. .set_door_close_percent("x", 0)
  22. .valid_for(__import__("datetime").timedelta(seconds=15))
  23. .build()
  24. )
  25. msg = batch_to_proto(pb2, batch)
  26. assert msg.device_id == "hood.0"
  27. assert msg.command_id == "p1"
  28. assert msg.lease_epoch == 1
  29. ids = [t.id for t in msg.continuous_targets]
  30. assert "fan.chamber.1" in ids
  31. assert "door.x.close_percent" in ids
  32. def test_api_version_constant_matches_proto_package():
  33. assert API_VERSION == "hth.api.v1"