Skip to content

Commit 395c3fd

Browse files
authored
v1.0.3
Enhance logging control in Modbus communication: adjust suppression logic based on debug level
2 parents 82b3457 + 543e53b commit 395c3fd

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

custom_components/sigen/config_flow.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ async def async_dhcp_check_device_types(self, host, port=DEFAULT_PORT, timeout=1
383383
client = AsyncModbusTcpClient(host=host, port=port, timeout=timeout)
384384

385385
try:
386-
with _suppress_pymodbus_logging():
386+
with _suppress_pymodbus_logging(really_suppress= False if _LOGGER.isEnabledFor(logging.DEBUG) else True):
387387
if not await client.connect():
388388
_LOGGER.debug("Modbus connection failed to %s:%s", host, port)
389389
return False
@@ -582,7 +582,7 @@ async def _async_try_read_register(self, client: AsyncModbusTcpClient, slave_id:
582582
host = client.comm_params.host
583583
port = client.comm_params.port
584584

585-
with _suppress_pymodbus_logging():
585+
with _suppress_pymodbus_logging(really_suppress= False if _LOGGER.isEnabledFor(logging.DEBUG) else True):
586586
if not await client.connect():
587587
err = ("Modbus connection failed to %s:%s" % (host, port))
588588
_LOGGER.debug(err)
@@ -625,7 +625,7 @@ async def async_check_device_type(self, host, port, slave_id, timeout=1) -> str:
625625
client = AsyncModbusTcpClient(host=host, port=port, timeout=timeout)
626626

627627
try:
628-
with _suppress_pymodbus_logging():
628+
with _suppress_pymodbus_logging(really_suppress= False if _LOGGER.isEnabledFor(logging.DEBUG) else True):
629629
if not await client.connect():
630630
_LOGGER.debug("Modbus connection failed to %s:%s", host, port)
631631
return DEVICE_TYPE_UNKNOWN # Cannot determine type if connection fails

custom_components/sigen/manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"loggers": ["custom_components.sigen"],
2222
"quality_scale": "custom",
2323
"requirements": ["pymodbus>=3.0.0"],
24-
"version": "1.0.2"
24+
"version": "1.0.3"
2525
}

custom_components/sigen/modbus.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ async def _probe_single_register(
248248
) -> Tuple[str, bool, Optional[Exception]]:
249249
"""Probe a single register and return its name, support status, and any exception."""
250250

251-
with _suppress_pymodbus_logging(really_suppress=True):
251+
with _suppress_pymodbus_logging(really_suppress= False if _LOGGER.isEnabledFor(logging.DEBUG) else True):
252252
if register.register_type == RegisterType.READ_ONLY:
253253
result = await client.read_input_registers(
254254
address=register.address,
@@ -401,7 +401,7 @@ async def async_read_registers(
401401
key = self._get_connection_key(device_info)
402402

403403
async with self._locks[key]:
404-
with _suppress_pymodbus_logging():
404+
with _suppress_pymodbus_logging(really_suppress= False if _LOGGER.isEnabledFor(logging.DEBUG) else True):
405405
result = await client.read_input_registers(
406406
address=address, count=count, slave=slave_id
407407
) if register_type == RegisterType.READ_ONLY \

0 commit comments

Comments
 (0)