From a135b4bb432ec47c1900771277fc5dab2acd970e Mon Sep 17 00:00:00 2001 From: Andrew Sayre <6730289+andrewsayre@users.noreply.github.com> Date: Wed, 29 Jan 2025 00:28:13 -0600 Subject: [PATCH] Enable strict typing for HEOS (#136797) --- .strict-typing | 1 + homeassistant/components/heos/__init__.py | 2 +- homeassistant/components/heos/coordinator.py | 7 +++++-- homeassistant/components/heos/media_player.py | 4 ++-- homeassistant/components/heos/quality_scale.yaml | 2 +- homeassistant/components/heos/services.py | 2 +- mypy.ini | 10 ++++++++++ 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.strict-typing b/.strict-typing index 1a5450d8eb4..4cebcb6f445 100644 --- a/.strict-typing +++ b/.strict-typing @@ -228,6 +228,7 @@ homeassistant.components.guardian.* homeassistant.components.habitica.* homeassistant.components.hardkernel.* homeassistant.components.hardware.* +homeassistant.components.heos.* homeassistant.components.here_travel_time.* homeassistant.components.history.* homeassistant.components.history_stats.* diff --git a/homeassistant/components/heos/__init__.py b/homeassistant/components/heos/__init__.py index b119ea83064..f76b95c271e 100644 --- a/homeassistant/components/heos/__init__.py +++ b/homeassistant/components/heos/__init__.py @@ -40,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool ): for domain, player_id in device.identifiers: if domain == DOMAIN and not isinstance(player_id, str): - device_registry.async_update_device( + device_registry.async_update_device( # type: ignore[unreachable] device.id, new_identifiers={(DOMAIN, str(player_id))} ) break diff --git a/homeassistant/components/heos/coordinator.py b/homeassistant/components/heos/coordinator.py index dd0e0a19d0b..dc8989fd55b 100644 --- a/homeassistant/components/heos/coordinator.py +++ b/homeassistant/components/heos/coordinator.py @@ -8,6 +8,7 @@ entities to update. Entities subscribe to entity-specific updates within the ent from collections.abc import Callable, Sequence from datetime import datetime, timedelta import logging +from typing import Any from pyheos import ( Credentials, @@ -23,7 +24,7 @@ from pyheos import ( from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform -from homeassistant.core import HassJob, HomeAssistant, callback +from homeassistant.core import CALLBACK_TYPE, HassJob, HomeAssistant, callback from homeassistant.exceptions import ConfigEntryNotReady from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers.event import async_call_later @@ -106,7 +107,9 @@ class HeosCoordinator(DataUpdateCoordinator[None]): await self.heos.disconnect() await super().async_shutdown() - def async_add_listener(self, update_callback, context=None) -> Callable[[], None]: + def async_add_listener( + self, update_callback: CALLBACK_TYPE, context: Any = None + ) -> Callable[[], None]: """Add a listener for the coordinator.""" remove_listener = super().async_add_listener(update_callback, context) # Update entities so group_member entity_ids fully populate. diff --git a/homeassistant/components/heos/media_player.py b/homeassistant/components/heos/media_player.py index 2f0945635c5..b53cb94d8e7 100644 --- a/homeassistant/components/heos/media_player.py +++ b/homeassistant/components/heos/media_player.py @@ -135,7 +135,7 @@ class HeosMediaPlayer(CoordinatorEntity[HeosCoordinator], MediaPlayerEntity): def __init__(self, coordinator: HeosCoordinator, player: HeosPlayer) -> None: """Initialize.""" - self._media_position_updated_at = None + self._media_position_updated_at: datetime | None = None self._player: HeosPlayer = player self._attr_unique_id = str(player.player_id) model_parts = player.model.split(maxsplit=1) @@ -151,7 +151,7 @@ class HeosMediaPlayer(CoordinatorEntity[HeosCoordinator], MediaPlayerEntity): ) super().__init__(coordinator, context=player.player_id) - async def _player_update(self, event): + async def _player_update(self, event: str) -> None: """Handle player attribute updated.""" if event == heos_const.EVENT_PLAYER_NOW_PLAYING_PROGRESS: self._media_position_updated_at = utcnow() diff --git a/homeassistant/components/heos/quality_scale.yaml b/homeassistant/components/heos/quality_scale.yaml index cc110c627f0..f5066d0a743 100644 --- a/homeassistant/components/heos/quality_scale.yaml +++ b/homeassistant/components/heos/quality_scale.yaml @@ -64,4 +64,4 @@ rules: inject-websession: status: done comment: The integration does not use websession - strict-typing: todo + strict-typing: done diff --git a/homeassistant/components/heos/services.py b/homeassistant/components/heos/services.py index 4dc3b247707..dc11bb7a76d 100644 --- a/homeassistant/components/heos/services.py +++ b/homeassistant/components/heos/services.py @@ -28,7 +28,7 @@ HEOS_SIGN_IN_SCHEMA = vol.Schema( HEOS_SIGN_OUT_SCHEMA = vol.Schema({}) -def register(hass: HomeAssistant): +def register(hass: HomeAssistant) -> None: """Register HEOS services.""" hass.services.async_register( DOMAIN, diff --git a/mypy.ini b/mypy.ini index 2139449ba8d..ddc5589dc09 100644 --- a/mypy.ini +++ b/mypy.ini @@ -2036,6 +2036,16 @@ disallow_untyped_defs = true warn_return_any = true warn_unreachable = true +[mypy-homeassistant.components.heos.*] +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.here_travel_time.*] check_untyped_defs = true disallow_incomplete_defs = true