diff --git a/homeassistant/components/hassio/services.py b/homeassistant/components/hassio/services.py index 17e73f56f25b..c029052be2a6 100644 --- a/homeassistant/components/hassio/services.py +++ b/homeassistant/components/hassio/services.py @@ -26,11 +26,13 @@ from homeassistant.core import ( from homeassistant.exceptions import HomeAssistantError, ServiceValidationError from homeassistant.helpers import ( config_validation as cv, - device_registry as dr, issue_registry as ir, selector, ) -from homeassistant.helpers.service import async_register_admin_service +from homeassistant.helpers.service import ( + async_get_device_and_config_entry, + async_register_admin_service, +) from homeassistant.util.dt import now from .const import ( @@ -47,10 +49,8 @@ from .const import ( ATTR_SLUG, DOMAIN, ISSUE_KEY_LEGACY_HOMEASSISTANT_FOLDER, - MAIN_COORDINATOR, SupervisorEntityModel, ) -from .coordinator import HassioMainDataUpdateCoordinator from .handler import get_supervisor_client SERVICE_ADDON_START = "addon_start" @@ -449,28 +449,14 @@ def async_register_network_storage_services( hass: HomeAssistant, supervisor_client: SupervisorClient ) -> None: """Register network storage (or mount) services.""" - dev_reg = dr.async_get(hass) async def async_mount_reload(service: ServiceCall) -> None: """Handle service calls for Hass.io.""" - coordinator: HassioMainDataUpdateCoordinator | None = None + device, _ = async_get_device_and_config_entry( + hass, DOMAIN, service.data[ATTR_DEVICE_ID] + ) - if ( - device := dev_reg.async_get( - service.data[ATTR_DEVICE_ID], include_child_devices=False - ) - ) is None: - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="mount_reload_unknown_device_id", - ) - - if ( - device.name is None - or device.model != SupervisorEntityModel.MOUNT - or (coordinator := hass.data.get(MAIN_COORDINATOR)) is None - or coordinator.entry_id not in device.config_entries - ): + if device.name is None or device.model != SupervisorEntityModel.MOUNT: raise ServiceValidationError( translation_domain=DOMAIN, translation_key="mount_reload_invalid_device", diff --git a/homeassistant/components/hassio/strings.json b/homeassistant/components/hassio/strings.json index 3b7f762c0638..5c8b89ecc696 100644 --- a/homeassistant/components/hassio/strings.json +++ b/homeassistant/components/hassio/strings.json @@ -50,9 +50,6 @@ "mount_reload_invalid_device": { "message": "Device is not a supervisor mount point" }, - "mount_reload_unknown_device_id": { - "message": "Device ID not found" - }, "supervisor_not_connected": { "message": "Not connected with the supervisor / system too busy" }, diff --git a/tests/components/hassio/test_init.py b/tests/components/hassio/test_init.py index e2adad92dcc9..858336aedd53 100644 --- a/tests/components/hassio/test_init.py +++ b/tests/components/hassio/test_init.py @@ -1723,7 +1723,7 @@ async def test_mount_reload_unknown_device_id( await hass.services.async_call( DOMAIN, "mount_reload", {"device_id": "1234"}, blocking=True ) - assert str(exc.value) == "Device ID not found" + assert str(exc.value) == "Device with ID 1234 was not found" async def test_mount_reload_no_name( @@ -1775,7 +1775,7 @@ async def test_mount_reload_not_supervisor_device( await hass.services.async_call( DOMAIN, "mount_reload", {"device_id": device2.id}, blocking=True ) - assert str(exc.value) == "Device is not a supervisor mount point" + assert str(exc.value) == "Device NAS does not belong to integration hassio" async def test_mount_reload_selector_matches_device_name(