88 GatewayTargetError ,
99 ModbusSerialParams ,
1010 ModbusTcpParams ,
11+ ModbusTimeoutError ,
1112 ModbusUdpParams ,
1213)
1314from modbus_connection .mock import MockModbusConnection
@@ -133,7 +134,7 @@ async def test_from_url_mock_unit(state: InverterState) -> None:
133134async def test_write_register_timeout (state : InverterState ) -> None :
134135 """Timeouts on write increment the counter and return False after retries."""
135136 unit = MagicMock ()
136- unit .write_registers = AsyncMock (side_effect = TimeoutError )
137+ unit .write_registers = AsyncMock (side_effect = ModbusTimeoutError )
137138 conn = MagicMock ()
138139 conn .connected = True
139140 conn .disconnect = AsyncMock ()
@@ -147,7 +148,7 @@ async def test_write_register_timeout(state: InverterState) -> None:
147148async def test_read_holding_registers_timeout (state : InverterState ) -> None :
148149 """Serial timeouts increment the counter, flush, retry, then raise ExceptionGroup."""
149150 unit = MagicMock ()
150- unit .read_holding_registers = AsyncMock (side_effect = TimeoutError )
151+ unit .read_holding_registers = AsyncMock (side_effect = ModbusTimeoutError )
151152 conn = MagicMock ()
152153 conn .connected = True
153154 conn .disconnect = AsyncMock ()
@@ -165,7 +166,7 @@ async def test_read_holding_registers_timeout_tcp_does_not_flush(
165166) -> None :
166167 """TCP timeouts still retry but leave the socket up."""
167168 unit = MagicMock ()
168- unit .read_holding_registers = AsyncMock (side_effect = TimeoutError )
169+ unit .read_holding_registers = AsyncMock (side_effect = ModbusTimeoutError )
169170 conn = MagicMock ()
170171 conn .connected = True
171172 conn .disconnect = AsyncMock ()
@@ -182,7 +183,7 @@ async def test_read_holding_registers_timeout_without_connection(
182183) -> None :
183184 """Solarman-style units have no ModbusConnection to flush."""
184185 unit = MagicMock ()
185- unit .read_holding_registers = AsyncMock (side_effect = TimeoutError )
186+ unit .read_holding_registers = AsyncMock (side_effect = ModbusTimeoutError )
186187 ss = Sunsynk (unit = unit , state = state )
187188 with pytest .raises (ExceptionGroup , match = "Failed to read" ):
188189 await ss .read_holding_registers (1 , 1 )
@@ -194,7 +195,7 @@ async def test_read_holding_registers_timeout_then_success(
194195) -> None :
195196 """A later attempt can still succeed after a timeout flush."""
196197 unit = MagicMock ()
197- unit .read_holding_registers = AsyncMock (side_effect = [TimeoutError , [9 , 8 ]])
198+ unit .read_holding_registers = AsyncMock (side_effect = [ModbusTimeoutError , [9 , 8 ]])
198199 conn = MagicMock ()
199200 conn .connected = True
200201 conn .disconnect = AsyncMock ()
@@ -208,7 +209,7 @@ async def test_read_holding_registers_timeout_then_success(
208209async def test_read_holding_registers_one_attempt (state : InverterState ) -> None :
209210 """read_attempts=1 raises after a single timeout."""
210211 unit = MagicMock ()
211- unit .read_holding_registers = AsyncMock (side_effect = TimeoutError )
212+ unit .read_holding_registers = AsyncMock (side_effect = ModbusTimeoutError )
212213 ss = Sunsynk (unit = unit , state = state , read_attempts = 1 )
213214 with pytest .raises (ExceptionGroup , match = "Failed to read" ):
214215 await ss .read_holding_registers (1 , 1 )
@@ -220,14 +221,14 @@ async def test_read_holding_registers_logs_empty_timeout(
220221 state : InverterState ,
221222 caplog : pytest .LogCaptureFixture ,
222223) -> None :
223- """Empty TimeoutError strings must still log the exception type."""
224+ """Empty ModbusTimeoutError strings must still log the exception type."""
224225 unit = MagicMock ()
225- unit .read_holding_registers = AsyncMock (side_effect = TimeoutError ())
226+ unit .read_holding_registers = AsyncMock (side_effect = ModbusTimeoutError ())
226227 ss = Sunsynk (unit = unit , state = state )
227228 with caplog .at_level (logging .ERROR ):
228229 with pytest .raises (ExceptionGroup ):
229230 await ss .read_holding_registers (0 , 8 )
230- assert "Read register 0 (count 8): TimeoutError " in caplog .text
231+ assert "Read register 0 x8: ModbusTimeoutError " in caplog .text
231232 assert "(retry" not in caplog .text
232233
233234
0 commit comments