From aa4107cee60aa30622074d0eb48375e7eb7c223f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Thu, 3 Sep 2026 23:57:17 +0200 Subject: [PATCH] Derive both raw swap oracles from one helper --- tests/integration/test_uart_mock_modbus.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_uart_mock_modbus.py b/tests/integration/test_uart_mock_modbus.py index d961ba8e22..36aa9a9668 100644 --- a/tests/integration/test_uart_mock_modbus.py +++ b/tests/integration/test_uart_mock_modbus.py @@ -26,8 +26,14 @@ import pytest from .state_utils import SensorTracker, find_entity, require_entity, wait_for_state from .types import APIClientConnectedFactory, RunCompiledFunction -# Byte-swapped raw U_WORD view of reg_u_word_s (0x1234 -> 0x3412) -MESH_RAW_U_WORD_S = 13330 + +def _swap16(value: int) -> int: + """Byte-swapped view of a 16-bit register as the raw U_WORD wire value.""" + return ((value & 0xFF) << 8) | (value >> 8) + + +# Raw U_WORD view of reg_u_word_s's initial 0x1234 +MESH_RAW_U_WORD_S = _swap16(4660) # Initial values of the mesh fixture's address 1 registers; the # server_controller test reads them and the write test uses them as baseline. @@ -384,7 +390,7 @@ async def test_uart_mock_modbus_server_controller_write( name: pytest.approx(value, abs=0.01) if isinstance(value, float) else value for name, (_, value) in register_writes.items() } - | {"reg_u_word_s_raw": 8515} # 0x4321 -> 0x2143 + | {"reg_u_word_s_raw": _swap16(register_writes["reg_u_word_s"][1])} ) async with (