From 72cfed6fc8daa026931f145c1ca3fa56c6962b27 Mon Sep 17 00:00:00 2001 From: partach Date: Thu, 30 Jul 2026 18:00:27 +0000 Subject: [PATCH] Fix: catch OSError/ConnectionError in Modbus service read path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The async_read_entity() method (service-call path) only caught ModbusIOException but client.read() can also raise OSError and ConnectionError on network failures. This caused unhandled exceptions when using the read_register service with unreachable devices. The bulk-read path (_auto_detect_type, _direct_read) already handled these correctly — only the service path was missed. https://claude.ai/code/session_0141XkQRjcng4RKLD4Yv5FAr --- .../protocol_wizard/protocols/modbus/coordinator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/custom_components/protocol_wizard/protocols/modbus/coordinator.py b/custom_components/protocol_wizard/protocols/modbus/coordinator.py index 96fb511..d40105f 100644 --- a/custom_components/protocol_wizard/protocols/modbus/coordinator.py +++ b/custom_components/protocol_wizard/protocols/modbus/coordinator.py @@ -425,10 +425,10 @@ async def async_read_entity(self, address: str, entity_config: dict, **kwargs) - values = test_values detected_type = test_type break - except ModbusIOException: + except (ModbusIOException, OSError, ConnectionError): continue # Try next type - except ModbusIOException as err: + except (ModbusIOException, OSError, ConnectionError) as err: _LOGGER.warning("[Modbus] I/O error reading address %s: %s - will attempt reconnect on next request", address, err) # Connection will be recovered on next _async_connect call return None