Bump nextdns
to version 3.1.0 (#120703)
Co-authored-by: Maciej Bieniek <478555+bieniu@users.noreply.github.com>
This commit is contained in:
parent
f3761a8e53
commit
e764afecac
9 changed files with 39 additions and 20 deletions
|
@ -18,6 +18,7 @@ from nextdns import (
|
||||||
NextDns,
|
NextDns,
|
||||||
Settings,
|
Settings,
|
||||||
)
|
)
|
||||||
|
from tenacity import RetryError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, Platform
|
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)
|
websession = async_get_clientsession(hass)
|
||||||
try:
|
try:
|
||||||
async with asyncio.timeout(10):
|
nextdns = await NextDns.create(websession, api_key)
|
||||||
nextdns = await NextDns.create(websession, api_key)
|
except (ApiError, ClientConnectorError, RetryError, TimeoutError) as err:
|
||||||
except (ApiError, ClientConnectorError, TimeoutError) as err:
|
|
||||||
raise ConfigEntryNotReady from err
|
raise ConfigEntryNotReady from err
|
||||||
|
|
||||||
tasks = []
|
tasks = []
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
from nextdns import ApiError, InvalidApiKeyError, NextDns
|
from nextdns import ApiError, InvalidApiKeyError, NextDns
|
||||||
|
from tenacity import RetryError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
|
||||||
|
@ -37,13 +37,12 @@ class NextDnsFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
self.api_key = user_input[CONF_API_KEY]
|
self.api_key = user_input[CONF_API_KEY]
|
||||||
try:
|
try:
|
||||||
async with asyncio.timeout(10):
|
self.nextdns = await NextDns.create(
|
||||||
self.nextdns = await NextDns.create(
|
websession, user_input[CONF_API_KEY]
|
||||||
websession, user_input[CONF_API_KEY]
|
)
|
||||||
)
|
|
||||||
except InvalidApiKeyError:
|
except InvalidApiKeyError:
|
||||||
errors["base"] = "invalid_api_key"
|
errors["base"] = "invalid_api_key"
|
||||||
except (ApiError, ClientConnectorError, TimeoutError):
|
except (ApiError, ClientConnectorError, RetryError, TimeoutError):
|
||||||
errors["base"] = "cannot_connect"
|
errors["base"] = "cannot_connect"
|
||||||
except Exception: # noqa: BLE001
|
except Exception: # noqa: BLE001
|
||||||
errors["base"] = "unknown"
|
errors["base"] = "unknown"
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""NextDns coordinator."""
|
"""NextDns coordinator."""
|
||||||
|
|
||||||
import asyncio
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import TypeVar
|
from typing import TypeVar
|
||||||
|
@ -19,6 +18,7 @@ from nextdns import (
|
||||||
Settings,
|
Settings,
|
||||||
)
|
)
|
||||||
from nextdns.model import NextDnsData
|
from nextdns.model import NextDnsData
|
||||||
|
from tenacity import RetryError
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
|
@ -58,9 +58,13 @@ class NextDnsUpdateCoordinator(DataUpdateCoordinator[CoordinatorDataT]):
|
||||||
async def _async_update_data(self) -> CoordinatorDataT:
|
async def _async_update_data(self) -> CoordinatorDataT:
|
||||||
"""Update data via internal method."""
|
"""Update data via internal method."""
|
||||||
try:
|
try:
|
||||||
async with asyncio.timeout(10):
|
return await self._async_update_data_internal()
|
||||||
return await self._async_update_data_internal()
|
except (
|
||||||
except (ApiError, ClientConnectorError, InvalidApiKeyError) as err:
|
ApiError,
|
||||||
|
ClientConnectorError,
|
||||||
|
InvalidApiKeyError,
|
||||||
|
RetryError,
|
||||||
|
) as err:
|
||||||
raise UpdateFailed(err) from err
|
raise UpdateFailed(err) from err
|
||||||
|
|
||||||
async def _async_update_data_internal(self) -> CoordinatorDataT:
|
async def _async_update_data_internal(self) -> CoordinatorDataT:
|
||||||
|
|
|
@ -8,5 +8,5 @@
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"loggers": ["nextdns"],
|
"loggers": ["nextdns"],
|
||||||
"quality_scale": "platinum",
|
"quality_scale": "platinum",
|
||||||
"requirements": ["nextdns==3.0.0"]
|
"requirements": ["nextdns==3.1.0"]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1404,7 +1404,7 @@ nextcloudmonitor==1.5.0
|
||||||
nextcord==2.6.0
|
nextcord==2.6.0
|
||||||
|
|
||||||
# homeassistant.components.nextdns
|
# homeassistant.components.nextdns
|
||||||
nextdns==3.0.0
|
nextdns==3.1.0
|
||||||
|
|
||||||
# homeassistant.components.nibe_heatpump
|
# homeassistant.components.nibe_heatpump
|
||||||
nibe==2.8.0
|
nibe==2.8.0
|
||||||
|
|
|
@ -1143,7 +1143,7 @@ nextcloudmonitor==1.5.0
|
||||||
nextcord==2.6.0
|
nextcord==2.6.0
|
||||||
|
|
||||||
# homeassistant.components.nextdns
|
# homeassistant.components.nextdns
|
||||||
nextdns==3.0.0
|
nextdns==3.1.0
|
||||||
|
|
||||||
# homeassistant.components.nibe_heatpump
|
# homeassistant.components.nibe_heatpump
|
||||||
nibe==2.8.0
|
nibe==2.8.0
|
||||||
|
|
|
@ -4,6 +4,7 @@ from unittest.mock import patch
|
||||||
|
|
||||||
from nextdns import ApiError, InvalidApiKeyError
|
from nextdns import ApiError, InvalidApiKeyError
|
||||||
import pytest
|
import pytest
|
||||||
|
from tenacity import RetryError
|
||||||
|
|
||||||
from homeassistant.components.nextdns.const import CONF_PROFILE_ID, DOMAIN
|
from homeassistant.components.nextdns.const import CONF_PROFILE_ID, DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_USER
|
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"),
|
(ApiError("API Error"), "cannot_connect"),
|
||||||
(InvalidApiKeyError, "invalid_api_key"),
|
(InvalidApiKeyError, "invalid_api_key"),
|
||||||
|
(RetryError("Retry Error"), "cannot_connect"),
|
||||||
(TimeoutError, "cannot_connect"),
|
(TimeoutError, "cannot_connect"),
|
||||||
(ValueError, "unknown"),
|
(ValueError, "unknown"),
|
||||||
],
|
],
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from nextdns import ApiError
|
from nextdns import ApiError
|
||||||
|
import pytest
|
||||||
|
from tenacity import RetryError
|
||||||
|
|
||||||
from homeassistant.components.nextdns.const import CONF_PROFILE_ID, DOMAIN
|
from homeassistant.components.nextdns.const import CONF_PROFILE_ID, DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
@ -24,7 +26,10 @@ async def test_async_setup_entry(hass: HomeAssistant) -> None:
|
||||||
assert state.state == "20.0"
|
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."""
|
"""Test for setup failure if the connection to the service fails."""
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
|
@ -35,7 +40,7 @@ async def test_config_not_ready(hass: HomeAssistant) -> None:
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.nextdns.NextDns.get_profiles",
|
"homeassistant.components.nextdns.NextDns.get_profiles",
|
||||||
side_effect=ApiError("API Error"),
|
side_effect=exc,
|
||||||
):
|
):
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
|
|
@ -8,6 +8,7 @@ from aiohttp.client_exceptions import ClientConnectorError
|
||||||
from nextdns import ApiError
|
from nextdns import ApiError
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy import SnapshotAssertion
|
from syrupy import SnapshotAssertion
|
||||||
|
from tenacity import RetryError
|
||||||
|
|
||||||
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
from homeassistant.components.switch import DOMAIN as SWITCH_DOMAIN
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
|
@ -94,7 +95,15 @@ async def test_switch_off(hass: HomeAssistant) -> None:
|
||||||
mock_switch_on.assert_called_once()
|
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."""
|
"""Ensure that we mark the entities unavailable correctly when service causes an error."""
|
||||||
await init_integration(hass)
|
await init_integration(hass)
|
||||||
|
|
||||||
|
@ -106,7 +115,7 @@ async def test_availability(hass: HomeAssistant) -> None:
|
||||||
future = utcnow() + timedelta(minutes=10)
|
future = utcnow() + timedelta(minutes=10)
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.nextdns.NextDns.get_settings",
|
"homeassistant.components.nextdns.NextDns.get_settings",
|
||||||
side_effect=ApiError("API Error"),
|
side_effect=exc,
|
||||||
):
|
):
|
||||||
async_fire_time_changed(hass, future)
|
async_fire_time_changed(hass, future)
|
||||||
await hass.async_block_till_done(wait_background_tasks=True)
|
await hass.async_block_till_done(wait_background_tasks=True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue