Add retries/retry_on_empty configuration parameters to Modbus (#51412)

* Add retries/retry_on_empty configuration parameters.

* Please review comment.
This commit is contained in:
jan iversen 2021-06-06 09:13:50 +02:00 committed by GitHub
parent 6a419483de
commit 50001684aa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 1 deletions

View file

@ -66,6 +66,8 @@ from .const import (
CONF_MIN_TEMP,
CONF_PARITY,
CONF_PRECISION,
CONF_RETRIES,
CONF_RETRY_ON_EMPTY,
CONF_REVERSE_ORDER,
CONF_SCALE,
CONF_STATE_CLOSED,
@ -292,6 +294,8 @@ MODBUS_SCHEMA = vol.Schema(
vol.Optional(CONF_TIMEOUT, default=3): cv.socket_timeout,
vol.Optional(CONF_CLOSE_COMM_ON_ERROR, default=True): cv.boolean,
vol.Optional(CONF_DELAY, default=0): cv.positive_int,
vol.Optional(CONF_RETRIES, default=3): cv.positive_int,
vol.Optional(CONF_RETRY_ON_EMPTY, default=False): cv.boolean,
vol.Optional(CONF_BINARY_SENSORS): vol.All(
cv.ensure_list, [BINARY_SENSOR_SCHEMA]
),

View file

@ -35,6 +35,8 @@ CONF_PARITY = "parity"
CONF_REGISTER = "register"
CONF_REGISTER_TYPE = "register_type"
CONF_REGISTERS = "registers"
CONF_RETRIES = "retries"
CONF_RETRY_ON_EMPTY = "retry_on_empty"
CONF_REVERSE_ORDER = "reverse_order"
CONF_PRECISION = "precision"
CONF_SCALE = "scale"

View file

@ -39,6 +39,8 @@ from .const import (
CONF_BYTESIZE,
CONF_CLOSE_COMM_ON_ERROR,
CONF_PARITY,
CONF_RETRIES,
CONF_RETRY_ON_EMPTY,
CONF_STOPBITS,
DEFAULT_HUB,
MODBUS_DOMAIN as DOMAIN,
@ -149,6 +151,8 @@ class ModbusHub:
self._config_timeout = client_config[CONF_TIMEOUT]
self._config_delay = client_config[CONF_DELAY]
self._config_reset_socket = client_config[CONF_CLOSE_COMM_ON_ERROR]
self._config_retries = client_config[CONF_RETRIES]
self._config_retry_on_empty = client_config[CONF_RETRY_ON_EMPTY]
Defaults.Timeout = client_config[CONF_TIMEOUT]
if self._config_type == "serial":
# serial configuration
@ -216,7 +220,8 @@ class ModbusHub:
bytesize=self._config_bytesize,
parity=self._config_parity,
timeout=self._config_timeout,
retry_on_empty=True,
retries=self._config_retries,
retry_on_empty=self._config_retry_on_empty,
reset_socket=self._config_reset_socket,
)
elif self._config_type == "rtuovertcp":
@ -225,6 +230,8 @@ class ModbusHub:
port=self._config_port,
framer=ModbusRtuFramer,
timeout=self._config_timeout,
retries=self._config_retries,
retry_on_empty=self._config_retry_on_empty,
reset_socket=self._config_reset_socket,
)
elif self._config_type == "tcp":
@ -232,6 +239,8 @@ class ModbusHub:
host=self._config_host,
port=self._config_port,
timeout=self._config_timeout,
retries=self._config_retries,
retry_on_empty=self._config_retry_on_empty,
reset_socket=self._config_reset_socket,
)
elif self._config_type == "udp":
@ -239,6 +248,8 @@ class ModbusHub:
host=self._config_host,
port=self._config_port,
timeout=self._config_timeout,
retries=self._config_retries,
retry_on_empty=self._config_retry_on_empty,
reset_socket=self._config_reset_socket,
)
except ModbusException as exception_error: