diff --git a/homeassistant/components/overseerr/services.py b/homeassistant/components/overseerr/services.py index 3c7335de15b..7ccb5f882ac 100644 --- a/homeassistant/components/overseerr/services.py +++ b/homeassistant/components/overseerr/services.py @@ -6,7 +6,6 @@ from typing import Any, cast from python_overseerr import OverseerrClient, OverseerrConnectionError import voluptuous as vol -from homeassistant.config_entries import ConfigEntryState from homeassistant.const import ATTR_CONFIG_ENTRY_ID from homeassistant.core import ( HomeAssistant, @@ -15,7 +14,8 @@ from homeassistant.core import ( SupportsResponse, callback, ) -from homeassistant.exceptions import HomeAssistantError, ServiceValidationError +from homeassistant.exceptions import HomeAssistantError +from homeassistant.helpers import service from homeassistant.util.json import JsonValueType from .const import ATTR_REQUESTED_BY, ATTR_SORT_ORDER, ATTR_STATUS, DOMAIN, LOGGER @@ -34,23 +34,6 @@ SERVICE_GET_REQUESTS_SCHEMA = vol.Schema( ) -def _async_get_entry(hass: HomeAssistant, config_entry_id: str) -> OverseerrConfigEntry: - """Get the Overseerr config entry.""" - if not (entry := hass.config_entries.async_get_entry(config_entry_id)): - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="integration_not_found", - translation_placeholders={"target": DOMAIN}, - ) - if entry.state is not ConfigEntryState.LOADED: - raise ServiceValidationError( - translation_domain=DOMAIN, - translation_key="not_loaded", - translation_placeholders={"target": entry.title}, - ) - return cast(OverseerrConfigEntry, entry) - - async def _get_media( client: OverseerrClient, media_type: str, identifier: int ) -> dict[str, Any]: @@ -70,7 +53,9 @@ async def _get_media( async def _async_get_requests(call: ServiceCall) -> ServiceResponse: """Get requests made to Overseerr.""" - entry = _async_get_entry(call.hass, call.data[ATTR_CONFIG_ENTRY_ID]) + entry: OverseerrConfigEntry = service.async_get_config_entry( + call.hass, DOMAIN, call.data[ATTR_CONFIG_ENTRY_ID] + ) client = entry.runtime_data.client kwargs: dict[str, Any] = {} if status := call.data.get(ATTR_STATUS): diff --git a/homeassistant/components/overseerr/strings.json b/homeassistant/components/overseerr/strings.json index 4e8829f269f..39ef4f7481c 100644 --- a/homeassistant/components/overseerr/strings.json +++ b/homeassistant/components/overseerr/strings.json @@ -115,12 +115,6 @@ }, "connection_error": { "message": "Error connecting to the Overseerr instance: {error}" - }, - "integration_not_found": { - "message": "Integration \"{target}\" not found in registry." - }, - "not_loaded": { - "message": "{target} is not loaded." } }, "selector": { diff --git a/tests/components/overseerr/test_services.py b/tests/components/overseerr/test_services.py index f53c6a917cb..d719f768cbc 100644 --- a/tests/components/overseerr/test_services.py +++ b/tests/components/overseerr/test_services.py @@ -135,7 +135,7 @@ async def test_service_entry_availability( await hass.config_entries.async_setup(mock_config_entry.entry_id) await hass.async_block_till_done() - with pytest.raises(ServiceValidationError, match="Mock Title is not loaded"): + with pytest.raises(ServiceValidationError, match="service_config_entry_not_loaded"): await hass.services.async_call( DOMAIN, service, @@ -144,9 +144,7 @@ async def test_service_entry_availability( return_response=True, ) - with pytest.raises( - ServiceValidationError, match='Integration "overseerr" not found in registry' - ): + with pytest.raises(ServiceValidationError, match="service_config_entry_not_found"): await hass.services.async_call( DOMAIN, service,