diff --git a/homeassistant/components/kiosker/services.py b/homeassistant/components/kiosker/services.py index 2aece1ab65fe..7729aa107035 100644 --- a/homeassistant/components/kiosker/services.py +++ b/homeassistant/components/kiosker/services.py @@ -14,15 +14,10 @@ from kiosker import ( ) import voluptuous as vol -from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_DEVICE_ID, ATTR_ICON from homeassistant.core import HomeAssistant, ServiceCall, ServiceResponse, callback from homeassistant.exceptions import HomeAssistantError, ServiceValidationError -from homeassistant.helpers import ( - config_validation as cv, - device_registry as dr, - selector, -) +from homeassistant.helpers import config_validation as cv, selector, service from .const import ( ATTR_BACKGROUND, @@ -38,7 +33,7 @@ from .const import ( ATTR_VISIBLE, DOMAIN, ) -from .coordinator import KioskerDataUpdateCoordinator +from .coordinator import KioskerConfigEntry, KioskerDataUpdateCoordinator NAVIGATE_URL_SCHEMA = vol.Schema( { @@ -106,14 +101,10 @@ async def _get_coordinator( call: ServiceCall, ) -> KioskerDataUpdateCoordinator: """Get the coordinator for the targeted device.""" - device_id: str = call.data[ATTR_DEVICE_ID] - _, config_entry = dr.async_get_device_and_config_entry_for_domain( - call.hass, device_id, domain=DOMAIN + config_entry: KioskerConfigEntry + _, config_entry = service.async_get_device_and_config_entry( + call.hass, DOMAIN, call.data[ATTR_DEVICE_ID] ) - if config_entry is None: - raise ServiceValidationError(f"No {DOMAIN} devices found in targeted selection") - if config_entry.state is not ConfigEntryState.LOADED: - raise HomeAssistantError(f"{config_entry.title} is not loaded") return config_entry.runtime_data diff --git a/tests/components/kiosker/test_services.py b/tests/components/kiosker/test_services.py index 15a5ca752208..004ba5acd3f0 100644 --- a/tests/components/kiosker/test_services.py +++ b/tests/components/kiosker/test_services.py @@ -262,7 +262,9 @@ async def test_service_non_kiosker_device( identifiers={("other_domain", "other_device")}, ) - with pytest.raises(ServiceValidationError, match=f"No {DOMAIN} devices"): + with pytest.raises( + ServiceValidationError, match=f"does not belong to integration {DOMAIN}" + ): await hass.services.async_call( DOMAIN, "navigate_url",