8000 Set slave default to 0, as already documented in Modbus by janiversen · Pull Request #66921 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/modbus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
{
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,
Expand Down
3 changes: 1 addition & 2 deletions homeassistant/components/modbus/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions tests/components/modbus/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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

Expand Down Expand Up @@ -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: [
Expand Down
10 changes: 10 additions & 0 deletions tests/components/modbus/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
CONF_PORT,
CONF_SCAN_INTERVAL,
CONF_SENSORS,
CONF_SLAVE,
CONF_STRUCTURE,
CONF_TIMEOUT,
CONF_TYPE,
Expand Down Expand Up @@ -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,
},
],
}
Expand All @@ -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,
},
],
}
Expand Down Expand Up @@ -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,
}
],
Expand Down Expand Up @@ -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,
}
],
Expand Down Expand Up @@ -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,
},
],
Expand Down Expand Up @@ -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,
}
],
Expand All @@ -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,
}
]
},
Expand Down
0