| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- """Live UDS tests against a running hthd. Skipped unless HTH_OBSERVE_SOCK is set."""
- from __future__ import annotations
- import asyncio
- import os
- from datetime import timedelta
- import pytest
- from hth_sdk.client import connect
- from hth_sdk.profiles import prod2u
- pytestmark = pytest.mark.skipif(
- not os.environ.get("HTH_OBSERVE_SOCK"),
- reason="HTH_OBSERVE_SOCK not set",
- )
- async def _run() -> None:
- observe = os.environ["HTH_OBSERVE_SOCK"]
- control = os.environ.get("HTH_CONTROL_SOCK") or None
- role = "control" if control else "observe"
- async with await connect(observe=observe, control=control, role=role) as client:
- caps = await client.get_capabilities("prod2u-0")
- assert caps.api_version == "hth.api.v1"
- assert caps.ack_supported is False
- assert caps.position_feedback_supported is False
- snap = await client.get_snapshot("prod2u-0")
- assert snap.snapshot_seq >= 1
- n = 0
- async for s in client.subscribe_telemetry("prod2u-0"):
- n += 1
- if s.data_gap:
- assert s.dropped_count >= 1
- if n >= 2:
- break
- if control:
- async with await client.acquire_lease(
- "prod2u-0", "pytest-live", timedelta(seconds=5), auto_renew=False
- ) as lease:
- snap = await client.get_snapshot("prod2u-0")
- batch = (
- prod2u.builder("prod2u-0", capabilities=caps)
- .based_on(snap.snapshot_seq, snap.control_revision)
- .set_fan(1, 10)
- .set_ptc(1, 0)
- .set_door_close_percent("x", 0)
- .set_door_close_percent("y", 0)
- .set_door_close_percent("z", 0)
- .build()
- )
- res = await lease.apply(batch)
- assert res.confirmation != "CONFIRMED"
- def test_live_uds_mock_daemon() -> None:
- asyncio.run(_run())
|