Handle relation between scan_interval and pymodbus timeout in modbus (#50363)
* Control scan_interval compared to pymodbus timeout. add MINIMUM_SCAN_INTERVAL=5 seconds and validata with Voluptous. Keep modbus.py 100% coverage. * Please pylint. * Review comments. * pylint.
This commit is contained in:
parent
9ae021a284
commit
70b09ed9a1
4 changed files with 70 additions and 29 deletions
|
@ -8,15 +8,11 @@ from pymodbus.exceptions import ModbusException
|
|||
from pymodbus.transaction import ModbusRtuFramer
|
||||
|
||||
from homeassistant.const import (
|
||||
CONF_BINARY_SENSORS,
|
||||
CONF_COVERS,
|
||||
CONF_DELAY,
|
||||
CONF_HOST,
|
||||
CONF_METHOD,
|
||||
CONF_NAME,
|
||||
CONF_PORT,
|
||||
CONF_SENSORS,
|
||||
CONF_SWITCHES,
|
||||
CONF_TIMEOUT,
|
||||
CONF_TYPE,
|
||||
EVENT_HOMEASSISTANT_STOP,
|
||||
|
@ -31,17 +27,12 @@ from .const import (
|
|||
ATTR_UNIT,
|
||||
ATTR_VALUE,
|
||||
CONF_BAUDRATE,
|
||||
CONF_BINARY_SENSOR,
|
||||
CONF_BYTESIZE,
|
||||
CONF_CLIMATE,
|
||||
CONF_CLIMATES,
|
||||
CONF_COVER,
|
||||
CONF_PARITY,
|
||||
CONF_SENSOR,
|
||||
CONF_STOPBITS,
|
||||
CONF_SWITCH,
|
||||
DEFAULT_HUB,
|
||||
MODBUS_DOMAIN as DOMAIN,
|
||||
PLATFORMS,
|
||||
SERVICE_WRITE_COIL,
|
||||
SERVICE_WRITE_REGISTER,
|
||||
)
|
||||
|
@ -63,13 +54,7 @@ def modbus_setup(
|
|||
hub_collect[conf_hub[CONF_NAME]].setup(hass)
|
||||
|
||||
# load platforms
|
||||
for component, conf_key in (
|
||||
(CONF_CLIMATE, CONF_CLIMATES),
|
||||
(CONF_COVER, CONF_COVERS),
|
||||
(CONF_BINARY_SENSOR, CONF_BINARY_SENSORS),
|
||||
(CONF_SENSOR, CONF_SENSORS),
|
||||
(CONF_SWITCH, CONF_SWITCHES),
|
||||
):
|
||||
for component, conf_key in PLATFORMS:
|
||||
if conf_key in conf_hub:
|
||||
load_platform(hass, component, DOMAIN, conf_hub, config)
|
||||
|
||||
|
@ -140,8 +125,7 @@ class ModbusHub:
|
|||
self._config_port = client_config[CONF_PORT]
|
||||
self._config_timeout = client_config[CONF_TIMEOUT]
|
||||
self._config_delay = client_config[CONF_DELAY]
|
||||
|
||||
Defaults.Timeout = 10
|
||||
Defaults.Timeout = client_config[CONF_TIMEOUT]
|
||||
if self._config_type == "serial":
|
||||
# serial configuration
|
||||
self._config_method = client_config[CONF_METHOD]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue