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