mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Use new generic notation in devolo_home_network (#129080)
This commit is contained in:
parent
8e7ffd9e16
commit
bd13dbdad0
@ -6,7 +6,7 @@ from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from enum import StrEnum
|
||||
from typing import Any, Generic, TypeVar
|
||||
from typing import Any
|
||||
|
||||
from devolo_plc_api.device_api import ConnectedStationInfo, NeighborAPInfo
|
||||
from devolo_plc_api.plcnet_api import REMOTE, DataRate, LogicalNetwork
|
||||
@ -47,26 +47,10 @@ def _last_restart(runtime: int) -> datetime:
|
||||
)
|
||||
|
||||
|
||||
_CoordinatorDataT = TypeVar(
|
||||
"_CoordinatorDataT",
|
||||
bound=LogicalNetwork
|
||||
| DataRate
|
||||
| list[ConnectedStationInfo]
|
||||
| list[NeighborAPInfo]
|
||||
| int,
|
||||
)
|
||||
_ValueDataT = TypeVar(
|
||||
"_ValueDataT",
|
||||
bound=LogicalNetwork
|
||||
| DataRate
|
||||
| list[ConnectedStationInfo]
|
||||
| list[NeighborAPInfo]
|
||||
| int,
|
||||
)
|
||||
_SensorDataT = TypeVar(
|
||||
"_SensorDataT",
|
||||
bound=int | float | datetime,
|
||||
type _CoordinatorDataType = (
|
||||
LogicalNetwork | DataRate | list[ConnectedStationInfo] | list[NeighborAPInfo] | int
|
||||
)
|
||||
type _SensorDataType = int | float | datetime
|
||||
|
||||
|
||||
class DataRateDirection(StrEnum):
|
||||
@ -77,9 +61,10 @@ class DataRateDirection(StrEnum):
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class DevoloSensorEntityDescription(
|
||||
SensorEntityDescription, Generic[_CoordinatorDataT, _SensorDataT]
|
||||
):
|
||||
class DevoloSensorEntityDescription[
|
||||
_CoordinatorDataT: _CoordinatorDataType,
|
||||
_SensorDataT: _SensorDataType,
|
||||
](SensorEntityDescription):
|
||||
"""Describes devolo sensor entity."""
|
||||
|
||||
value_func: Callable[[_CoordinatorDataT], _SensorDataT]
|
||||
@ -200,8 +185,11 @@ async def async_setup_entry(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class BaseDevoloSensorEntity(
|
||||
Generic[_CoordinatorDataT, _ValueDataT, _SensorDataT],
|
||||
class BaseDevoloSensorEntity[
|
||||
_CoordinatorDataT: _CoordinatorDataType,
|
||||
_ValueDataT: _CoordinatorDataType,
|
||||
_SensorDataT: _SensorDataType,
|
||||
](
|
||||
DevoloCoordinatorEntity[_CoordinatorDataT],
|
||||
SensorEntity,
|
||||
):
|
||||
@ -218,9 +206,11 @@ class BaseDevoloSensorEntity(
|
||||
super().__init__(entry, coordinator)
|
||||
|
||||
|
||||
class DevoloSensorEntity(
|
||||
BaseDevoloSensorEntity[_CoordinatorDataT, _CoordinatorDataT, _SensorDataT]
|
||||
):
|
||||
class DevoloSensorEntity[
|
||||
_CoordinatorDataT: _CoordinatorDataType,
|
||||
_ValueDataT: _CoordinatorDataType,
|
||||
_SensorDataT: _SensorDataType,
|
||||
](BaseDevoloSensorEntity[_CoordinatorDataT, _ValueDataT, _SensorDataT]):
|
||||
"""Representation of a generic devolo sensor."""
|
||||
|
||||
entity_description: DevoloSensorEntityDescription[_CoordinatorDataT, _SensorDataT]
|
||||
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||
|
||||
from collections.abc import Awaitable, Callable
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Generic, TypeVar
|
||||
from typing import Any
|
||||
|
||||
from devolo_plc_api.device import Device
|
||||
from devolo_plc_api.device_api import WifiGuestAccessGet
|
||||
@ -23,11 +23,11 @@ from .entity import DevoloCoordinatorEntity
|
||||
|
||||
PARALLEL_UPDATES = 1
|
||||
|
||||
_DataT = TypeVar("_DataT", bound=WifiGuestAccessGet | bool)
|
||||
type _DataType = WifiGuestAccessGet | bool
|
||||
|
||||
|
||||
@dataclass(frozen=True, kw_only=True)
|
||||
class DevoloSwitchEntityDescription(SwitchEntityDescription, Generic[_DataT]):
|
||||
class DevoloSwitchEntityDescription[_DataT: _DataType](SwitchEntityDescription):
|
||||
"""Describes devolo switch entity."""
|
||||
|
||||
is_on_func: Callable[[_DataT], bool]
|
||||
@ -81,7 +81,9 @@ async def async_setup_entry(
|
||||
async_add_entities(entities)
|
||||
|
||||
|
||||
class DevoloSwitchEntity(DevoloCoordinatorEntity[_DataT], SwitchEntity):
|
||||
class DevoloSwitchEntity[_DataT: _DataType](
|
||||
DevoloCoordinatorEntity[_DataT], SwitchEntity
|
||||
):
|
||||
"""Representation of a devolo switch."""
|
||||
|
||||
entity_description: DevoloSwitchEntityDescription[_DataT]
|
||||
|
Loading…
x
Reference in New Issue
Block a user