Remove deprecated restart service in modbus (#128059)

This commit is contained in:
G Johansson 2024-10-10 17:30:50 +02:00 committed by GitHub
parent 5b7bd6a52f
commit 2ab5e5d267
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 91 deletions

View File

@ -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

View File

@ -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."
}
}
}

View File

@ -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."""