import asyncio from unittest.mock import AsyncMock from pm3py.core.protocol import Cmd from pm3py.core.transport import PM3Response from pm3py.core.hf import HFCommands def test_hf_tune(): t = AsyncMock() hf = HFCommands(t) # MEASURE (mode 2) returns the voltage as a uint16 mV; 15485 mV = 0x3C7D t.send_ng.return_value = PM3Response(cmd=Cmd.MEASURE_ANTENNA_TUNING_HF, status=0, reason=0, ng=True, data=b"\x7d\x3c") result = asyncio.get_event_loop().run_until_complete(hf.tune()) assert result["voltage_mV"] == 15485 assert result["voltage_V"] == 15.485 # Firmware requires the START(1)/MEASURE(2)/STOP(3) mode-byte sequence modes = [call.args[1] for call in t.send_ng.call_args_list] assert modes == [bytes([1]), bytes([2]), bytes([3])]