diff --git a/homeassistant/components/modbus/__init__.py b/homeassistant/components/modbus/__init__.py index 875669e6dd7..85fba66b68a 100644 --- a/homeassistant/components/modbus/__init__.py +++ b/homeassistant/components/modbus/__init__.py @@ -344,7 +344,7 @@ MODBUS_SCHEMA = vol.Schema( vol.Optional(CONF_CLOSE_COMM_ON_ERROR): 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_RETRY_ON_EMPTY): cv.boolean, vol.Optional(CONF_MSG_WAIT): cv.positive_int, vol.Optional(CONF_BINARY_SENSORS): vol.All( cv.ensure_list, [BINARY_SENSOR_SCHEMA] diff --git a/homeassistant/components/modbus/modbus.py b/homeassistant/components/modbus/modbus.py index db8a4d47fdc..4ef205aace3 100644 --- a/homeassistant/components/modbus/modbus.py +++ b/homeassistant/components/modbus/modbus.py @@ -276,7 +276,25 @@ class ModbusHub: }, ) _LOGGER.warning( - "`close_comm_on_error`: is deprecated and will be remove in version 2024.4" + "`close_comm_on_error`: is deprecated and will be removed in version 2024.4" + ) + if CONF_RETRY_ON_EMPTY in client_config: + async_create_issue( + hass, + DOMAIN, + "deprecated_retry_on_empty", + breaks_in_ha_version="2024.4.0", + is_fixable=False, + severity=IssueSeverity.WARNING, + translation_key="deprecated_retry_on_empty", + translation_placeholders={ + "config_key": "retry_on_empty", + "integration": DOMAIN, + "url": "https://www.home-assistant.io/integrations/modbus", + }, + ) + _LOGGER.warning( + "`retry_on_empty`: is deprecated and will be removed in version 2024.4" ) # generic configuration self._client: ModbusBaseClient | None = None @@ -298,7 +316,7 @@ class ModbusHub: "port": client_config[CONF_PORT], "timeout": client_config[CONF_TIMEOUT], "retries": client_config[CONF_RETRIES], - "retry_on_empty": client_config[CONF_RETRY_ON_EMPTY], + "retry_on_empty": True, } if self._config_type == SERIAL: # serial configuration diff --git a/homeassistant/components/modbus/strings.json b/homeassistant/components/modbus/strings.json index 780757a3eeb..5f45d0df596 100644 --- a/homeassistant/components/modbus/strings.json +++ b/homeassistant/components/modbus/strings.json @@ -73,6 +73,10 @@ "deprecated_close_comm_config": { "title": "`{config_key}` configuration key is being removed", "description": "Please remove the `{config_key}` key from the {integration} entry in your configuration.yaml file and restart Home Assistant to fix this issue.\n\nCommunication is automatically closed on errors, see [the documentation]({url}) for other error handling parameters." + }, + "deprecated_retry_on_empty": { + "title": "`{config_key}` configuration key is being removed", + "description": "Please remove the `{config_key}` key from the {integration} entry in your configuration.yaml file and restart Home Assistant to fix this issue.\n\nRetry on empty is automatically applied, see [the documentation]({url}) for other error handling parameters." } } } diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index 5f8c0554e6d..e66115f24d9 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -46,6 +46,7 @@ from homeassistant.components.modbus.const import ( CONF_INPUT_TYPE, CONF_MSG_WAIT, CONF_PARITY, + CONF_RETRY_ON_EMPTY, CONF_SLAVE_COUNT, CONF_STOPBITS, CONF_SWAP, @@ -420,6 +421,12 @@ async def test_duplicate_entity_validator(do_config) -> None: CONF_PORT: TEST_PORT_TCP, CONF_CLOSE_COMM_ON_ERROR: True, }, + { + CONF_TYPE: TCP, + CONF_HOST: TEST_MODBUS_HOST, + CONF_PORT: TEST_PORT_TCP, + CONF_RETRY_ON_EMPTY: True, + }, { CONF_TYPE: TCP, CONF_HOST: TEST_MODBUS_HOST,