mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add parameter to delay sending of requests in modbus (#54203)
This commit is contained in:
parent
d3007c26b3
commit
2232915ea8
@ -66,6 +66,7 @@ from .const import (
|
||||
CONF_INPUT_TYPE,
|
||||
CONF_MAX_TEMP,
|
||||
CONF_MIN_TEMP,
|
||||
CONF_MSG_WAIT,
|
||||
CONF_PARITY,
|
||||
CONF_PRECISION,
|
||||
CONF_RETRIES,
|
||||
@ -283,6 +284,7 @@ MODBUS_SCHEMA = vol.Schema(
|
||||
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_MSG_WAIT): cv.positive_int,
|
||||
vol.Optional(CONF_BINARY_SENSORS): vol.All(
|
||||
cv.ensure_list, [BINARY_SENSOR_SCHEMA]
|
||||
),
|
||||
|
@ -30,6 +30,7 @@ CONF_INPUTS = "inputs"
|
||||
CONF_INPUT_TYPE = "input_type"
|
||||
CONF_MAX_TEMP = "max_temp"
|
||||
CONF_MIN_TEMP = "min_temp"
|
||||
CONF_MSG_WAIT = "message_wait_milliseconds"
|
||||
CONF_PARITY = "parity"
|
||||
CONF_REGISTER = "register"
|
||||
CONF_REGISTER_TYPE = "register_type"
|
||||
|
@ -39,6 +39,7 @@ from .const import (
|
||||
CONF_BAUDRATE,
|
||||
CONF_BYTESIZE,
|
||||
CONF_CLOSE_COMM_ON_ERROR,
|
||||
CONF_MSG_WAIT,
|
||||
CONF_PARITY,
|
||||
CONF_RETRIES,
|
||||
CONF_RETRY_ON_EMPTY,
|
||||
@ -227,6 +228,12 @@ class ModbusHub:
|
||||
self._pb_params["framer"] = ModbusRtuFramer
|
||||
|
||||
Defaults.Timeout = client_config[CONF_TIMEOUT]
|
||||
if CONF_MSG_WAIT in client_config:
|
||||
self._msg_wait = client_config[CONF_MSG_WAIT] / 1000
|
||||
elif self._config_type == CONF_SERIAL:
|
||||
self._msg_wait = 30 / 1000
|
||||
else:
|
||||
self._msg_wait = 0
|
||||
|
||||
def _log_error(self, text: str, error_state=True):
|
||||
log_text = f"Pymodbus: {text}"
|
||||
@ -322,7 +329,7 @@ class ModbusHub:
|
||||
result = await self.hass.async_add_executor_job(
|
||||
self._pymodbus_call, unit, address, value, use_call
|
||||
)
|
||||
if self._config_type == "serial":
|
||||
if self._msg_wait:
|
||||
# small delay until next request/response
|
||||
await asyncio.sleep(30 / 1000)
|
||||
await asyncio.sleep(self._msg_wait)
|
||||
return result
|
||||
|
@ -40,6 +40,7 @@ from homeassistant.components.modbus.const import (
|
||||
CONF_BYTESIZE,
|
||||
CONF_DATA_TYPE,
|
||||
CONF_INPUT_TYPE,
|
||||
CONF_MSG_WAIT,
|
||||
CONF_PARITY,
|
||||
CONF_STOPBITS,
|
||||
CONF_SWAP,
|
||||
@ -245,6 +246,7 @@ async def test_exception_struct_validator(do_config):
|
||||
CONF_PORT: "usb01",
|
||||
CONF_PARITY: "E",
|
||||
CONF_STOPBITS: 1,
|
||||
CONF_MSG_WAIT: 100,
|
||||
},
|
||||
{
|
||||
CONF_TYPE: "serial",
|
||||
|
Loading…
x
Reference in New Issue
Block a user