Add device_address to modbus configuration (#100399)

pull/100434/head
jan iversen 2023-09-15 13:49:33 +02:00 committed by GitHub
parent 1737b27dd4
commit c173ebd11a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -62,6 +62,7 @@ from .const import ( # noqa: F401
CONF_CLIMATES,
CONF_CLOSE_COMM_ON_ERROR,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_FANS,
CONF_HVAC_MODE_AUTO,
CONF_HVAC_MODE_COOL,
@ -138,7 +139,8 @@ BASE_COMPONENT_SCHEMA = vol.Schema(
{
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,

View File

@ -42,6 +42,7 @@ from .const import (
CALL_TYPE_X_COILS,
CALL_TYPE_X_REGISTER_HOLDINGS,
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_INPUT_TYPE,
CONF_LAZY_ERROR,
CONF_MAX_VALUE,
@ -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

View File

@ -17,6 +17,7 @@ CONF_BYTESIZE = "bytesize"
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"

View File

@ -25,6 +25,7 @@ from homeassistant.const import (
from .const import (
CONF_DATA_TYPE,
CONF_DEVICE_ADDRESS,
CONF_INPUT_TYPE,
CONF_SLAVE_COUNT,
CONF_SWAP,
@ -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"