from __future__ import annotations import pytest from hth_sdk.thermal import ThermalHTH, decode_snapshot class Backend: def __init__(self): self.targets = [] self.stimuli = [] def set_target(self, temperature_c): self.targets.append(temperature_c) def get_snapshot_payload(self): return bytes(193) def run_stimulus(self, duration_seconds, ptc, front, rear): self.stimuli.append((duration_seconds, list(ptc), list(front), list(rear))) def test_target_stop_and_snapshot() -> None: backend = Backend() hth = ThermalHTH(backend) hth.set_target(70) hth.stop() assert backend.targets == [70, 0] assert hth.get_snapshot().decoded["bmc_raw"] == [0] * 24 def test_production_rejects_stimulus() -> None: with pytest.raises(NotImplementedError): ThermalHTH(Backend()).run_stimulus(1, [0] * 24, [0] * 4, [0] * 4) def test_identification_validates_and_runs_stimulus() -> None: backend = Backend() hth = ThermalHTH(backend, identification=True) hth.run_stimulus(2, [1] * 24, [20] * 4, [30] * 4) assert backend.stimuli[0][0] == 2 def test_snapshot_length_is_exact() -> None: with pytest.raises(ValueError): decode_snapshot(bytes(192))