diff --git a/homeassistant/components/zha/button.py b/homeassistant/components/zha/button.py index e41e7a81e12..da14df0e2f7 100644 --- a/homeassistant/components/zha/button.py +++ b/homeassistant/components/zha/button.py @@ -4,8 +4,9 @@ from __future__ import annotations import abc import functools import logging -from typing import TYPE_CHECKING, Any, TypeVar +from typing import TYPE_CHECKING, Any +from typing_extensions import Self import zigpy.exceptions from zigpy.zcl.foundation import Status @@ -27,8 +28,6 @@ if TYPE_CHECKING: from .core.device import ZHADevice -_ZHAIdentifyButtonSelfT = TypeVar("_ZHAIdentifyButtonSelfT", bound="ZHAIdentifyButton") - MULTI_MATCH = functools.partial(ZHA_ENTITIES.multipass_match, Platform.BUTTON) CONFIG_DIAGNOSTIC_MATCH = functools.partial( ZHA_ENTITIES.config_diagnostic_match, Platform.BUTTON @@ -91,12 +90,12 @@ class ZHAIdentifyButton(ZHAButton): @classmethod def create_entity( - cls: type[_ZHAIdentifyButtonSelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _ZHAIdentifyButtonSelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None diff --git a/homeassistant/components/zha/core/channels/__init__.py b/homeassistant/components/zha/core/channels/__init__.py index 7484b46256c..149b733be39 100644 --- a/homeassistant/components/zha/core/channels/__init__.py +++ b/homeassistant/components/zha/core/channels/__init__.py @@ -2,8 +2,9 @@ from __future__ import annotations 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.zcl.clusters.closures @@ -36,8 +37,6 @@ if TYPE_CHECKING: from ...entity import ZhaEntity from ..device import ZHADevice -_ChannelsSelfT = TypeVar("_ChannelsSelfT", bound="Channels") -_ChannelPoolSelfT = TypeVar("_ChannelPoolSelfT", bound="ChannelPool") _ChannelsDictType = dict[str, base.ZigbeeChannel] @@ -104,7 +103,7 @@ class Channels: } @classmethod - def new(cls: type[_ChannelsSelfT], zha_device: ZHADevice) -> _ChannelsSelfT: + def new(cls, zha_device: ZHADevice) -> Self: """Create new instance.""" channels = cls(zha_device) for ep_id in sorted(zha_device.device.endpoints): @@ -272,9 +271,7 @@ class ChannelPool: ) @classmethod - def new( - cls: type[_ChannelPoolSelfT], channels: Channels, ep_id: int - ) -> _ChannelPoolSelfT: + def new(cls, channels: Channels, ep_id: int) -> Self: """Create new channels for an endpoint.""" pool = cls(channels, ep_id) pool.add_all_channels() diff --git a/homeassistant/components/zha/core/device.py b/homeassistant/components/zha/core/device.py index dd8b3b9c2a7..17ec04fa9e8 100644 --- a/homeassistant/components/zha/core/device.py +++ b/homeassistant/components/zha/core/device.py @@ -9,8 +9,9 @@ from functools import cached_property import logging import random import time -from typing import TYPE_CHECKING, Any, TypeVar +from typing import TYPE_CHECKING, Any +from typing_extensions import Self from zigpy import types import zigpy.device import zigpy.exceptions @@ -90,8 +91,6 @@ _LOGGER = logging.getLogger(__name__) _UPDATE_ALIVE_INTERVAL = (60, 90) _CHECKIN_GRACE_PERIODS = 2 -_ZHADeviceSelfT = TypeVar("_ZHADeviceSelfT", bound="ZHADevice") - class DeviceStatus(Enum): """Status of a device.""" @@ -346,12 +345,12 @@ class ZHADevice(LogMixin): @classmethod def new( - cls: type[_ZHADeviceSelfT], + cls, hass: HomeAssistant, zigpy_dev: zigpy.device.Device, gateway: ZHAGateway, restored: bool = False, - ) -> _ZHADeviceSelfT: + ) -> Self: """Create new device.""" zha_dev = cls(hass, zigpy_dev, gateway) zha_dev.channels = channels.Channels.new(zha_dev) diff --git a/homeassistant/components/zha/entity.py b/homeassistant/components/zha/entity.py index 065f2ce1572..8e0b58a8721 100644 --- a/homeassistant/components/zha/entity.py +++ b/homeassistant/components/zha/entity.py @@ -5,7 +5,9 @@ import asyncio from collections.abc import Callable import functools 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.core import CALLBACK_TYPE, Event, callback @@ -35,9 +37,6 @@ if TYPE_CHECKING: from .core.channels.base import ZigbeeChannel from .core.device import ZHADevice -_ZhaEntitySelfT = TypeVar("_ZhaEntitySelfT", bound="ZhaEntity") -_ZhaGroupEntitySelfT = TypeVar("_ZhaGroupEntitySelfT", bound="ZhaGroupEntity") - _LOGGER = logging.getLogger(__name__) ENTITY_SUFFIX = "entity_suffix" @@ -181,12 +180,12 @@ class ZhaEntity(BaseZhaEntity, RestoreEntity): @classmethod def create_entity( - cls: type[_ZhaEntitySelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _ZhaEntitySelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None @@ -279,13 +278,13 @@ class ZhaGroupEntity(BaseZhaEntity): @classmethod def create_entity( - cls: type[_ZhaGroupEntitySelfT], + cls, entity_ids: list[str], unique_id: str, group_id: int, zha_device: ZHADevice, **kwargs: Any, - ) -> _ZhaGroupEntitySelfT | None: + ) -> Self | None: """Group Entity Factory. Return entity if it is a supported configuration, otherwise return None diff --git a/homeassistant/components/zha/number.py b/homeassistant/components/zha/number.py index 63eb5892242..184a3d46515 100644 --- a/homeassistant/components/zha/number.py +++ b/homeassistant/components/zha/number.py @@ -3,8 +3,9 @@ from __future__ import annotations import functools import logging -from typing import TYPE_CHECKING, Any, TypeVar +from typing import TYPE_CHECKING, Any +from typing_extensions import Self import zigpy.exceptions from zigpy.zcl.foundation import Status @@ -36,10 +37,6 @@ if TYPE_CHECKING: _LOGGER = logging.getLogger(__name__) -_ZHANumberConfigurationEntitySelfT = TypeVar( - "_ZHANumberConfigurationEntitySelfT", bound="ZHANumberConfigurationEntity" -) - STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.NUMBER) CONFIG_DIAGNOSTIC_MATCH = functools.partial( ZHA_ENTITIES.config_diagnostic_match, Platform.NUMBER @@ -383,12 +380,12 @@ class ZHANumberConfigurationEntity(ZhaEntity, NumberEntity): @classmethod def create_entity( - cls: type[_ZHANumberConfigurationEntitySelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _ZHANumberConfigurationEntitySelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None diff --git a/homeassistant/components/zha/select.py b/homeassistant/components/zha/select.py index 295c61314c7..3f6b24282c9 100644 --- a/homeassistant/components/zha/select.py +++ b/homeassistant/components/zha/select.py @@ -4,8 +4,9 @@ from __future__ import annotations from enum import Enum import functools 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.zcl.clusters.general import OnOff from zigpy.zcl.clusters.security import IasWd @@ -36,10 +37,6 @@ if TYPE_CHECKING: from .core.device import ZHADevice -_ZCLEnumSelectEntitySelfT = TypeVar( - "_ZCLEnumSelectEntitySelfT", bound="ZCLEnumSelectEntity" -) - CONFIG_DIAGNOSTIC_MATCH = functools.partial( ZHA_ENTITIES.config_diagnostic_match, Platform.SELECT ) @@ -164,12 +161,12 @@ class ZCLEnumSelectEntity(ZhaEntity, SelectEntity): @classmethod def create_entity( - cls: type[_ZCLEnumSelectEntitySelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _ZCLEnumSelectEntitySelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None diff --git a/homeassistant/components/zha/sensor.py b/homeassistant/components/zha/sensor.py index eb952d44610..b7dec5d61dc 100644 --- a/homeassistant/components/zha/sensor.py +++ b/homeassistant/components/zha/sensor.py @@ -4,8 +4,9 @@ from __future__ import annotations import enum import functools 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 homeassistant.components.climate import HVACAction @@ -68,13 +69,6 @@ if TYPE_CHECKING: from .core.channels.base import ZigbeeChannel 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 BATTERY_SIZES = { @@ -139,12 +133,12 @@ class Sensor(ZhaEntity, SensorEntity): @classmethod def create_entity( - cls: type[_SensorSelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _SensorSelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None @@ -209,12 +203,12 @@ class Battery(Sensor): @classmethod def create_entity( - cls: type[_BatterySelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _BatterySelfT | None: + ) -> Self | None: """Entity Factory. Unlike any other entity, PowerConfiguration cluster may not support @@ -710,12 +704,12 @@ class ThermostatHVACAction(Sensor, id_suffix="hvac_action"): @classmethod def create_entity( - cls: type[_ThermostatHVACActionSelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _ThermostatHVACActionSelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None @@ -839,12 +833,12 @@ class RSSISensor(Sensor, id_suffix="rssi"): @classmethod def create_entity( - cls: type[_RSSISensorSelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _RSSISensorSelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None diff --git a/homeassistant/components/zha/switch.py b/homeassistant/components/zha/switch.py index f7a16c83b60..854c112d4bb 100644 --- a/homeassistant/components/zha/switch.py +++ b/homeassistant/components/zha/switch.py @@ -3,8 +3,9 @@ from __future__ import annotations import functools import logging -from typing import TYPE_CHECKING, Any, TypeVar +from typing import TYPE_CHECKING, Any +from typing_extensions import Self import zigpy.exceptions from zigpy.zcl.clusters.general import OnOff from zigpy.zcl.foundation import Status @@ -33,10 +34,6 @@ if TYPE_CHECKING: from .core.channels.base import ZigbeeChannel from .core.device import ZHADevice -_ZHASwitchConfigurationEntitySelfT = TypeVar( - "_ZHASwitchConfigurationEntitySelfT", bound="ZHASwitchConfigurationEntity" -) - STRICT_MATCH = functools.partial(ZHA_ENTITIES.strict_match, Platform.SWITCH) GROUP_MATCH = functools.partial(ZHA_ENTITIES.group_match, Platform.SWITCH) CONFIG_DIAGNOSTIC_MATCH = functools.partial( @@ -179,12 +176,12 @@ class ZHASwitchConfigurationEntity(ZhaEntity, SwitchEntity): @classmethod def create_entity( - cls: type[_ZHASwitchConfigurationEntitySelfT], + cls, unique_id: str, zha_device: ZHADevice, channels: list[ZigbeeChannel], **kwargs: Any, - ) -> _ZHASwitchConfigurationEntitySelfT | None: + ) -> Self | None: """Entity Factory. Return entity if it is a supported configuration, otherwise return None