Adjust hassio to not access DeviceEntry.config_entries (#181739)

This commit is contained in:
Erik Montnemery
2026-09-09 15:39:02 +02:00
committed by GitHub
parent b69a9a5310
commit 9147543bca
3 changed files with 10 additions and 27 deletions
+8 -22
View File
@@ -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",
@@ -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"
},
+2 -2
View File
@@ -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(