From 3b4b36a9fddcbbaadf715043c8303f5428956e12 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Fri, 24 May 2024 10:24:18 +0200 Subject: [PATCH] Fix partial typing (#118022) --- .../devolo_home_control/__init__.py | 2 +- homeassistant/components/energy/validate.py | 26 +++++++++++-------- .../components/websocket_api/commands.py | 6 ++--- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/homeassistant/components/devolo_home_control/__init__.py b/homeassistant/components/devolo_home_control/__init__.py index 8795c9005a2..7755e0f22b4 100644 --- a/homeassistant/components/devolo_home_control/__init__.py +++ b/homeassistant/components/devolo_home_control/__init__.py @@ -62,7 +62,7 @@ async def async_setup_entry( await hass.async_add_executor_job( partial( HomeControl, - gateway_id=gateway_id, + gateway_id=str(gateway_id), mydevolo_instance=mydevolo, zeroconf_instance=zeroconf_instance, ) diff --git a/homeassistant/components/energy/validate.py b/homeassistant/components/energy/validate.py index 2d34f606653..cfacbe48b97 100644 --- a/homeassistant/components/energy/validate.py +++ b/homeassistant/components/energy/validate.py @@ -20,7 +20,7 @@ from . import data from .const import DOMAIN ENERGY_USAGE_DEVICE_CLASSES = (sensor.SensorDeviceClass.ENERGY,) -ENERGY_USAGE_UNITS = { +ENERGY_USAGE_UNITS: dict[str, tuple[UnitOfEnergy, ...]] = { sensor.SensorDeviceClass.ENERGY: ( UnitOfEnergy.GIGA_JOULE, UnitOfEnergy.KILO_WATT_HOUR, @@ -38,7 +38,7 @@ GAS_USAGE_DEVICE_CLASSES = ( sensor.SensorDeviceClass.ENERGY, sensor.SensorDeviceClass.GAS, ) -GAS_USAGE_UNITS = { +GAS_USAGE_UNITS: dict[str, tuple[UnitOfEnergy | UnitOfVolume, ...]] = { sensor.SensorDeviceClass.ENERGY: ( UnitOfEnergy.GIGA_JOULE, UnitOfEnergy.KILO_WATT_HOUR, @@ -58,7 +58,7 @@ GAS_PRICE_UNITS = tuple( GAS_UNIT_ERROR = "entity_unexpected_unit_gas" GAS_PRICE_UNIT_ERROR = "entity_unexpected_unit_gas_price" WATER_USAGE_DEVICE_CLASSES = (sensor.SensorDeviceClass.WATER,) -WATER_USAGE_UNITS = { +WATER_USAGE_UNITS: dict[str, tuple[UnitOfVolume, ...]] = { sensor.SensorDeviceClass.WATER: ( UnitOfVolume.CENTUM_CUBIC_FEET, UnitOfVolume.CUBIC_FEET, @@ -360,12 +360,14 @@ async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation: source_result, ) ) - elif flow.get("entity_energy_price") is not None: + elif ( + entity_energy_price := flow.get("entity_energy_price") + ) is not None: validate_calls.append( functools.partial( _async_validate_price_entity, hass, - flow["entity_energy_price"], + entity_energy_price, source_result, ENERGY_PRICE_UNITS, ENERGY_PRICE_UNIT_ERROR, @@ -411,12 +413,14 @@ async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation: source_result, ) ) - elif flow.get("entity_energy_price") is not None: + elif ( + entity_energy_price := flow.get("entity_energy_price") + ) is not None: validate_calls.append( functools.partial( _async_validate_price_entity, hass, - flow["entity_energy_price"], + entity_energy_price, source_result, ENERGY_PRICE_UNITS, ENERGY_PRICE_UNIT_ERROR, @@ -462,12 +466,12 @@ async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation: source_result, ) ) - elif source.get("entity_energy_price") is not None: + elif (entity_energy_price := source.get("entity_energy_price")) is not None: validate_calls.append( functools.partial( _async_validate_price_entity, hass, - source["entity_energy_price"], + entity_energy_price, source_result, GAS_PRICE_UNITS, GAS_PRICE_UNIT_ERROR, @@ -513,12 +517,12 @@ async def async_validate(hass: HomeAssistant) -> EnergyPreferencesValidation: source_result, ) ) - elif source.get("entity_energy_price") is not None: + elif (entity_energy_price := source.get("entity_energy_price")) is not None: validate_calls.append( functools.partial( _async_validate_price_entity, hass, - source["entity_energy_price"], + entity_energy_price, source_result, WATER_PRICE_UNITS, WATER_PRICE_UNIT_ERROR, diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index 13b51fda9d6..e159880c8bc 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -103,7 +103,7 @@ def pong_message(iden: int) -> dict[str, Any]: @callback def _forward_events_check_permissions( - send_message: Callable[[bytes | str | dict[str, Any] | Callable[[], str]], None], + send_message: Callable[[bytes | str | dict[str, Any]], None], user: User, message_id_as_bytes: bytes, event: Event, @@ -123,7 +123,7 @@ def _forward_events_check_permissions( @callback def _forward_events_unconditional( - send_message: Callable[[bytes | str | dict[str, Any] | Callable[[], str]], None], + send_message: Callable[[bytes | str | dict[str, Any]], None], message_id_as_bytes: bytes, event: Event, ) -> None: @@ -365,7 +365,7 @@ def _send_handle_get_states_response( @callback def _forward_entity_changes( - send_message: Callable[[str | bytes | dict[str, Any] | Callable[[], str]], None], + send_message: Callable[[str | bytes | dict[str, Any]], None], entity_ids: set[str], user: User, message_id_as_bytes: bytes,