mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Add modbus name to log_error (#55336)
This commit is contained in:
parent
98c8782c2b
commit
7ac72ebf38
@ -242,7 +242,7 @@ class ModbusHub:
|
|||||||
self._msg_wait = 0
|
self._msg_wait = 0
|
||||||
|
|
||||||
def _log_error(self, text: str, error_state=True):
|
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:
|
if self._in_error:
|
||||||
_LOGGER.debug(log_text)
|
_LOGGER.debug(log_text)
|
||||||
else:
|
else:
|
||||||
|
@ -593,6 +593,7 @@ async def test_pymodbus_constructor_fail(hass, caplog):
|
|||||||
config = {
|
config = {
|
||||||
DOMAIN: [
|
DOMAIN: [
|
||||||
{
|
{
|
||||||
|
CONF_NAME: TEST_MODBUS_NAME,
|
||||||
CONF_TYPE: TCP,
|
CONF_TYPE: TCP,
|
||||||
CONF_HOST: TEST_MODBUS_HOST,
|
CONF_HOST: TEST_MODBUS_HOST,
|
||||||
CONF_PORT: TEST_PORT_TCP,
|
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")
|
mock_pb.side_effect = ModbusException("test no class")
|
||||||
assert await async_setup_component(hass, DOMAIN, config) is False
|
assert await async_setup_component(hass, DOMAIN, config) is False
|
||||||
await hass.async_block_till_done()
|
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 caplog.records[0].levelname == "ERROR"
|
||||||
assert mock_pb.called
|
assert mock_pb.called
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user