Empty response returns empty list in Nord Pool (#145514)

This commit is contained in:
G Johansson 2025-05-26 14:25:07 +02:00 committed by GitHub
parent e22fbe553b
commit 970359c6a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 9 deletions

View File

@ -97,11 +97,8 @@ def async_setup_services(hass: HomeAssistant) -> None:
translation_domain=DOMAIN,
translation_key="authentication_error",
) from error
except NordPoolEmptyResponseError as error:
raise ServiceValidationError(
translation_domain=DOMAIN,
translation_key="empty_response",
) from error
except NordPoolEmptyResponseError:
return {area: [] for area in areas}
except NordPoolError as error:
raise ServiceValidationError(
translation_domain=DOMAIN,

View File

@ -129,9 +129,6 @@
"authentication_error": {
"message": "There was an authentication error as you tried to retrieve data too far in the past."
},
"empty_response": {
"message": "Nord Pool has not posted market prices for the provided date."
},
"connection_error": {
"message": "There was a connection error connecting to the API. Try again later."
}

View File

@ -1,4 +1,10 @@
# serializer version: 1
# name: test_empty_response_returns_empty_list
dict({
'SE3': list([
]),
})
# ---
# name: test_service_call
dict({
'SE3': list([

View File

@ -74,7 +74,6 @@ async def test_service_call(
("error", "key"),
[
(NordPoolAuthenticationError, "authentication_error"),
(NordPoolEmptyResponseError, "empty_response"),
(NordPoolError, "connection_error"),
],
)
@ -106,6 +105,33 @@ async def test_service_call_failures(
assert err.value.translation_key == key
@pytest.mark.freeze_time("2024-11-05T18:00:00+00:00")
async def test_empty_response_returns_empty_list(
hass: HomeAssistant,
load_int: MockConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test get_prices_for_date service call return empty list for empty response."""
service_data = TEST_SERVICE_DATA.copy()
service_data[ATTR_CONFIG_ENTRY] = load_int.entry_id
with (
patch(
"homeassistant.components.nordpool.coordinator.NordPoolClient.async_get_delivery_period",
side_effect=NordPoolEmptyResponseError,
),
):
response = await hass.services.async_call(
DOMAIN,
SERVICE_GET_PRICES_FOR_DATE,
service_data,
blocking=True,
return_response=True,
)
assert response == snapshot
@pytest.mark.freeze_time("2024-11-05T18:00:00+00:00")
async def test_service_call_config_entry_bad_state(
hass: HomeAssistant,