Enable strict typing for HEOS (#136797)

This commit is contained in:
Andrew Sayre 2025-01-29 00:28:13 -06:00 committed by GitHub
parent a2b5a96bc9
commit a135b4bb43
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 21 additions and 7 deletions

View File

@ -228,6 +228,7 @@ homeassistant.components.guardian.*
homeassistant.components.habitica.* homeassistant.components.habitica.*
homeassistant.components.hardkernel.* homeassistant.components.hardkernel.*
homeassistant.components.hardware.* homeassistant.components.hardware.*
homeassistant.components.heos.*
homeassistant.components.here_travel_time.* homeassistant.components.here_travel_time.*
homeassistant.components.history.* homeassistant.components.history.*
homeassistant.components.history_stats.* homeassistant.components.history_stats.*

View File

@ -40,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: HeosConfigEntry) -> bool
): ):
for domain, player_id in device.identifiers: for domain, player_id in device.identifiers:
if domain == DOMAIN and not isinstance(player_id, str): 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))} device.id, new_identifiers={(DOMAIN, str(player_id))}
) )
break break

View File

@ -8,6 +8,7 @@ entities to update. Entities subscribe to entity-specific updates within the ent
from collections.abc import Callable, Sequence from collections.abc import Callable, Sequence
from datetime import datetime, timedelta from datetime import datetime, timedelta
import logging import logging
from typing import Any
from pyheos import ( from pyheos import (
Credentials, Credentials,
@ -23,7 +24,7 @@ from pyheos import (
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME, Platform 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.exceptions import ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr, entity_registry as er from homeassistant.helpers import device_registry as dr, entity_registry as er
from homeassistant.helpers.event import async_call_later from homeassistant.helpers.event import async_call_later
@ -106,7 +107,9 @@ class HeosCoordinator(DataUpdateCoordinator[None]):
await self.heos.disconnect() await self.heos.disconnect()
await super().async_shutdown() 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.""" """Add a listener for the coordinator."""
remove_listener = super().async_add_listener(update_callback, context) remove_listener = super().async_add_listener(update_callback, context)
# Update entities so group_member entity_ids fully populate. # Update entities so group_member entity_ids fully populate.

View File

@ -135,7 +135,7 @@ class HeosMediaPlayer(CoordinatorEntity[HeosCoordinator], MediaPlayerEntity):
def __init__(self, coordinator: HeosCoordinator, player: HeosPlayer) -> None: def __init__(self, coordinator: HeosCoordinator, player: HeosPlayer) -> None:
"""Initialize.""" """Initialize."""
self._media_position_updated_at = None self._media_position_updated_at: datetime | None = None
self._player: HeosPlayer = player self._player: HeosPlayer = player
self._attr_unique_id = str(player.player_id) self._attr_unique_id = str(player.player_id)
model_parts = player.model.split(maxsplit=1) model_parts = player.model.split(maxsplit=1)
@ -151,7 +151,7 @@ class HeosMediaPlayer(CoordinatorEntity[HeosCoordinator], MediaPlayerEntity):
) )
super().__init__(coordinator, context=player.player_id) 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.""" """Handle player attribute updated."""
if event == heos_const.EVENT_PLAYER_NOW_PLAYING_PROGRESS: if event == heos_const.EVENT_PLAYER_NOW_PLAYING_PROGRESS:
self._media_position_updated_at = utcnow() self._media_position_updated_at = utcnow()

View File

@ -64,4 +64,4 @@ rules:
inject-websession: inject-websession:
status: done status: done
comment: The integration does not use websession comment: The integration does not use websession
strict-typing: todo strict-typing: done

View File

@ -28,7 +28,7 @@ HEOS_SIGN_IN_SCHEMA = vol.Schema(
HEOS_SIGN_OUT_SCHEMA = vol.Schema({}) HEOS_SIGN_OUT_SCHEMA = vol.Schema({})
def register(hass: HomeAssistant): def register(hass: HomeAssistant) -> None:
"""Register HEOS services.""" """Register HEOS services."""
hass.services.async_register( hass.services.async_register(
DOMAIN, DOMAIN,

10
mypy.ini generated
View File

@ -2036,6 +2036,16 @@ disallow_untyped_defs = true
warn_return_any = true warn_return_any = true
warn_unreachable = 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.*] [mypy-homeassistant.components.here_travel_time.*]
check_untyped_defs = true check_untyped_defs = true
disallow_incomplete_defs = true disallow_incomplete_defs = true