Add Home Connect to .strict-typing (#138799)

* Add Home Connect to .strict-typing

* Fix mypy errors
This commit is contained in:
J. Diego Rodríguez Royo
2025-02-18 21:50:19 +01:00
committed by GitHub
parent 8ae52cdc4c
commit 141bcae793
5 changed files with 31 additions and 14 deletions

View File

@ -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.*

View File

@ -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)

View File

@ -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"])

View File

@ -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()

10
mypy.ini generated
View File

@ -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