diff --git a/homeassistant/components/modbus/modbus.py b/homeassistant/components/modbus/modbus.py index 92609f5e891..c2e39542077 100644 --- a/homeassistant/components/modbus/modbus.py +++ b/homeassistant/components/modbus/modbus.py @@ -242,7 +242,7 @@ class ModbusHub: self._msg_wait = 0 def _log_error(self, text: str, error_state=True): - log_text = f"Pymodbus: {text}" + log_text = f"Pymodbus: {self.name}: {text}" if self._in_error: _LOGGER.debug(log_text) else: diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index b24115ee964..1bb538a886a 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -593,6 +593,7 @@ async def test_pymodbus_constructor_fail(hass, caplog): config = { DOMAIN: [ { + CONF_NAME: TEST_MODBUS_NAME, CONF_TYPE: TCP, CONF_HOST: TEST_MODBUS_HOST, CONF_PORT: TEST_PORT_TCP, @@ -606,7 +607,8 @@ async def test_pymodbus_constructor_fail(hass, caplog): mock_pb.side_effect = ModbusException("test no class") assert await async_setup_component(hass, DOMAIN, config) is False await hass.async_block_till_done() - assert caplog.messages[0].startswith("Pymodbus: Modbus Error: test") + message = f"Pymodbus: {TEST_MODBUS_NAME}: Modbus Error: test" + assert caplog.messages[0].startswith(message) assert caplog.records[0].levelname == "ERROR" assert mock_pb.called