Make _LOGGER public in modbus (#177376)

This commit is contained in:
Martin
2026-07-27 15:08:00 +02:00
committed by GitHub
parent 890d330bd0
commit c476e6ea39
6 changed files with 16 additions and 16 deletions
@@ -21,11 +21,11 @@ from homeassistant.helpers.update_coordinator import (
from . import get_hub
from .const import (
_LOGGER,
CALL_TYPE_COIL,
CALL_TYPE_DISCRETE,
CONF_SLAVE_COUNT,
CONF_VIRTUAL_COUNT,
LOGGER,
)
from .entity import ModbusBaseEntity
from .modbus import ModbusHub
@@ -84,7 +84,7 @@ class ModbusBinarySensor(ModbusBaseEntity, RestoreEntity, BinarySensorEntity):
name = self._attr_name or "modbus_sensor"
self._coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
LOGGER,
config_entry=None,
name=name,
)
+2 -2
View File
@@ -42,7 +42,6 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from . import get_hub
from .const import (
_LOGGER,
CALL_TYPE_COIL,
CALL_TYPE_REGISTER_HOLDING,
CALL_TYPE_WRITE_COIL,
@@ -104,6 +103,7 @@ from .const import (
CONF_WRITE_REGISTERS,
DEFAULT_OFFSET,
DEFAULT_SCALE,
LOGGER,
DataType,
)
from .entity import ModbusStructEntity
@@ -584,7 +584,7 @@ class ModbusThermostat(ModbusStructEntity, RestoreEntity, ClimateEntity):
f"{self.name}: No answer received from"
" Swing mode register. State is Unknown"
)
_LOGGER.error(_err)
LOGGER.error(_err)
# Read the on/off register if defined. If the value in this
# register is "OFF", it will take precedence over the value
+1 -1
View File
@@ -188,4 +188,4 @@ LIGHT_MODBUS_INVALID_VALUE = 0xFFFF
DEFAULT_SCALE = 1.0
DEFAULT_OFFSET = 0
_LOGGER = logging.getLogger(__package__)
LOGGER = logging.getLogger(__package__)
+4 -4
View File
@@ -29,7 +29,6 @@ from homeassistant.helpers.event import async_call_later
from homeassistant.helpers.restore_state import RestoreEntity
from .const import (
_LOGGER,
CALL_TYPE_COIL,
CALL_TYPE_DISCRETE,
CALL_TYPE_REGISTER_HOLDING,
@@ -60,6 +59,7 @@ from .const import (
CONF_ZERO_SUPPRESS,
DEFAULT_OFFSET,
DEFAULT_SCALE,
LOGGER,
SIGNAL_STOP_ENTITY,
DataType,
)
@@ -128,7 +128,7 @@ class ModbusBaseEntity(Entity):
@callback
def async_disable(self) -> None:
"""Remote stop entity."""
_LOGGER.info(f"hold entity {self._attr_name}")
LOGGER.info(f"hold entity {self._attr_name}")
if self._cancel_call:
self._cancel_call()
self._cancel_call = None
@@ -249,7 +249,7 @@ class ModbusStructEntity(ModbusBaseEntity, RestoreEntity):
except struct.error as err:
recv_size = len(registers) * 2
msg = f"Received {recv_size} bytes, unpack error {err}"
_LOGGER.error(msg)
LOGGER.error(msg)
return None
if len(val) > 1:
# Apply scale, precision, limits to floats and ints
@@ -382,7 +382,7 @@ class ModbusToggleEntity(ModbusBaseEntity, ToggleEntity, RestoreEntity):
elif value in self._state_off:
self._attr_is_on = False
elif value is not None:
_LOGGER.error(
LOGGER.error(
(
"Unexpected response from modbus device slave %s register %s,"
" got 0x%2x"
+5 -5
View File
@@ -33,7 +33,6 @@ from homeassistant.helpers.typing import ConfigType
from homeassistant.util.hass_dict import HassKey
from .const import (
_LOGGER,
ATTR_ADDRESS,
ATTR_HUB,
ATTR_SLAVE,
@@ -55,6 +54,7 @@ from .const import (
DEFAULT_HUB,
DEVICE_ID,
DOMAIN,
LOGGER,
PLATFORMS,
RTUOVERTCP,
SERIAL,
@@ -305,21 +305,21 @@ class ModbusHub:
return
self._last_log_error = text
log_text = f"Pymodbus: {self.name}: {text}"
_LOGGER.error(log_text)
LOGGER.error(log_text)
async def async_pb_connect(self) -> None:
"""Connect to device, async."""
while True:
try:
if await self._client.connect(): # type: ignore[union-attr]
_LOGGER.info(f"modbus {self.name} communication open")
LOGGER.info(f"modbus {self.name} communication open")
break
except ModbusException as exception_error:
self._log_error(
f"{self.name} connect failed, please check"
f" your configuration ({exception_error!s})"
)
_LOGGER.info(
LOGGER.info(
f"modbus {self.name} connect NOT a success !"
f" retrying in {PRIMARY_RECONNECT_DELAY} seconds"
)
@@ -368,7 +368,7 @@ class ModbusHub:
except ModbusException as exception_error:
self._log_error(str(exception_error))
self._client = None
_LOGGER.info(f"modbus {self.name} communication closed")
LOGGER.info(f"modbus {self.name} communication closed")
async def low_level_pb_call(
self, slave: int | None, address: int, value: int | list[int], use_call: str
+2 -2
View File
@@ -25,12 +25,12 @@ from homeassistant.helpers.update_coordinator import (
from . import get_hub
from .const import (
_LOGGER,
CONF_SCALE,
CONF_SLAVE_COUNT,
CONF_VIRTUAL_COUNT,
DEFAULT_OFFSET,
DEFAULT_SCALE,
LOGGER,
)
from .entity import ModbusStructEntity
from .modbus import ModbusHub
@@ -100,7 +100,7 @@ class ModbusRegisterSensor(ModbusStructEntity, RestoreSensor, SensorEntity):
name = self._attr_name or "modbus_sensor"
self._coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
LOGGER,
config_entry=None,
name=name,
)