Bump `nextdns` to version 3.1.0 (#120703)

Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
pull/120671/head^2
Maciej Bieniek 2024-06-27 23:12:20 +02:00 committed by GitHub
parent f3761a8e53
commit e764afecac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 39 additions and 20 deletions

View File

@ -18,6 +18,7 @@ from nextdns import (
NextDns,
Settings,
)
from tenacity import RetryError
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_API_KEY, Platform
@ -84,9 +85,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: NextDnsConfigEntry) -> b
websession = async_get_clientsession(hass)
try:
async with asyncio.timeout(10):
nextdns = await NextDns.create(websession, api_key)
except (ApiError, ClientConnectorError, TimeoutError) as err:
nextdns = await NextDns.create(websession, api_key)
except (ApiError, ClientConnectorError, RetryError, TimeoutError) as err:
raise ConfigEntryNotReady from err
tasks = []

View File

@ -2,11 +2,11 @@
from __future__ import annotations
import asyncio
from typing import Any
from aiohttp.client_exceptions import ClientConnectorError
from nextdns import ApiError, InvalidApiKeyError, NextDns
from tenacity import RetryError
import voluptuous as vol
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
@ -37,13 +37,12 @@ class NextDnsFlowHandler(ConfigFlow, domain=DOMAIN):
if user_input is not None:
self.api_key = user_input[CONF_API_KEY]
try:
async with asyncio.timeout(10):
self.nextdns = await NextDns.create(
websession, user_input[CONF_API_KEY]
)
self.nextdns = await NextDns.create(
websession, user_input[CONF_API_KEY]
)
except InvalidApiKeyError:
errors["base"] = "invalid_api_key"
except (ApiError, ClientConnectorError, TimeoutError):
except (ApiError, ClientConnectorError, RetryError, TimeoutError):
errors["base"] = "cannot_connect"
except Exception: # noqa: BLE001
errors["base"] = "unknown"

View File

@ -1,6 +1,5 @@
"""NextDns coordinator."""
import asyncio
from datetime import timedelta
import logging
from typing import TypeVar
@ -19,6 +18,7 @@ from nextdns import (
Settings,
)
from nextdns.model import NextDnsData
from tenacity import RetryError
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
@ -58,9 +58,13 @@ class NextDnsUpdateCoordinator(DataUpdateCoordinator[CoordinatorDataT]):
async def _async_update_data(self) -> CoordinatorDataT:
"""Update data via internal method."""
try:
async with asyncio.timeout(10):
return await self._async_update_data_internal()
except (ApiError, ClientConnectorError, InvalidApiKeyError) as err:
return await self._async_update_data_internal()
except (
ApiError,
ClientConnectorError,
InvalidApiKeyError,
RetryError,
) as err:
raise UpdateFailed(err) from err
async def _async_update_data_internal(self) -> CoordinatorDataT:

View File

@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"loggers": ["nextdns"],
"quality_scale": "platinum",
"requirements": ["nextdns==3.0.0"]
"requirements": ["nextdns==3.1.0"]
}

View File

@ -1404,7 +1404,7 @@ nextcloudmonitor==1.5.0
nextcord==2.6.0
# homeassistant.components.nextdns
nextdns==3.0.0
nextdns==3.1.0
# homeassistant.components.nibe_heatpump
nibe==2.8.0

View File

@ -1143,7 +1143,7 @@ nextcloudmonitor==1.5.0
nextcord==2.6.0
# homeassistant.components.nextdns
nextdns==3.0.0
nextdns==3.1.0
# homeassistant.components.nibe_heatpump
nibe==2.8.0

View File

@ -4,6 +4,7 @@ from unittest.mock import patch
from nextdns import ApiError, InvalidApiKeyError
import pytest
from tenacity import RetryError
from homeassistant.components.nextdns.const import CONF_PROFILE_ID, DOMAIN
from homeassistant.config_entries import SOURCE_USER
@ -57,6 +58,7 @@ async def test_form_create_entry(hass: HomeAssistant) -> None:
[
(ApiError("API Error"), "cannot_connect"),
(InvalidApiKeyError, "invalid_api_key"),
(RetryError("Retry Error"), "cannot_connect"),
(TimeoutError, "cannot_connect"),
(ValueError, "unknown"),
],

View File

@ -3,6 +3,8 @@
from unittest.mock import patch
from nextdns import ApiError
import pytest
from tenacity import RetryError
from homeassistant.components.nextdns.const import CONF_PROFILE_ID, DOMAIN
from homeassistant.config_entries import ConfigEntryState
@ -24,7 +26,10 @@ async def test_async_setup_entry(hass: HomeAssistant) -> None:
assert state.state == "20.0"
async def test_config_not_ready(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
"exc", [ApiError("API Error"), RetryError("Retry Error"), TimeoutError]
)
async def test_config_not_ready(hass: HomeAssistant, exc: Exception) -> None:
"""Test for setup failure if the connection to the service fails."""
entry = MockConfigEntry(
domain=DOMAIN,
@ -35,7 +40,7 @@ async def test_config_not_ready(hass: HomeAssistant) -> None:
with patch(
"homeassistant.components.nextdns.NextDns.get_profiles",
side_effect=ApiError("API Error"),
side_effect=exc,
):
entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id)

View File

@ -8,6 +8,7 @@ from aiohttp.client_exceptions import ClientConnectorError
from nextdns import ApiError
import pytest
from syrupy import SnapshotAssertion
from tenacity import RetryError
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
from homeassistant.const import (
@ -94,7 +95,15 @@ async def test_switch_off(hass: HomeAssistant) -> None:
mock_switch_on.assert_called_once()
async def test_availability(hass: HomeAssistant) -> None:
@pytest.mark.parametrize(
"exc",
[
ApiError("API Error"),
RetryError("Retry Error"),
TimeoutError,
],
)
async def test_availability(hass: HomeAssistant, exc: Exception) -> None:
"""Ensure that we mark the entities unavailable correctly when service causes an error."""
await init_integration(hass)
@ -106,7 +115,7 @@ async def test_availability(hass: HomeAssistant) -> None:
future = utcnow() + timedelta(minutes=10)
with patch(
"homeassistant.components.nextdns.NextDns.get_settings",
side_effect=ApiError("API Error"),
side_effect=exc,
):
async_fire_time_changed(hass, future)
await hass.async_block_till_done(wait_background_tasks=True)