1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-14 23:28:42 +00:00

Use service helper to extract overseerr config entry (#162804)

This commit is contained in:
epenet
2026-02-11 15:36:34 +01:00
committed by GitHub
parent 842abf78d2
commit 305b911c0d
3 changed files with 7 additions and 30 deletions

View File

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

View File

@@ -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": {

View File

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