From 141bcae79345998f3b632c19d94594f49454a719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20Diego=20Rodr=C3=ADguez=20Royo?= Date: Tue, 18 Feb 2025 21:50:19 +0100 Subject: [PATCH] Add Home Connect to .strict-typing (#138799) * Add Home Connect to .strict-typing * Fix mypy errors --- .strict-typing | 1 + .../components/home_connect/__init__.py | 26 +++++++++++-------- homeassistant/components/home_connect/api.py | 4 ++- .../components/home_connect/coordinator.py | 4 +-- mypy.ini | 10 +++++++ 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/.strict-typing b/.strict-typing index 1e3187980cc..9543ccc3989 100644 --- a/.strict-typing +++ b/.strict-typing @@ -234,6 +234,7 @@ homeassistant.components.here_travel_time.* homeassistant.components.history.* homeassistant.components.history_stats.* homeassistant.components.holiday.* +homeassistant.components.home_connect.* homeassistant.components.homeassistant.* homeassistant.components.homeassistant_alerts.* homeassistant.components.homeassistant_green.* diff --git a/homeassistant/components/home_connect/__init__.py b/homeassistant/components/home_connect/__init__.py index a020b2370b9..b4ceb11be92 100644 --- a/homeassistant/components/home_connect/__init__.py +++ b/homeassistant/components/home_connect/__init__.py @@ -237,7 +237,7 @@ async def _get_client_and_ha_id( async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: C901 """Set up Home Connect component.""" - async def _async_service_program(call: ServiceCall, start: bool): + async def _async_service_program(call: ServiceCall, start: bool) -> None: """Execute calls to services taking a program.""" program = call.data[ATTR_PROGRAM] client, ha_id = await _get_client_and_ha_id(hass, call.data[ATTR_DEVICE_ID]) @@ -323,7 +323,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: }, ) from err - async def _async_service_set_program_options(call: ServiceCall, active: bool): + async def _async_service_set_program_options( + call: ServiceCall, active: bool + ) -> None: """Execute calls to services taking a program.""" option_key = call.data[ATTR_KEY] value = call.data[ATTR_VALUE] @@ -396,7 +398,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: }, ) from err - async def _async_service_command(call: ServiceCall, command_key: CommandKey): + async def _async_service_command( + call: ServiceCall, command_key: CommandKey + ) -> None: """Execute calls to services executing a command.""" client, ha_id = await _get_client_and_ha_id(hass, call.data[ATTR_DEVICE_ID]) @@ -412,15 +416,15 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: }, ) from err - async def async_service_option_active(call: ServiceCall): + async def async_service_option_active(call: ServiceCall) -> None: """Service for setting an option for an active program.""" await _async_service_set_program_options(call, True) - async def async_service_option_selected(call: ServiceCall): + async def async_service_option_selected(call: ServiceCall) -> None: """Service for setting an option for a selected program.""" await _async_service_set_program_options(call, False) - async def async_service_setting(call: ServiceCall): + async def async_service_setting(call: ServiceCall) -> None: """Service for changing a setting.""" key = call.data[ATTR_KEY] value = call.data[ATTR_VALUE] @@ -439,19 +443,19 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: }, ) from err - async def async_service_pause_program(call: ServiceCall): + async def async_service_pause_program(call: ServiceCall) -> None: """Service for pausing a program.""" await _async_service_command(call, CommandKey.BSH_COMMON_PAUSE_PROGRAM) - async def async_service_resume_program(call: ServiceCall): + async def async_service_resume_program(call: ServiceCall) -> None: """Service for resuming a paused program.""" await _async_service_command(call, CommandKey.BSH_COMMON_RESUME_PROGRAM) - async def async_service_select_program(call: ServiceCall): + async def async_service_select_program(call: ServiceCall) -> None: """Service for selecting a program.""" await _async_service_program(call, False) - async def async_service_set_program_and_options(call: ServiceCall): + async def async_service_set_program_and_options(call: ServiceCall) -> None: """Service for setting a program and options.""" data = dict(call.data) program = data.pop(ATTR_PROGRAM, None) @@ -521,7 +525,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: # noqa: }, ) from err - async def async_service_start_program(call: ServiceCall): + async def async_service_start_program(call: ServiceCall) -> None: """Service for starting a program.""" await _async_service_program(call, True) diff --git a/homeassistant/components/home_connect/api.py b/homeassistant/components/home_connect/api.py index 5d711dae032..b66236c367d 100644 --- a/homeassistant/components/home_connect/api.py +++ b/homeassistant/components/home_connect/api.py @@ -1,5 +1,7 @@ """API for Home Connect bound to HASS OAuth.""" +from typing import cast + from aiohomeconnect.client import AbstractAuth from aiohomeconnect.const import API_ENDPOINT @@ -25,4 +27,4 @@ class AsyncConfigEntryAuth(AbstractAuth): """Return a valid access token.""" await self.session.async_ensure_token_valid() - return self.session.token["access_token"] + return cast(str, self.session.token["access_token"]) diff --git a/homeassistant/components/home_connect/coordinator.py b/homeassistant/components/home_connect/coordinator.py index da47d8ec91c..ceedde7fe72 100644 --- a/homeassistant/components/home_connect/coordinator.py +++ b/homeassistant/components/home_connect/coordinator.py @@ -254,7 +254,7 @@ class HomeConnectCoordinator( await self.async_refresh() @callback - def _call_event_listener(self, event_message: EventMessage): + def _call_event_listener(self, event_message: EventMessage) -> None: """Call listener for event.""" for event in event_message.data.items: for listener in self.context_listeners.get( @@ -263,7 +263,7 @@ class HomeConnectCoordinator( listener() @callback - def _call_all_event_listeners_for_appliance(self, ha_id: str): + def _call_all_event_listeners_for_appliance(self, ha_id: str) -> None: for listener, context in self._listeners.values(): if isinstance(context, tuple) and context[0] == ha_id: listener() diff --git a/mypy.ini b/mypy.ini index 2d9821b1c64..f15ad433a52 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2096,6 +2096,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.home_connect.*] +check_untyped_defs = true +disallow_incomplete_defs = true +disallow_subclassing_any = true +disallow_untyped_calls = true +disallow_untyped_decorators = true +disallow_untyped_defs = true +warn_return_any = true +warn_unreachable = true + [mypy-homeassistant.components.homeassistant.*] check_untyped_defs = true disallow_incomplete_defs = true