Allow unlimited scan_interval in modbus (#51471)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
pull/51494/head
jan iversen 2021-06-04 18:06:44 +02:00 committed by GitHub
parent e41e153220
commit 5e067c2631
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 13 deletions

View File

@ -90,7 +90,6 @@ SERVICE_WRITE_REGISTER = "write_register"
# integration names
DEFAULT_HUB = "modbus_hub"
MINIMUM_SCAN_INTERVAL = 5 # seconds
DEFAULT_SCAN_INTERVAL = 15 # seconds
DEFAULT_SLAVE = 1
DEFAULT_STRUCTURE_PREFIX = ">f"

View File

@ -26,7 +26,6 @@ from .const import (
DATA_TYPE_STRING,
DEFAULT_SCAN_INTERVAL,
DEFAULT_STRUCT_FORMAT,
MINIMUM_SCAN_INTERVAL,
PLATFORMS,
)
@ -127,25 +126,28 @@ def scan_interval_validator(config: dict) -> dict:
for entry in hub[conf_key]:
scan_interval = entry.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
if scan_interval < MINIMUM_SCAN_INTERVAL:
if scan_interval == 0:
continue
if scan_interval == 0:
continue
if scan_interval < 5:
_LOGGER.warning(
"%s %s scan_interval(%d) is adjusted to minimum(%d)",
"%s %s scan_interval(%d) is lower than 5 seconds, "
"which may cause Home Assistant stability issues",
component,
entry.get(CONF_NAME),
scan_interval,
MINIMUM_SCAN_INTERVAL,
)
scan_interval = MINIMUM_SCAN_INTERVAL
entry[CONF_SCAN_INTERVAL] = scan_interval
minimum_scan_interval = min(scan_interval, minimum_scan_interval)
if CONF_TIMEOUT in hub and hub[CONF_TIMEOUT] > minimum_scan_interval - 1:
if (
CONF_TIMEOUT in hub
and hub[CONF_TIMEOUT] > minimum_scan_interval - 1
and minimum_scan_interval > 1
):
_LOGGER.warning(
"Modbus %s timeout(%d) is adjusted(%d) due to scan_interval",
hub.get(CONF_NAME, ""),
hub[CONF_TIMEOUT],
minimum_scan_interval - 1,
)
hub[CONF_TIMEOUT] = minimum_scan_interval - 1
hub[CONF_TIMEOUT] = minimum_scan_interval - 1
return config

View File

@ -457,9 +457,9 @@ async def mock_modbus_read_pymodbus(
@pytest.mark.parametrize(
"do_domain, do_group,do_type,do_scan_interval",
[
[SENSOR_DOMAIN, CONF_SENSORS, CALL_TYPE_REGISTER_HOLDING, 1],
[SENSOR_DOMAIN, CONF_SENSORS, CALL_TYPE_REGISTER_INPUT, 1],
[BINARY_SENSOR_DOMAIN, CONF_BINARY_SENSORS, CALL_TYPE_DISCRETE, 1],
[SENSOR_DOMAIN, CONF_SENSORS, CALL_TYPE_REGISTER_HOLDING, 10],
[SENSOR_DOMAIN, CONF_SENSORS, CALL_TYPE_REGISTER_INPUT, 10],
[BINARY_SENSOR_DOMAIN, CONF_BINARY_SENSORS, CALL_TYPE_DISCRETE, 10],
[BINARY_SENSOR_DOMAIN, CONF_BINARY_SENSORS, CALL_TYPE_COIL, 1],
],
)