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