From e94348611ea9af9461831a59d805b921b6af950e Mon Sep 17 00:00:00 2001 From: partach Date: Thu, 30 Jul 2026 17:49:11 +0000 Subject: [PATCH] Fix: catch ModbusIOException in config flow connection test The BLE001 lint fix narrowed `except Exception` to specific types but missed ModbusIOException, which pymodbus raises on communication failures. This caused uncaught exceptions when testing serial Modbus connections with unresponsive devices. https://claude.ai/code/session_0141XkQRjcng4RKLD4Yv5FAr --- custom_components/protocol_wizard/config_flow.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/protocol_wizard/config_flow.py b/custom_components/protocol_wizard/config_flow.py index d94cac1..1522446 100644 --- a/custom_components/protocol_wizard/config_flow.py +++ b/custom_components/protocol_wizard/config_flow.py @@ -15,6 +15,7 @@ AsyncModbusTcpClient, AsyncModbusUdpClient, ) +from pymodbus.exceptions import ModbusIOException from .const import ( CONF_BAUDRATE, @@ -318,7 +319,7 @@ async def async_step_modbus_device(self, user_input: dict[str, Any] | None = Non }, ) - except (OSError, ConnectionError, TimeoutError): + except (ModbusIOException, OSError, ConnectionError, TimeoutError): _LOGGER.exception("Connection test failed") errors["base"] = "cannot_connect" @@ -435,7 +436,7 @@ async def _async_test_modbus_connection(self, data: dict[str, Any]) -> None: if not result.isError() and hasattr(result, "registers") and len(result.registers) == count: success = True break - except (OSError, ConnectionError, TimeoutError) as inner_err: + except (ModbusIOException, OSError, ConnectionError, TimeoutError) as inner_err: _LOGGER.debug("Test read failed for %s at addr %d: %s", name, address, inner_err) if not success: