diff --git a/homeassistant/auth/jwt_wrapper.py b/homeassistant/auth/jwt_wrapper.py index 58f9260ff8f..3aa3ac63764 100644 --- a/homeassistant/auth/jwt_wrapper.py +++ b/homeassistant/auth/jwt_wrapper.py @@ -78,7 +78,7 @@ class _PyJWTWithVerify(PyJWT): key: str, algorithms: list[str], issuer: str | None = None, - leeway: int | float | timedelta = 0, + leeway: float | timedelta = 0, options: dict[str, Any] | None = None, ) -> dict[str, Any]: """Verify a JWT's signature and claims.""" diff --git a/homeassistant/components/alexa/resources.py b/homeassistant/components/alexa/resources.py index 4bc63f6ccae..7782716798a 100644 --- a/homeassistant/components/alexa/resources.py +++ b/homeassistant/components/alexa/resources.py @@ -291,9 +291,9 @@ class AlexaPresetResource(AlexaCapabilityResource): def __init__( self, labels: list[str], - min_value: int | float, - max_value: int | float, - precision: int | float, + min_value: float, + max_value: float, + precision: float, unit: str | None = None, ) -> None: """Initialize an Alexa presetResource.""" @@ -306,7 +306,7 @@ class AlexaPresetResource(AlexaCapabilityResource): if unit in AlexaGlobalCatalog.__dict__.values(): self._unit_of_measure = unit - def add_preset(self, value: int | float, labels: list[str]) -> None: + def add_preset(self, value: float, labels: list[str]) -> None: """Add preset to configuration presets array.""" self._presets.append({"value": value, "labels": labels}) @@ -405,7 +405,7 @@ class AlexaSemantics: ) def add_states_to_range( - self, states: list[str], min_value: int | float, max_value: int | float + self, states: list[str], min_value: float, max_value: float ) -> None: """Add StatesToRange stateMappings.""" self._add_state_mapping( diff --git a/homeassistant/components/demo/sensor.py b/homeassistant/components/demo/sensor.py index 4281ca9cc59..0c61faae00e 100644 --- a/homeassistant/components/demo/sensor.py +++ b/homeassistant/components/demo/sensor.py @@ -149,7 +149,7 @@ class DemoSensor(SensorEntity): self, unique_id: str, device_name: str | None, - state: float | int | str | None, + state: float | str | None, device_class: SensorDeviceClass, state_class: SensorStateClass | None, unit_of_measurement: str | None, diff --git a/homeassistant/components/homekit/type_thermostats.py b/homeassistant/components/homekit/type_thermostats.py index ba0f9790efb..5dc520e8568 100644 --- a/homeassistant/components/homekit/type_thermostats.py +++ b/homeassistant/components/homekit/type_thermostats.py @@ -411,10 +411,10 @@ class Thermostat(HomeAccessory): params = {ATTR_ENTITY_ID: self.entity_id, ATTR_FAN_MODE: mode} self.async_call_service(DOMAIN_CLIMATE, SERVICE_SET_FAN_MODE, params) - def _temperature_to_homekit(self, temp: float | int) -> float: + def _temperature_to_homekit(self, temp: float) -> float: return temperature_to_homekit(temp, self._unit) - def _temperature_to_states(self, temp: float | int) -> float: + def _temperature_to_states(self, temp: float) -> float: return temperature_to_states(temp, self._unit) def _set_chars(self, char_values: dict[str, Any]) -> None: diff --git a/homeassistant/components/homekit/util.py b/homeassistant/components/homekit/util.py index f63ad9f46ae..dec7fe8eba7 100644 --- a/homeassistant/components/homekit/util.py +++ b/homeassistant/components/homekit/util.py @@ -401,14 +401,14 @@ def cleanup_name_for_homekit(name: str | None) -> str: return name.translate(HOMEKIT_CHAR_TRANSLATIONS)[:MAX_NAME_LENGTH] -def temperature_to_homekit(temperature: float | int, unit: str) -> float: +def temperature_to_homekit(temperature: float, unit: str) -> float: """Convert temperature to Celsius for HomeKit.""" return round( TemperatureConverter.convert(temperature, unit, UnitOfTemperature.CELSIUS), 1 ) -def temperature_to_states(temperature: float | int, unit: str) -> float: +def temperature_to_states(temperature: float, unit: str) -> float: """Convert temperature back from Celsius to Home Assistant unit.""" return ( round( diff --git a/homeassistant/components/isy994/helpers.py b/homeassistant/components/isy994/helpers.py index 8b6a4249931..3686a182fe9 100644 --- a/homeassistant/components/isy994/helpers.py +++ b/homeassistant/components/isy994/helpers.py @@ -431,7 +431,7 @@ def _categorize_programs(isy_data: IsyData, programs: Programs) -> None: def convert_isy_value_to_hass( - value: int | float | None, + value: float | None, uom: str | None, precision: int | str, fallback_precision: int | None = None, diff --git a/homeassistant/components/modbus/base_platform.py b/homeassistant/components/modbus/base_platform.py index 5c8816dd74e..9f0e862f283 100644 --- a/homeassistant/components/modbus/base_platform.py +++ b/homeassistant/components/modbus/base_platform.py @@ -202,7 +202,7 @@ class BaseStructPlatform(BasePlatform, RestoreEntity): registers.reverse() return registers - def __process_raw_value(self, entry: float | int | str | bytes) -> str | None: + def __process_raw_value(self, entry: float | str | bytes) -> str | None: """Process value from sensor with NaN handling, scaling, offset, min/max etc.""" if self._nan_value and entry in (self._nan_value, -self._nan_value): return None diff --git a/homeassistant/components/nibe_heatpump/coordinator.py b/homeassistant/components/nibe_heatpump/coordinator.py index a3d37ce0719..fc212faee71 100644 --- a/homeassistant/components/nibe_heatpump/coordinator.py +++ b/homeassistant/components/nibe_heatpump/coordinator.py @@ -136,7 +136,7 @@ class Coordinator(ContextCoordinator[dict[int, CoilData], int]): return float(value) # type: ignore[arg-type] return None - async def async_write_coil(self, coil: Coil, value: int | float | str) -> None: + async def async_write_coil(self, coil: Coil, value: float | str) -> None: """Write coil and update state.""" data = CoilData(coil, value) await self.connection.write_coil(data) @@ -224,7 +224,7 @@ class CoilEntity(CoordinatorEntity[Coordinator]): def _async_read_coil(self, data: CoilData): """Update state of entity based on coil data.""" - async def _async_write_coil(self, value: int | float | str): + async def _async_write_coil(self, value: float | str): """Write coil and update state.""" await self.coordinator.async_write_coil(self._coil, value) diff --git a/homeassistant/components/number/significant_change.py b/homeassistant/components/number/significant_change.py index ff77f25e527..14cb2246615 100644 --- a/homeassistant/components/number/significant_change.py +++ b/homeassistant/components/number/significant_change.py @@ -21,10 +21,10 @@ from .const import NumberDeviceClass def _absolute_and_relative_change( - old_state: int | float | None, - new_state: int | float | None, - absolute_change: int | float, - percentage_change: int | float, + old_state: float | None, + new_state: float | None, + absolute_change: float, + percentage_change: float, ) -> bool: return check_absolute_change( old_state, new_state, absolute_change diff --git a/homeassistant/components/sensor/significant_change.py b/homeassistant/components/sensor/significant_change.py index f320a7efcdf..00de36fc67c 100644 --- a/homeassistant/components/sensor/significant_change.py +++ b/homeassistant/components/sensor/significant_change.py @@ -20,10 +20,10 @@ from . import SensorDeviceClass def _absolute_and_relative_change( - old_state: int | float | None, - new_state: int | float | None, - absolute_change: int | float, - percentage_change: int | float, + old_state: float | None, + new_state: float | None, + absolute_change: float, + percentage_change: float, ) -> bool: return check_absolute_change( old_state, new_state, absolute_change diff --git a/homeassistant/components/sonos/diagnostics.py b/homeassistant/components/sonos/diagnostics.py index b97b03b9be2..09fe9d9db5f 100644 --- a/homeassistant/components/sonos/diagnostics.py +++ b/homeassistant/components/sonos/diagnostics.py @@ -113,7 +113,7 @@ async def async_generate_speaker_info( payload: dict[str, Any] = {} def get_contents( - item: int | float | str | dict[str, Any], + item: float | str | dict[str, Any], ) -> int | float | str | dict[str, Any]: if isinstance(item, (int, float, str)): return item diff --git a/homeassistant/components/tomorrowio/sensor.py b/homeassistant/components/tomorrowio/sensor.py index 371121a9da3..f3ca5302b2a 100644 --- a/homeassistant/components/tomorrowio/sensor.py +++ b/homeassistant/components/tomorrowio/sensor.py @@ -100,7 +100,7 @@ class TomorrowioSensorEntityDescription(SensorEntityDescription): # From https://cfpub.epa.gov/ncer_abstracts/index.cfm/fuseaction/display.files/fileID/14285 # x ug/m^3 = y ppb * molecular weight / 24.45 -def convert_ppb_to_ugm3(molecular_weight: int | float) -> Callable[[float], float]: +def convert_ppb_to_ugm3(molecular_weight: float) -> Callable[[float], float]: """Return function to convert ppb to ug/m^3.""" return lambda x: (x * molecular_weight) / 24.45 @@ -339,7 +339,7 @@ async def async_setup_entry( def handle_conversion( - value: float | int, conversion: Callable[[float], float] | float + value: float, conversion: Callable[[float], float] | float ) -> float: """Handle conversion of a value based on conversion type.""" if callable(conversion): diff --git a/homeassistant/components/tplink/light.py b/homeassistant/components/tplink/light.py index d007868930a..aa50c3f2ed2 100644 --- a/homeassistant/components/tplink/light.py +++ b/homeassistant/components/tplink/light.py @@ -228,7 +228,7 @@ class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity): await self.device.set_hsv(hue, sat, brightness, transition=transition) async def _async_set_color_temp( - self, color_temp: float | int, brightness: int | None, transition: int | None + self, color_temp: float, brightness: int | None, transition: int | None ) -> None: device = self.device valid_temperature_range = device.valid_temperature_range diff --git a/homeassistant/components/tuya/base.py b/homeassistant/components/tuya/base.py index 8ff7041fd5e..8b161f0538f 100644 --- a/homeassistant/components/tuya/base.py +++ b/homeassistant/components/tuya/base.py @@ -45,19 +45,19 @@ class IntegerTypeData: """Return the step scaled.""" return self.step / (10**self.scale) - def scale_value(self, value: float | int) -> float: + def scale_value(self, value: float) -> float: """Scale a value.""" return value / (10**self.scale) - def scale_value_back(self, value: float | int) -> int: + def scale_value_back(self, value: float) -> int: """Return raw value for scaled.""" return int(value * (10**self.scale)) def remap_value_to( self, value: float, - to_min: float | int = 0, - to_max: float | int = 255, + to_min: float = 0, + to_max: float = 255, reverse: bool = False, ) -> float: """Remap a value from this range to a new range.""" @@ -66,8 +66,8 @@ class IntegerTypeData: def remap_value_from( self, value: float, - from_min: float | int = 0, - from_max: float | int = 255, + from_min: float = 0, + from_max: float = 255, reverse: bool = False, ) -> float: """Remap a value from its current range to this range.""" diff --git a/homeassistant/components/tuya/util.py b/homeassistant/components/tuya/util.py index b6e6f17f49b..c1615b89c2d 100644 --- a/homeassistant/components/tuya/util.py +++ b/homeassistant/components/tuya/util.py @@ -4,11 +4,11 @@ from __future__ import annotations def remap_value( - value: float | int, - from_min: float | int = 0, - from_max: float | int = 255, - to_min: float | int = 0, - to_max: float | int = 255, + value: float, + from_min: float = 0, + from_max: float = 255, + to_min: float = 0, + to_max: float = 255, reverse: bool = False, ) -> float: """Remap a value from its current range, to a new range.""" diff --git a/homeassistant/components/weather/significant_change.py b/homeassistant/components/weather/significant_change.py index d36139904f5..ce7bcd15ede 100644 --- a/homeassistant/components/weather/significant_change.py +++ b/homeassistant/components/weather/significant_change.py @@ -64,7 +64,7 @@ VALID_CARDINAL_DIRECTIONS: list[str] = [ ] -def _cardinal_to_degrees(value: str | int | float | None) -> int | float | None: +def _cardinal_to_degrees(value: str | float | None) -> int | float | None: """Translate a cardinal direction into azimuth angle (degrees).""" if not isinstance(value, str): return value diff --git a/homeassistant/helpers/significant_change.py b/homeassistant/helpers/significant_change.py index 44b103e5c27..1b1f1b5c617 100644 --- a/homeassistant/helpers/significant_change.py +++ b/homeassistant/helpers/significant_change.py @@ -99,9 +99,9 @@ def either_one_none(val1: Any | None, val2: Any | None) -> bool: def _check_numeric_change( - old_state: int | float | None, - new_state: int | float | None, - change: int | float, + old_state: float | None, + new_state: float | None, + change: float, metric: Callable[[int | float, int | float], int | float], ) -> bool: """Check if two numeric values have changed.""" @@ -121,9 +121,9 @@ def _check_numeric_change( def check_absolute_change( - val1: int | float | None, - val2: int | float | None, - change: int | float, + val1: float | None, + val2: float | None, + change: float, ) -> bool: """Check if two numeric values have changed.""" return _check_numeric_change( @@ -132,13 +132,13 @@ def check_absolute_change( def check_percentage_change( - old_state: int | float | None, - new_state: int | float | None, - change: int | float, + old_state: float | None, + new_state: float | None, + change: float, ) -> bool: """Check if two numeric values have changed.""" - def percentage_change(old_state: int | float, new_state: int | float) -> float: + def percentage_change(old_state: float, new_state: float) -> float: if old_state == new_state: return 0 try: @@ -149,7 +149,7 @@ def check_percentage_change( return _check_numeric_change(old_state, new_state, change, percentage_change) -def check_valid_float(value: str | int | float) -> bool: +def check_valid_float(value: str | float) -> bool: """Check if given value is a valid float.""" try: float(value) diff --git a/pyproject.toml b/pyproject.toml index 0ab3fd23597..bda0ee4f85f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -722,7 +722,6 @@ ignore = [ # temporarily disabled "PT019", "PYI024", # Use typing.NamedTuple instead of collections.namedtuple - "PYI041", "RET503", "RET502", "RET501", diff --git a/tests/components/coolmaster/conftest.py b/tests/components/coolmaster/conftest.py index 7ddf1fd5942..15670af4bc8 100644 --- a/tests/components/coolmaster/conftest.py +++ b/tests/components/coolmaster/conftest.py @@ -64,7 +64,7 @@ class CoolMasterNetUnitMock: self._attributes["mode"] = value return CoolMasterNetUnitMock(self.unit_id, self._attributes) - async def set_thermostat(self, value: int | float) -> CoolMasterNetUnitMock: + async def set_thermostat(self, value: float) -> CoolMasterNetUnitMock: """Set the target temperature.""" self._attributes["thermostat"] = value return CoolMasterNetUnitMock(self.unit_id, self._attributes) diff --git a/tests/components/nibe_heatpump/__init__.py b/tests/components/nibe_heatpump/__init__.py index 1dbef2fe4f2..15cd9859d6e 100644 --- a/tests/components/nibe_heatpump/__init__.py +++ b/tests/components/nibe_heatpump/__init__.py @@ -50,7 +50,7 @@ class MockConnection(Connection): async def verify_connectivity(self): """Verify that we have functioning communication.""" - def mock_coil_update(self, coil_id: int, value: int | float | str | None): + def mock_coil_update(self, coil_id: int, value: float | str | None): """Trigger an out of band coil update.""" coil = self.heatpump.get_coil_by_address(coil_id) self.coils[coil_id] = value diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index 0ecb4b9c60f..9e8e401ea46 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -2630,7 +2630,7 @@ async def test_suggested_unit_guard_valid_unit( native_unit: str, native_value: int, suggested_unit: str, - expect_value: float | int, + expect_value: float, ) -> None: """Test suggested_unit_of_measurement guard. diff --git a/tests/helpers/test_template.py b/tests/helpers/test_template.py index 54fdf0368eb..87279ef707b 100644 --- a/tests/helpers/test_template.py +++ b/tests/helpers/test_template.py @@ -1176,7 +1176,7 @@ def test_as_datetime(hass: HomeAssistant, input) -> None: ) def test_as_datetime_from_timestamp( hass: HomeAssistant, - input: int | float, + input: float, output: str, ) -> None: """Test converting a UNIX timestamp to a date object."""