mirror of
https://github.com/home-assistant/core.git
synced 2025-07-18 02:37:08 +00:00
Use PEP 695 TypeVar syntax for nextdns (#147155)
This commit is contained in:
parent
b8dfb2c850
commit
73d0d87705
@ -4,7 +4,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientConnectorError
|
from aiohttp.client_exceptions import ClientConnectorError
|
||||||
from nextdns import (
|
from nextdns import (
|
||||||
@ -33,10 +33,10 @@ from .const import DOMAIN
|
|||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
CoordinatorDataT = TypeVar("CoordinatorDataT", bound=NextDnsData)
|
|
||||||
|
|
||||||
|
class NextDnsUpdateCoordinator[CoordinatorDataT: NextDnsData](
|
||||||
class NextDnsUpdateCoordinator(DataUpdateCoordinator[CoordinatorDataT]):
|
DataUpdateCoordinator[CoordinatorDataT]
|
||||||
|
):
|
||||||
"""Class to manage fetching NextDNS data API."""
|
"""Class to manage fetching NextDNS data API."""
|
||||||
|
|
||||||
config_entry: NextDnsConfigEntry
|
config_entry: NextDnsConfigEntry
|
||||||
|
@ -1,14 +1,18 @@
|
|||||||
"""Define NextDNS entities."""
|
"""Define NextDNS entities."""
|
||||||
|
|
||||||
|
from nextdns.model import NextDnsData
|
||||||
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity import EntityDescription
|
from homeassistant.helpers.entity import EntityDescription
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import DOMAIN
|
from .const import DOMAIN
|
||||||
from .coordinator import CoordinatorDataT, NextDnsUpdateCoordinator
|
from .coordinator import NextDnsUpdateCoordinator
|
||||||
|
|
||||||
|
|
||||||
class NextDnsEntity(CoordinatorEntity[NextDnsUpdateCoordinator[CoordinatorDataT]]):
|
class NextDnsEntity[CoordinatorDataT: NextDnsData](
|
||||||
|
CoordinatorEntity[NextDnsUpdateCoordinator[CoordinatorDataT]]
|
||||||
|
):
|
||||||
"""Define NextDNS entity."""
|
"""Define NextDNS entity."""
|
||||||
|
|
||||||
_attr_has_entity_name = True
|
_attr_has_entity_name = True
|
||||||
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
|||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Generic
|
|
||||||
|
|
||||||
from nextdns import (
|
from nextdns import (
|
||||||
AnalyticsDnssec,
|
AnalyticsDnssec,
|
||||||
@ -13,6 +12,7 @@ from nextdns import (
|
|||||||
AnalyticsProtocols,
|
AnalyticsProtocols,
|
||||||
AnalyticsStatus,
|
AnalyticsStatus,
|
||||||
)
|
)
|
||||||
|
from nextdns.model import NextDnsData
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
@ -32,15 +32,14 @@ from .const import (
|
|||||||
ATTR_PROTOCOLS,
|
ATTR_PROTOCOLS,
|
||||||
ATTR_STATUS,
|
ATTR_STATUS,
|
||||||
)
|
)
|
||||||
from .coordinator import CoordinatorDataT
|
|
||||||
from .entity import NextDnsEntity
|
from .entity import NextDnsEntity
|
||||||
|
|
||||||
PARALLEL_UPDATES = 0
|
PARALLEL_UPDATES = 0
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
class NextDnsSensorEntityDescription(
|
class NextDnsSensorEntityDescription[CoordinatorDataT: NextDnsData](
|
||||||
SensorEntityDescription, Generic[CoordinatorDataT]
|
SensorEntityDescription
|
||||||
):
|
):
|
||||||
"""NextDNS sensor entity description."""
|
"""NextDNS sensor entity description."""
|
||||||
|
|
||||||
@ -297,10 +296,12 @@ async def async_setup_entry(
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class NextDnsSensor(NextDnsEntity, SensorEntity):
|
class NextDnsSensor[CoordinatorDataT: NextDnsData](
|
||||||
|
NextDnsEntity[CoordinatorDataT], SensorEntity
|
||||||
|
):
|
||||||
"""Define an NextDNS sensor."""
|
"""Define an NextDNS sensor."""
|
||||||
|
|
||||||
entity_description: NextDnsSensorEntityDescription
|
entity_description: NextDnsSensorEntityDescription[CoordinatorDataT]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self) -> StateType:
|
def native_value(self) -> StateType:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user