From 2ab5e5d267d6efd0c2cbea8db946840e2624c095 Mon Sep 17 00:00:00 2001 From: G Johansson Date: Thu, 10 Oct 2024 17:30:50 +0200 Subject: [PATCH] Remove deprecated restart service in modbus (#128059) --- homeassistant/components/modbus/modbus.py | 37 +++---------- homeassistant/components/modbus/strings.json | 4 -- tests/components/modbus/test_init.py | 56 -------------------- 3 files changed, 6 insertions(+), 91 deletions(-) diff --git a/homeassistant/components/modbus/modbus.py b/homeassistant/components/modbus/modbus.py index cc70a783234..8f855addd47 100644 --- a/homeassistant/components/modbus/modbus.py +++ b/homeassistant/components/modbus/modbus.py @@ -34,7 +34,6 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.discovery import async_load_platform from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.reload import async_setup_reload_service from homeassistant.helpers.typing import ConfigType @@ -62,11 +61,9 @@ from .const import ( PLATFORMS, RTUOVERTCP, SERIAL, - SERVICE_RESTART, SERVICE_STOP, SERVICE_WRITE_COIL, SERVICE_WRITE_REGISTER, - SIGNAL_START_ENTITY, SIGNAL_STOP_ENTITY, TCP, UDP, @@ -233,34 +230,12 @@ async def async_modbus_setup( hub = hub_collect[service.data[ATTR_HUB]] await hub.async_close() - async def async_restart_hub(service: ServiceCall) -> None: - """Restart Modbus hub.""" - async_create_issue( - hass, - DOMAIN, - "deprecated_restart", - breaks_in_ha_version="2024.11.0", - is_fixable=False, - severity=IssueSeverity.WARNING, - translation_key="deprecated_restart", - ) - _LOGGER.warning( - "`modbus.restart` is deprecated and will be removed in version 2024.11" - ) - async_dispatcher_send(hass, SIGNAL_START_ENTITY) - hub = hub_collect[service.data[ATTR_HUB]] - await hub.async_restart() - - for x_service in ( - (SERVICE_STOP, async_stop_hub), - (SERVICE_RESTART, async_restart_hub), - ): - hass.services.async_register( - DOMAIN, - x_service[0], - x_service[1], - schema=vol.Schema({vol.Required(ATTR_HUB): cv.string}), - ) + hass.services.async_register( + DOMAIN, + SERVICE_STOP, + async_stop_hub, + schema=vol.Schema({vol.Required(ATTR_HUB): cv.string}), + ) return True diff --git a/homeassistant/components/modbus/strings.json b/homeassistant/components/modbus/strings.json index c0d702a9b89..7b55022645e 100644 --- a/homeassistant/components/modbus/strings.json +++ b/homeassistant/components/modbus/strings.json @@ -97,10 +97,6 @@ "no_entities": { "title": "Modbus {sub_1} contain no entities, entry not loaded.", "description": "Please add at least one entity to Modbus {sub_1} in your configuration.yaml file and restart Home Assistant to fix this issue." - }, - "deprecated_restart": { - "title": "modbus.restart is being removed", - "description": "Please use reload yaml via the developer tools in the UI instead of via the `modbus.restart` action." } } } diff --git a/tests/components/modbus/test_init.py b/tests/components/modbus/test_init.py index 70230e7d326..728c2c37ccd 100644 --- a/tests/components/modbus/test_init.py +++ b/tests/components/modbus/test_init.py @@ -68,7 +68,6 @@ from homeassistant.components.modbus.const import ( MODBUS_DOMAIN as DOMAIN, RTUOVERTCP, SERIAL, - SERVICE_RESTART, SERVICE_STOP, SERVICE_WRITE_COIL, SERVICE_WRITE_REGISTER, @@ -1149,61 +1148,6 @@ async def test_shutdown( assert caplog.text == "" -@pytest.mark.parametrize( - "do_config", - [ - { - CONF_SENSORS: [ - { - CONF_NAME: TEST_ENTITY_NAME, - CONF_ADDRESS: 51, - CONF_SLAVE: 0, - } - ] - }, - ], -) -async def test_stop_restart( - hass: HomeAssistant, caplog: pytest.LogCaptureFixture, mock_modbus -) -> None: - """Run test for service stop.""" - - caplog.set_level(logging.WARNING) - entity_id = f"{SENSOR_DOMAIN}.{TEST_ENTITY_NAME}".replace(" ", "_") - assert hass.states.get(entity_id).state in (STATE_UNKNOWN, STATE_UNAVAILABLE) - hass.states.async_set(entity_id, 17) - await hass.async_block_till_done() - assert hass.states.get(entity_id).state == "17" - - mock_modbus.reset_mock() - caplog.clear() - data = { - ATTR_HUB: TEST_MODBUS_NAME, - } - await hass.services.async_call(DOMAIN, SERVICE_STOP, data, blocking=True) - await hass.async_block_till_done() - assert hass.states.get(entity_id).state == STATE_UNAVAILABLE - assert mock_modbus.close.called - assert f"modbus {TEST_MODBUS_NAME} communication closed" in caplog.text - - mock_modbus.reset_mock() - caplog.clear() - await hass.services.async_call(DOMAIN, SERVICE_RESTART, data, blocking=True) - await hass.async_block_till_done() - assert not mock_modbus.close.called - assert mock_modbus.connect.called - assert f"modbus {TEST_MODBUS_NAME} communication open" in caplog.text - - mock_modbus.reset_mock() - caplog.clear() - await hass.services.async_call(DOMAIN, SERVICE_RESTART, data, blocking=True) - await hass.async_block_till_done() - assert mock_modbus.close.called - assert mock_modbus.connect.called - assert f"modbus {TEST_MODBUS_NAME} communication closed" in caplog.text - assert f"modbus {TEST_MODBUS_NAME} communication open" in caplog.text - - @pytest.mark.parametrize("do_config", [{}]) async def test_write_no_client(hass: HomeAssistant, mock_modbus) -> None: """Run test for service stop and write without client."""