diff --git a/homeassistant/components/aranet/sensor.py b/homeassistant/components/aranet/sensor.py index 512748fef8d..6ac27b1652b 100644 --- a/homeassistant/components/aranet/sensor.py +++ b/homeassistant/components/aranet/sensor.py @@ -1,8 +1,6 @@ """Support for Aranet sensors.""" from __future__ import annotations -from typing import Optional, Union - from aranet4.client import Aranet4Advertisement from bleak.backends.device import BLEDevice @@ -145,9 +143,7 @@ async def async_setup_entry( class Aranet4BluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of an Aranet sensor.""" diff --git a/homeassistant/components/bluemaestro/sensor.py b/homeassistant/components/bluemaestro/sensor.py index d3776d418e5..b4b10ed2ee6 100644 --- a/homeassistant/components/bluemaestro/sensor.py +++ b/homeassistant/components/bluemaestro/sensor.py @@ -1,8 +1,6 @@ """Support for BlueMaestro sensors.""" from __future__ import annotations -from typing import Optional, Union - from bluemaestro_ble import ( SensorDeviceClass as BlueMaestroSensorDeviceClass, SensorUpdate, @@ -137,9 +135,7 @@ async def async_setup_entry( class BlueMaestroBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a BlueMaestro sensor.""" diff --git a/homeassistant/components/bthome/sensor.py b/homeassistant/components/bthome/sensor.py index 219ce17c081..8cc8b10a67c 100644 --- a/homeassistant/components/bthome/sensor.py +++ b/homeassistant/components/bthome/sensor.py @@ -1,8 +1,6 @@ """Support for BTHome sensors.""" from __future__ import annotations -from typing import Optional, Union - from bthome_ble import SensorDeviceClass as BTHomeSensorDeviceClass, SensorUpdate, Units from homeassistant import config_entries @@ -332,9 +330,7 @@ async def async_setup_entry( class BTHomeBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a BTHome BLE sensor.""" diff --git a/homeassistant/components/dlna_dmr/config_flow.py b/homeassistant/components/dlna_dmr/config_flow.py index d1d1aad0ce9..219f0497ff0 100644 --- a/homeassistant/components/dlna_dmr/config_flow.py +++ b/homeassistant/components/dlna_dmr/config_flow.py @@ -6,7 +6,7 @@ from functools import partial from ipaddress import IPv6Address, ip_address import logging from pprint import pformat -from typing import Any, Optional, cast +from typing import Any, cast from urllib.parse import urlparse from async_upnp_client.client import UpnpError @@ -36,7 +36,7 @@ from .data import get_domain_data LOGGER = logging.getLogger(__name__) -FlowInput = Optional[Mapping[str, Any]] +FlowInput = Mapping[str, Any] | None class ConnectError(IntegrationError): diff --git a/homeassistant/components/govee_ble/sensor.py b/homeassistant/components/govee_ble/sensor.py index ce603b5b5a6..b2da37bdf7e 100644 --- a/homeassistant/components/govee_ble/sensor.py +++ b/homeassistant/components/govee_ble/sensor.py @@ -1,8 +1,6 @@ """Support for govee ble sensors.""" from __future__ import annotations -from typing import Optional, Union - from govee_ble import DeviceClass, DeviceKey, SensorUpdate, Units from govee_ble.parser import ERROR @@ -117,7 +115,7 @@ async def async_setup_entry( class GoveeBluetoothSensorEntity( PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int, str]]] + PassiveBluetoothDataProcessor[float | int | str | None] ], SensorEntity, ): diff --git a/homeassistant/components/inkbird/sensor.py b/homeassistant/components/inkbird/sensor.py index 74716d465a8..f93f2024289 100644 --- a/homeassistant/components/inkbird/sensor.py +++ b/homeassistant/components/inkbird/sensor.py @@ -1,8 +1,6 @@ """Support for inkbird ble sensors.""" from __future__ import annotations -from typing import Optional, Union - from inkbird_ble import DeviceClass, DeviceKey, SensorUpdate, Units from homeassistant import config_entries @@ -115,9 +113,7 @@ async def async_setup_entry( class INKBIRDBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a inkbird ble sensor.""" diff --git a/homeassistant/components/kegtron/sensor.py b/homeassistant/components/kegtron/sensor.py index c80788d2503..5d9895248d3 100644 --- a/homeassistant/components/kegtron/sensor.py +++ b/homeassistant/components/kegtron/sensor.py @@ -1,8 +1,6 @@ """Support for Kegtron sensors.""" from __future__ import annotations -from typing import Optional, Union - from kegtron_ble import ( SensorDeviceClass as KegtronSensorDeviceClass, SensorUpdate, @@ -126,9 +124,7 @@ async def async_setup_entry( class KegtronBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a Kegtron sensor.""" diff --git a/homeassistant/components/moat/sensor.py b/homeassistant/components/moat/sensor.py index fc83d1fe757..f75717fad40 100644 --- a/homeassistant/components/moat/sensor.py +++ b/homeassistant/components/moat/sensor.py @@ -1,8 +1,6 @@ """Support for moat ble sensors.""" from __future__ import annotations -from typing import Optional, Union - from moat_ble import DeviceClass, DeviceKey, SensorUpdate, Units from homeassistant import config_entries @@ -122,9 +120,7 @@ async def async_setup_entry( class MoatBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a moat ble sensor.""" diff --git a/homeassistant/components/modbus/binary_sensor.py b/homeassistant/components/modbus/binary_sensor.py index ec923100347..4f416874f9d 100644 --- a/homeassistant/components/modbus/binary_sensor.py +++ b/homeassistant/components/modbus/binary_sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from datetime import datetime import logging -from typing import Any, Optional +from typing import Any from homeassistant.components.binary_sensor import BinarySensorEntity from homeassistant.const import ( @@ -123,7 +123,7 @@ class ModbusBinarySensor(BasePlatform, RestoreEntity, BinarySensorEntity): class SlaveSensor( - CoordinatorEntity[DataUpdateCoordinator[Optional[list[int]]]], + CoordinatorEntity[DataUpdateCoordinator[list[int] | None]], RestoreEntity, BinarySensorEntity, ): diff --git a/homeassistant/components/modbus/sensor.py b/homeassistant/components/modbus/sensor.py index 7294485365d..04b986e41ba 100644 --- a/homeassistant/components/modbus/sensor.py +++ b/homeassistant/components/modbus/sensor.py @@ -3,7 +3,7 @@ from __future__ import annotations from datetime import datetime import logging -from typing import Any, Optional +from typing import Any from homeassistant.components.sensor import CONF_STATE_CLASS, SensorEntity from homeassistant.const import ( @@ -134,7 +134,7 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity): class SlaveSensor( - CoordinatorEntity[DataUpdateCoordinator[Optional[list[int]]]], + CoordinatorEntity[DataUpdateCoordinator[list[int] | None]], RestoreEntity, SensorEntity, ): diff --git a/homeassistant/components/oralb/sensor.py b/homeassistant/components/oralb/sensor.py index 46ad83d9135..7a198c21f80 100644 --- a/homeassistant/components/oralb/sensor.py +++ b/homeassistant/components/oralb/sensor.py @@ -1,8 +1,6 @@ """Support for OralB sensors.""" from __future__ import annotations -from typing import Optional, Union - from oralb_ble import OralBSensor, SensorUpdate from homeassistant import config_entries @@ -117,9 +115,7 @@ async def async_setup_entry( class OralBBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[str, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[str | int | None]], SensorEntity, ): """Representation of a OralB sensor.""" diff --git a/homeassistant/components/qingping/sensor.py b/homeassistant/components/qingping/sensor.py index 84276c11292..a128bdede0b 100644 --- a/homeassistant/components/qingping/sensor.py +++ b/homeassistant/components/qingping/sensor.py @@ -1,8 +1,6 @@ """Support for Qingping sensors.""" from __future__ import annotations -from typing import Optional, Union - from qingping_ble import ( SensorDeviceClass as QingpingSensorDeviceClass, SensorUpdate, @@ -161,9 +159,7 @@ async def async_setup_entry( class QingpingBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a Qingping sensor.""" diff --git a/homeassistant/components/ruuvitag_ble/sensor.py b/homeassistant/components/ruuvitag_ble/sensor.py index ebdf2c5f264..128edd42b19 100644 --- a/homeassistant/components/ruuvitag_ble/sensor.py +++ b/homeassistant/components/ruuvitag_ble/sensor.py @@ -1,8 +1,6 @@ """Support for RuuviTag sensors.""" from __future__ import annotations -from typing import Optional, Union - from sensor_state_data import ( DeviceKey, SensorDescription, @@ -143,9 +141,7 @@ async def async_setup_entry( class RuuvitagBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a Ruuvitag BLE sensor.""" diff --git a/homeassistant/components/sensirion_ble/sensor.py b/homeassistant/components/sensirion_ble/sensor.py index 2af5808fa56..3d288f92d12 100644 --- a/homeassistant/components/sensirion_ble/sensor.py +++ b/homeassistant/components/sensirion_ble/sensor.py @@ -1,8 +1,6 @@ """Support for Sensirion sensors.""" from __future__ import annotations -from typing import Optional, Union - from sensor_state_data import ( DeviceKey, SensorDescription, @@ -123,9 +121,7 @@ async def async_setup_entry( class SensirionBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a Sensirion BLE sensor.""" diff --git a/homeassistant/components/sensorpro/sensor.py b/homeassistant/components/sensorpro/sensor.py index edfe2fb21c5..36eb3737884 100644 --- a/homeassistant/components/sensorpro/sensor.py +++ b/homeassistant/components/sensorpro/sensor.py @@ -1,8 +1,6 @@ """Support for SensorPro sensors.""" from __future__ import annotations -from typing import Optional, Union - from sensorpro_ble import ( SensorDeviceClass as SensorProSensorDeviceClass, SensorUpdate, @@ -128,9 +126,7 @@ async def async_setup_entry( class SensorProBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a SensorPro sensor.""" diff --git a/homeassistant/components/sensorpush/sensor.py b/homeassistant/components/sensorpush/sensor.py index 7742642e92c..479acd8ac1e 100644 --- a/homeassistant/components/sensorpush/sensor.py +++ b/homeassistant/components/sensorpush/sensor.py @@ -1,8 +1,6 @@ """Support for sensorpush ble sensors.""" from __future__ import annotations -from typing import Optional, Union - from sensorpush_ble import DeviceClass, DeviceKey, SensorUpdate, Units from homeassistant import config_entries @@ -116,9 +114,7 @@ async def async_setup_entry( class SensorPushBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a sensorpush ble sensor.""" diff --git a/homeassistant/components/thermobeacon/sensor.py b/homeassistant/components/thermobeacon/sensor.py index b651fb2cea0..6cd80bad7a3 100644 --- a/homeassistant/components/thermobeacon/sensor.py +++ b/homeassistant/components/thermobeacon/sensor.py @@ -1,8 +1,6 @@ """Support for ThermoBeacon sensors.""" from __future__ import annotations -from typing import Optional, Union - from thermobeacon_ble import ( SensorDeviceClass as ThermoBeaconSensorDeviceClass, SensorUpdate, @@ -128,9 +126,7 @@ async def async_setup_entry( class ThermoBeaconBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a ThermoBeacon sensor.""" diff --git a/homeassistant/components/thermopro/sensor.py b/homeassistant/components/thermopro/sensor.py index 8a2e68f1625..107385615f8 100644 --- a/homeassistant/components/thermopro/sensor.py +++ b/homeassistant/components/thermopro/sensor.py @@ -1,8 +1,6 @@ """Support for thermopro ble sensors.""" from __future__ import annotations -from typing import Optional, Union - from thermopro_ble import ( DeviceKey, SensorDeviceClass as ThermoProSensorDeviceClass, @@ -117,9 +115,7 @@ async def async_setup_entry( class ThermoProBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a thermopro ble sensor.""" diff --git a/homeassistant/components/tilt_ble/sensor.py b/homeassistant/components/tilt_ble/sensor.py index be0e9e66037..7edfec3643f 100644 --- a/homeassistant/components/tilt_ble/sensor.py +++ b/homeassistant/components/tilt_ble/sensor.py @@ -1,8 +1,6 @@ """Support for Tilt Hydrometers.""" from __future__ import annotations -from typing import Optional, Union - from tilt_ble import DeviceClass, DeviceKey, SensorUpdate, Units from homeassistant import config_entries @@ -103,9 +101,7 @@ async def async_setup_entry( class TiltBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a Tilt Hydrometer BLE sensor.""" diff --git a/homeassistant/components/xiaomi_ble/sensor.py b/homeassistant/components/xiaomi_ble/sensor.py index 334099cdbb6..652ae335c00 100644 --- a/homeassistant/components/xiaomi_ble/sensor.py +++ b/homeassistant/components/xiaomi_ble/sensor.py @@ -1,8 +1,6 @@ """Support for xiaomi ble sensors.""" from __future__ import annotations -from typing import Optional, Union - from xiaomi_ble import DeviceClass, SensorUpdate, Units from homeassistant import config_entries @@ -162,9 +160,7 @@ async def async_setup_entry( class XiaomiBluetoothSensorEntity( - PassiveBluetoothProcessorEntity[ - PassiveBluetoothDataProcessor[Optional[Union[float, int]]] - ], + PassiveBluetoothProcessorEntity[PassiveBluetoothDataProcessor[float | int | None]], SensorEntity, ): """Representation of a xiaomi ble sensor.""" diff --git a/homeassistant/helpers/typing.py b/homeassistant/helpers/typing.py index 0e3edab71b0..326d2f98259 100644 --- a/homeassistant/helpers/typing.py +++ b/homeassistant/helpers/typing.py @@ -1,7 +1,7 @@ """Typing Helpers for Home Assistant.""" from collections.abc import Mapping from enum import Enum -from typing import Any, Optional, Union +from typing import Any import homeassistant.core @@ -11,8 +11,8 @@ ContextType = homeassistant.core.Context DiscoveryInfoType = dict[str, Any] EventType = homeassistant.core.Event ServiceDataType = dict[str, Any] -StateType = Union[None, str, int, float] -TemplateVarsType = Optional[Mapping[str, Any]] +StateType = str | int | float | None +TemplateVarsType = Mapping[str, Any] | None # Custom type for recorder Queries QueryType = Any