mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Fix Seerr request media action crashing when nothing is left to request (#192284)
This commit is contained in:
@@ -11,5 +11,5 @@
|
||||
"integration_type": "service",
|
||||
"iot_class": "local_push",
|
||||
"quality_scale": "platinum",
|
||||
"requirements": ["python-overseerr==0.10.0"]
|
||||
"requirements": ["python-overseerr==0.10.1"]
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ from typing import Any, Literal, cast
|
||||
|
||||
import probatio
|
||||
from python_overseerr import OverseerrClient, OverseerrConnectionError
|
||||
from python_overseerr.exceptions import OverseerrNothingToRequestError
|
||||
|
||||
from homeassistant.const import CommonServiceArgument
|
||||
from homeassistant.core import (
|
||||
@@ -16,7 +17,7 @@ from homeassistant.core import (
|
||||
SupportsResponse,
|
||||
callback,
|
||||
)
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers import service
|
||||
from homeassistant.util.json import JsonValueType
|
||||
|
||||
@@ -185,6 +186,11 @@ async def _async_request_media(call: ServiceCall) -> ServiceResponse:
|
||||
try:
|
||||
# We can always pass in the seasons, they will be ignored if the media type isn't TV
|
||||
request = await client.create_request(media_type, media_id, seasons)
|
||||
except OverseerrNothingToRequestError as err:
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="nothing_to_request",
|
||||
) from err
|
||||
except OverseerrConnectionError as err:
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
|
||||
@@ -113,6 +113,9 @@
|
||||
},
|
||||
"connection_error": {
|
||||
"message": "Error connecting to the Seerr instance: {error}"
|
||||
},
|
||||
"nothing_to_request": {
|
||||
"message": "There is nothing left to request, the media has already been requested or is already available."
|
||||
}
|
||||
},
|
||||
"selector": {
|
||||
|
||||
Generated
+1
-1
@@ -2858,7 +2858,7 @@ python-opensky==1.0.1
|
||||
python-otbr-api==3.1.0
|
||||
|
||||
# homeassistant.components.overseerr
|
||||
python-overseerr==0.10.0
|
||||
python-overseerr==0.10.1
|
||||
|
||||
# homeassistant.components.picnic
|
||||
python-picnic-api2==2.0.1
|
||||
|
||||
@@ -6,6 +6,7 @@ from unittest.mock import AsyncMock
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry
|
||||
from python_overseerr import OverseerrConnectionError
|
||||
from python_overseerr.exceptions import OverseerrNothingToRequestError
|
||||
from python_overseerr.models import MediaType
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
@@ -165,6 +166,18 @@ async def test_service_request_media(
|
||||
HomeAssistantError,
|
||||
"Error connecting to the Seerr instance: Timeout",
|
||||
),
|
||||
(
|
||||
OverseerrService.REQUEST_MEDIA,
|
||||
{
|
||||
OverseerrServiceArgument.MEDIA_TYPE: "tv",
|
||||
OverseerrServiceArgument.MEDIA_ID: "123456789",
|
||||
OverseerrServiceArgument.SEASONS: "all",
|
||||
},
|
||||
"create_request",
|
||||
OverseerrNothingToRequestError("No seasons available to request"),
|
||||
ServiceValidationError,
|
||||
"There is nothing left to request",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_services_connection_error(
|
||||
|
||||
Reference in New Issue
Block a user