Skip to content

Commit

Permalink
Add device_address to modbus configuration (home-assistant#100399)
Browse files Browse the repository at this point in the history
  • Loading branch information
janiversen authored Sep 15, 2023
1 parent 1737b27 commit c173ebd
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion homeassistant/components/modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
CONF_CLIMATES,
CONF_CLOSE_COMM_ON_ERROR,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_FANS,
CONF_HVAC_MODE_AUTO,
CONF_HVAC_MODE_COOL,
Expand Down Expand Up @@ -138,7 +139,8 @@
{
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_ADDRESS): cv.positive_int,
vol.Optional(CONF_SLAVE, default=0): cv.positive_int,
vol.Exclusive(CONF_DEVICE_ADDRESS, "slave_addr"): cv.positive_int,
vol.Exclusive(CONF_SLAVE, "slave_addr"): cv.positive_int,
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): cv.positive_int,
Expand Down
3 changes: 2 additions & 1 deletion homeassistant/components/modbus/base_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
CALL_TYPE_X_COILS,
CALL_TYPE_X_REGISTER_HOLDINGS,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_INPUT_TYPE,
CONF_LAZY_ERROR,
CONF_MAX_VALUE,
Expand Down Expand Up @@ -76,7 +77,7 @@ class BasePlatform(Entity):
def __init__(self, hub: ModbusHub, entry: dict[str, Any]) -> None:
"""Initialize the Modbus binary sensor."""
self._hub = hub
self._slave = entry.get(CONF_SLAVE, 0)
self._slave = entry.get(CONF_SLAVE, None) or entry.get(CONF_DEVICE_ADDRESS, 0)
self._address = int(entry[CONF_ADDRESS])
self._input_type = entry[CONF_INPUT_TYPE]
self._value: str | None = None
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/modbus/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
CONF_CLIMATES = "climates"
CONF_CLOSE_COMM_ON_ERROR = "close_comm_on_error"
CONF_DATA_TYPE = "data_type"
CONF_DEVICE_ADDRESS = "device_address"
CONF_FANS = "fans"
CONF_INPUT_TYPE = "input_type"
CONF_LAZY_ERROR = "lazy_error_count"
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/modbus/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from .const import (
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_INPUT_TYPE,
CONF_SLAVE_COUNT,
CONF_SWAP,
Expand Down Expand Up @@ -241,7 +242,8 @@ def duplicate_entity_validator(config: dict) -> dict:
addr += "_" + str(entry[CONF_COMMAND_ON])
if CONF_COMMAND_OFF in entry:
addr += "_" + str(entry[CONF_COMMAND_OFF])
addr += "_" + str(entry.get(CONF_SLAVE, 0))
inx = entry.get(CONF_SLAVE, None) or entry.get(CONF_DEVICE_ADDRESS, 0)
addr += "_" + str(inx)
if addr in addresses:
err = (
f"Modbus {component}/{name} address {addr} is duplicate, second"
Expand Down

0 comments on commit c173ebd

Please sign in to comment.