From 40be2324cce648256dad9f978edfcebca11dfd24 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 23 Jan 2023 09:06:26 +0100 Subject: [PATCH] Update Union typing (5) [Py310] (#86428) --- .../components/device_automation/__init__.py | 15 ++++++++------- homeassistant/components/hue/switch.py | 6 +++--- homeassistant/components/hue/v2/binary_sensor.py | 6 +++--- homeassistant/components/hue/v2/entity.py | 4 ++-- homeassistant/components/hue/v2/sensor.py | 16 ++++++++-------- homeassistant/components/lcn/helpers.py | 9 +++++---- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/homeassistant/components/device_automation/__init__.py b/homeassistant/components/device_automation/__init__.py index 65aad7def74..75caf6f4f0a 100644 --- a/homeassistant/components/device_automation/__init__.py +++ b/homeassistant/components/device_automation/__init__.py @@ -7,7 +7,7 @@ from enum import Enum from functools import wraps import logging from types import ModuleType -from typing import TYPE_CHECKING, Any, Literal, NamedTuple, Union, overload +from typing import TYPE_CHECKING, Any, Literal, NamedTuple, TypeAlias, overload import voluptuous as vol import voluptuous_serialize @@ -43,12 +43,13 @@ if TYPE_CHECKING: from .condition import DeviceAutomationConditionProtocol from .trigger import DeviceAutomationTriggerProtocol - DeviceAutomationPlatformType = Union[ - ModuleType, - DeviceAutomationTriggerProtocol, - DeviceAutomationConditionProtocol, - DeviceAutomationActionProtocol, - ] + DeviceAutomationPlatformType: TypeAlias = ( + ModuleType + | DeviceAutomationTriggerProtocol + | DeviceAutomationConditionProtocol + | DeviceAutomationActionProtocol + ) + DOMAIN = "device_automation" diff --git a/homeassistant/components/hue/switch.py b/homeassistant/components/hue/switch.py index 7fb40cba38f..936b91aeef8 100644 --- a/homeassistant/components/hue/switch.py +++ b/homeassistant/components/hue/switch.py @@ -1,7 +1,7 @@ """Support for switch platform for Hue resources (V2 only).""" from __future__ import annotations -from typing import Any, Union +from typing import Any, TypeAlias from aiohue.v2 import HueBridgeV2 from aiohue.v2.controllers.events import EventType @@ -22,9 +22,9 @@ from .bridge import HueBridge from .const import DOMAIN from .v2.entity import HueBaseEntity -ControllerType = Union[LightLevelController, MotionController] +ControllerType: TypeAlias = LightLevelController | MotionController -SensingService = Union[LightLevel, Motion] +SensingService: TypeAlias = LightLevel | Motion async def async_setup_entry( diff --git a/homeassistant/components/hue/v2/binary_sensor.py b/homeassistant/components/hue/v2/binary_sensor.py index a7077ccf765..0a8f50b8b7a 100644 --- a/homeassistant/components/hue/v2/binary_sensor.py +++ b/homeassistant/components/hue/v2/binary_sensor.py @@ -1,7 +1,7 @@ """Support for Hue binary sensors.""" from __future__ import annotations -from typing import Any, Union +from typing import Any, TypeAlias from aiohue.v2 import HueBridgeV2 from aiohue.v2.controllers.config import ( @@ -25,8 +25,8 @@ from ..bridge import HueBridge from ..const import DOMAIN from .entity import HueBaseEntity -SensorType = Union[Motion, EntertainmentConfiguration] -ControllerType = Union[MotionController, EntertainmentConfigurationController] +SensorType: TypeAlias = Motion | EntertainmentConfiguration +ControllerType: TypeAlias = MotionController | EntertainmentConfigurationController async def async_setup_entry( diff --git a/homeassistant/components/hue/v2/entity.py b/homeassistant/components/hue/v2/entity.py index ac901d63758..04bb553cd36 100644 --- a/homeassistant/components/hue/v2/entity.py +++ b/homeassistant/components/hue/v2/entity.py @@ -1,7 +1,7 @@ """Generic Hue Entity Model.""" from __future__ import annotations -from typing import TYPE_CHECKING, Union +from typing import TYPE_CHECKING, TypeAlias from aiohue.v2.controllers.base import BaseResourcesController from aiohue.v2.controllers.events import EventType @@ -23,7 +23,7 @@ if TYPE_CHECKING: from aiohue.v2.models.light_level import LightLevel from aiohue.v2.models.motion import Motion - HueResource = Union[Light, DevicePower, GroupedLight, LightLevel, Motion] + HueResource: TypeAlias = Light | DevicePower | GroupedLight | LightLevel | Motion RESOURCE_TYPE_NAMES = { diff --git a/homeassistant/components/hue/v2/sensor.py b/homeassistant/components/hue/v2/sensor.py index c0d450230c9..208873b93f9 100644 --- a/homeassistant/components/hue/v2/sensor.py +++ b/homeassistant/components/hue/v2/sensor.py @@ -1,7 +1,7 @@ """Support for Hue sensors.""" from __future__ import annotations -from typing import Any, Union +from typing import Any, TypeAlias from aiohue.v2 import HueBridgeV2 from aiohue.v2.controllers.events import EventType @@ -32,13 +32,13 @@ from ..bridge import HueBridge from ..const import DOMAIN from .entity import HueBaseEntity -SensorType = Union[DevicePower, LightLevel, Temperature, ZigbeeConnectivity] -ControllerType = Union[ - DevicePowerController, - LightLevelController, - TemperatureController, - ZigbeeConnectivityController, -] +SensorType: TypeAlias = DevicePower | LightLevel | Temperature | ZigbeeConnectivity +ControllerType: TypeAlias = ( + DevicePowerController + | LightLevelController + | TemperatureController + | ZigbeeConnectivityController +) async def async_setup_entry( diff --git a/homeassistant/components/lcn/helpers.py b/homeassistant/components/lcn/helpers.py index e9fb2683f4f..776ad116f4a 100644 --- a/homeassistant/components/lcn/helpers.py +++ b/homeassistant/components/lcn/helpers.py @@ -5,7 +5,7 @@ import asyncio from copy import deepcopy from itertools import chain import re -from typing import Union, cast +from typing import TypeAlias, cast import pypck import voluptuous as vol @@ -60,9 +60,10 @@ from .const import ( # typing AddressType = tuple[int, int, bool] -DeviceConnectionType = Union[ - pypck.module.ModuleConnection, pypck.module.GroupConnection -] +DeviceConnectionType: TypeAlias = ( + pypck.module.ModuleConnection | pypck.module.GroupConnection +) + InputType = type[pypck.inputs.Input] # Regex for address validation