Set slave default to 0, as already documented in Modbus (#66921)

pull/66931/head
jan iversen 2022-02-20 11:56:38 +01:00 committed by GitHub
parent 6e5ae3e2e4
commit 4ca339c5b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 6 deletions

View File

@ -118,7 +118,7 @@ BASE_COMPONENT_SCHEMA = vol.Schema(
{
vol.Required(CONF_NAME): cv.string,
vol.Required(CONF_ADDRESS): cv.positive_int,
vol.Optional(CONF_SLAVE): cv.positive_int,
vol.Optional(CONF_SLAVE, default=0): cv.positive_int,
vol.Optional(
CONF_SCAN_INTERVAL, default=DEFAULT_SCAN_INTERVAL
): cv.positive_int,

View File

@ -209,8 +209,7 @@ 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])
if CONF_SLAVE in entry:
addr += "_" + str(entry[CONF_SLAVE])
addr += "_" + str(entry[CONF_SLAVE])
if addr in addresses:
err = f"Modbus {component}/{name} address {addr} is duplicate, second entry not loaded!"
_LOGGER.warning(err)

View File

@ -9,7 +9,7 @@ from pymodbus.exceptions import ModbusException
import pytest
from homeassistant.components.modbus.const import MODBUS_DOMAIN as DOMAIN, TCP
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_TYPE
from homeassistant.const import CONF_HOST, CONF_NAME, CONF_PORT, CONF_SLAVE, CONF_TYPE
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@ -82,9 +82,12 @@ async def mock_modbus_fixture(
):
"""Load integration modbus using mocked pymodbus."""
conf = copy.deepcopy(do_config)
if config_addon:
for key in conf.keys():
for key in conf.keys():
if config_addon:
conf[key][0].update(config_addon)
for entity in conf[key]:
if CONF_SLAVE not in entity:
entity[CONF_SLAVE] = 0
caplog.set_level(logging.WARNING)
config = {
DOMAIN: [

View File

@ -76,6 +76,7 @@ from homeassistant.const import (
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_SENSORS,
CONF_SLAVE,
CONF_STRUCTURE,
CONF_TIMEOUT,
CONF_TYPE,
@ -272,10 +273,12 @@ async def test_duplicate_modbus_validator(do_config):
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 117,
CONF_SLAVE: 0,
},
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 119,
CONF_SLAVE: 0,
},
],
}
@ -290,10 +293,12 @@ async def test_duplicate_modbus_validator(do_config):
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 117,
CONF_SLAVE: 0,
},
{
CONF_NAME: TEST_ENTITY_NAME + "2",
CONF_ADDRESS: 117,
CONF_SLAVE: 0,
},
],
}
@ -409,6 +414,7 @@ async def test_duplicate_entity_validator(do_config):
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 117,
CONF_SLAVE: 0,
CONF_SCAN_INTERVAL: 0,
}
],
@ -544,6 +550,7 @@ async def mock_modbus_read_pymodbus_fixture(
CONF_INPUT_TYPE: do_type,
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 51,
CONF_SLAVE: 0,
CONF_SCAN_INTERVAL: do_scan_interval,
}
],
@ -688,6 +695,7 @@ async def test_delay(hass, mock_pymodbus):
CONF_INPUT_TYPE: CALL_TYPE_COIL,
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 52,
CONF_SLAVE: 0,
CONF_SCAN_INTERVAL: set_scan_interval,
},
],
@ -736,6 +744,7 @@ async def test_delay(hass, mock_pymodbus):
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 117,
CONF_SLAVE: 0,
CONF_SCAN_INTERVAL: 0,
}
],
@ -759,6 +768,7 @@ async def test_shutdown(hass, caplog, mock_pymodbus, mock_modbus_with_pymodbus):
{
CONF_NAME: TEST_ENTITY_NAME,
CONF_ADDRESS: 51,
CONF_SLAVE: 0,
}
]
},