Add Self typing (2) [mypy 1.0] (#87599)
This commit is contained in:
parent
37bb1e8948
commit
a5d376069a
8 changed files with 41 additions and 62 deletions
|
@ -4,8 +4,9 @@ from __future__ import annotations
|
||||||
import abc
|
import abc
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import zigpy.exceptions
|
import zigpy.exceptions
|
||||||
from zigpy.zcl.foundation import Status
|
from zigpy.zcl.foundation import Status
|
||||||
|
|
||||||
|
@ -27,8 +28,6 @@ if TYPE_CHECKING:
|
||||||
from .core.device import ZHADevice
|
from .core.device import ZHADevice
|
||||||
|
|
||||||
|
|
||||||
_ZHAIdentifyButtonSelfT = TypeVar("_ZHAIdentifyButtonSelfT", bound="ZHAIdentifyButton")
|
|
||||||
|
|
||||||
MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.BUTTON)
|
MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.BUTTON)
|
||||||
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
||||||
ZHA_ENTITIES.config_diagnostic_match, Platform.BUTTON
|
ZHA_ENTITIES.config_diagnostic_match, Platform.BUTTON
|
||||||
|
@ -91,12 +90,12 @@ class ZHAIdentifyButton(ZHAButton):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ZHAIdentifyButtonSelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ZHAIdentifyButtonSelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
|
|
@ -2,8 +2,9 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import zigpy.endpoint
|
import zigpy.endpoint
|
||||||
import zigpy.zcl.clusters.closures
|
import zigpy.zcl.clusters.closures
|
||||||
|
|
||||||
|
@ -36,8 +37,6 @@ if TYPE_CHECKING:
|
||||||
from ...entity import ZhaEntity
|
from ...entity import ZhaEntity
|
||||||
from ..device import ZHADevice
|
from ..device import ZHADevice
|
||||||
|
|
||||||
_ChannelsSelfT = TypeVar("_ChannelsSelfT", bound="Channels")
|
|
||||||
_ChannelPoolSelfT = TypeVar("_ChannelPoolSelfT", bound="ChannelPool")
|
|
||||||
_ChannelsDictType = dict[str, base.ZigbeeChannel]
|
_ChannelsDictType = dict[str, base.ZigbeeChannel]
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +103,7 @@ class Channels:
|
||||||
}
|
}
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(cls: type[_ChannelsSelfT], zha_device: ZHADevice) -> _ChannelsSelfT:
|
def new(cls, zha_device: ZHADevice) -> Self:
|
||||||
"""Create new instance."""
|
"""Create new instance."""
|
||||||
channels = cls(zha_device)
|
channels = cls(zha_device)
|
||||||
for ep_id in sorted(zha_device.device.endpoints):
|
for ep_id in sorted(zha_device.device.endpoints):
|
||||||
|
@ -272,9 +271,7 @@ class ChannelPool:
|
||||||
)
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(
|
def new(cls, channels: Channels, ep_id: int) -> Self:
|
||||||
cls: type[_ChannelPoolSelfT], channels: Channels, ep_id: int
|
|
||||||
) -> _ChannelPoolSelfT:
|
|
||||||
"""Create new channels for an endpoint."""
|
"""Create new channels for an endpoint."""
|
||||||
pool = cls(channels, ep_id)
|
pool = cls(channels, ep_id)
|
||||||
pool.add_all_channels()
|
pool.add_all_channels()
|
||||||
|
|
|
@ -9,8 +9,9 @@ from functools import cached_property
|
||||||
import logging
|
import logging
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
from zigpy import types
|
from zigpy import types
|
||||||
import zigpy.device
|
import zigpy.device
|
||||||
import zigpy.exceptions
|
import zigpy.exceptions
|
||||||
|
@ -90,8 +91,6 @@ _LOGGER = logging.getLogger(__name__)
|
||||||
_UPDATE_ALIVE_INTERVAL = (60, 90)
|
_UPDATE_ALIVE_INTERVAL = (60, 90)
|
||||||
_CHECKIN_GRACE_PERIODS = 2
|
_CHECKIN_GRACE_PERIODS = 2
|
||||||
|
|
||||||
_ZHADeviceSelfT = TypeVar("_ZHADeviceSelfT", bound="ZHADevice")
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceStatus(Enum):
|
class DeviceStatus(Enum):
|
||||||
"""Status of a device."""
|
"""Status of a device."""
|
||||||
|
@ -346,12 +345,12 @@ class ZHADevice(LogMixin):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def new(
|
def new(
|
||||||
cls: type[_ZHADeviceSelfT],
|
cls,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
zigpy_dev: zigpy.device.Device,
|
zigpy_dev: zigpy.device.Device,
|
||||||
gateway: ZHAGateway,
|
gateway: ZHAGateway,
|
||||||
restored: bool = False,
|
restored: bool = False,
|
||||||
) -> _ZHADeviceSelfT:
|
) -> Self:
|
||||||
"""Create new device."""
|
"""Create new device."""
|
||||||
zha_dev = cls(hass, zigpy_dev, gateway)
|
zha_dev = cls(hass, zigpy_dev, gateway)
|
||||||
zha_dev.channels = channels.Channels.new(zha_dev)
|
zha_dev.channels = channels.Channels.new(zha_dev)
|
||||||
|
|
|
@ -5,7 +5,9 @@ import asyncio
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
|
|
||||||
from homeassistant.const import ATTR_NAME
|
from homeassistant.const import ATTR_NAME
|
||||||
from homeassistant.core import CALLBACK_TYPE, Event, callback
|
from homeassistant.core import CALLBACK_TYPE, Event, callback
|
||||||
|
@ -35,9 +37,6 @@ if TYPE_CHECKING:
|
||||||
from .core.channels.base import ZigbeeChannel
|
from .core.channels.base import ZigbeeChannel
|
||||||
from .core.device import ZHADevice
|
from .core.device import ZHADevice
|
||||||
|
|
||||||
_ZhaEntitySelfT = TypeVar("_ZhaEntitySelfT", bound="ZhaEntity")
|
|
||||||
_ZhaGroupEntitySelfT = TypeVar("_ZhaGroupEntitySelfT", bound="ZhaGroupEntity")
|
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
ENTITY_SUFFIX = "entity_suffix"
|
ENTITY_SUFFIX = "entity_suffix"
|
||||||
|
@ -181,12 +180,12 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ZhaEntitySelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ZhaEntitySelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
@ -279,13 +278,13 @@ class ZhaGroupEntity(BaseZhaEntity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ZhaGroupEntitySelfT],
|
cls,
|
||||||
entity_ids: list[str],
|
entity_ids: list[str],
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
group_id: int,
|
group_id: int,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ZhaGroupEntitySelfT | None:
|
) -> Self | None:
|
||||||
"""Group Entity Factory.
|
"""Group Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
|
|
@ -3,8 +3,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import zigpy.exceptions
|
import zigpy.exceptions
|
||||||
from zigpy.zcl.foundation import Status
|
from zigpy.zcl.foundation import Status
|
||||||
|
|
||||||
|
@ -36,10 +37,6 @@ if TYPE_CHECKING:
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
_ZHANumberConfigurationEntitySelfT = TypeVar(
|
|
||||||
"_ZHANumberConfigurationEntitySelfT", bound="ZHANumberConfigurationEntity"
|
|
||||||
)
|
|
||||||
|
|
||||||
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.NUMBER)
|
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.NUMBER)
|
||||||
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
||||||
ZHA_ENTITIES.config_diagnostic_match, Platform.NUMBER
|
ZHA_ENTITIES.config_diagnostic_match, Platform.NUMBER
|
||||||
|
@ -383,12 +380,12 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ZHANumberConfigurationEntitySelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ZHANumberConfigurationEntitySelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
|
|
@ -4,8 +4,9 @@ from __future__ import annotations
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
from zigpy import types
|
from zigpy import types
|
||||||
from zigpy.zcl.clusters.general import OnOff
|
from zigpy.zcl.clusters.general import OnOff
|
||||||
from zigpy.zcl.clusters.security import IasWd
|
from zigpy.zcl.clusters.security import IasWd
|
||||||
|
@ -36,10 +37,6 @@ if TYPE_CHECKING:
|
||||||
from .core.device import ZHADevice
|
from .core.device import ZHADevice
|
||||||
|
|
||||||
|
|
||||||
_ZCLEnumSelectEntitySelfT = TypeVar(
|
|
||||||
"_ZCLEnumSelectEntitySelfT", bound="ZCLEnumSelectEntity"
|
|
||||||
)
|
|
||||||
|
|
||||||
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
||||||
ZHA_ENTITIES.config_diagnostic_match, Platform.SELECT
|
ZHA_ENTITIES.config_diagnostic_match, Platform.SELECT
|
||||||
)
|
)
|
||||||
|
@ -164,12 +161,12 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ZCLEnumSelectEntitySelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ZCLEnumSelectEntitySelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
|
|
@ -4,8 +4,9 @@ from __future__ import annotations
|
||||||
import enum
|
import enum
|
||||||
import functools
|
import functools
|
||||||
import numbers
|
import numbers
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
from zigpy import types
|
from zigpy import types
|
||||||
|
|
||||||
from homeassistant.components.climate import HVACAction
|
from homeassistant.components.climate import HVACAction
|
||||||
|
@ -68,13 +69,6 @@ if TYPE_CHECKING:
|
||||||
from .core.channels.base import ZigbeeChannel
|
from .core.channels.base import ZigbeeChannel
|
||||||
from .core.device import ZHADevice
|
from .core.device import ZHADevice
|
||||||
|
|
||||||
_SensorSelfT = TypeVar("_SensorSelfT", bound="Sensor")
|
|
||||||
_BatterySelfT = TypeVar("_BatterySelfT", bound="Battery")
|
|
||||||
_ThermostatHVACActionSelfT = TypeVar(
|
|
||||||
"_ThermostatHVACActionSelfT", bound="ThermostatHVACAction"
|
|
||||||
)
|
|
||||||
_RSSISensorSelfT = TypeVar("_RSSISensorSelfT", bound="RSSISensor")
|
|
||||||
|
|
||||||
PARALLEL_UPDATES = 5
|
PARALLEL_UPDATES = 5
|
||||||
|
|
||||||
BATTERY_SIZES = {
|
BATTERY_SIZES = {
|
||||||
|
@ -139,12 +133,12 @@ class Sensor(ZhaEntity, SensorEntity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_SensorSelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _SensorSelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
@ -209,12 +203,12 @@ class Battery(Sensor):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_BatterySelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _BatterySelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Unlike any other entity, PowerConfiguration cluster may not support
|
Unlike any other entity, PowerConfiguration cluster may not support
|
||||||
|
@ -710,12 +704,12 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ThermostatHVACActionSelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ThermostatHVACActionSelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
@ -839,12 +833,12 @@ class RSSISensor(Sensor, id_suffix="rssi"):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_RSSISensorSelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _RSSISensorSelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
|
|
@ -3,8 +3,9 @@ from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any, TypeVar
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
from typing_extensions import Self
|
||||||
import zigpy.exceptions
|
import zigpy.exceptions
|
||||||
from zigpy.zcl.clusters.general import OnOff
|
from zigpy.zcl.clusters.general import OnOff
|
||||||
from zigpy.zcl.foundation import Status
|
from zigpy.zcl.foundation import Status
|
||||||
|
@ -33,10 +34,6 @@ if TYPE_CHECKING:
|
||||||
from .core.channels.base import ZigbeeChannel
|
from .core.channels.base import ZigbeeChannel
|
||||||
from .core.device import ZHADevice
|
from .core.device import ZHADevice
|
||||||
|
|
||||||
_ZHASwitchConfigurationEntitySelfT = TypeVar(
|
|
||||||
"_ZHASwitchConfigurationEntitySelfT", bound="ZHASwitchConfigurationEntity"
|
|
||||||
)
|
|
||||||
|
|
||||||
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SWITCH)
|
STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SWITCH)
|
||||||
GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.SWITCH)
|
GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.SWITCH)
|
||||||
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
CONFIG_DIAGNOSTIC_MATCH = functools.partial(
|
||||||
|
@ -179,12 +176,12 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def create_entity(
|
def create_entity(
|
||||||
cls: type[_ZHASwitchConfigurationEntitySelfT],
|
cls,
|
||||||
unique_id: str,
|
unique_id: str,
|
||||||
zha_device: ZHADevice,
|
zha_device: ZHADevice,
|
||||||
channels: list[ZigbeeChannel],
|
channels: list[ZigbeeChannel],
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> _ZHASwitchConfigurationEntitySelfT | None:
|
) -> Self | None:
|
||||||
"""Entity Factory.
|
"""Entity Factory.
|
||||||
|
|
||||||
Return entity if it is a supported configuration, otherwise return None
|
Return entity if it is a supported configuration, otherwise return None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue