Skip to content

Commit

Permalink
Add modbus name to log_error (home-assistant#55336)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Aug 27, 2021
1 parent 98c8782 commit 7ac72eb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/modbus/modbus.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def __init__(self, hass, client_config):
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:
Expand Down
4 changes: 3 additions & 1 deletion tests/components/modbus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down

0 comments on commit 7ac72eb

Please sign in to comment.