mypy fixes for Hass Players (#2452)
authorOzGav <gavnosp@hotmail.com>
Sun, 5 Oct 2025 18:30:05 +0000 (04:30 +1000)
committerGitHub <noreply@github.com>
Sun, 5 Oct 2025 18:30:05 +0000 (20:30 +0200)
music_assistant/providers/hass_players/player.py
music_assistant/providers/hass_players/provider.py
pyproject.toml

index 89c011cbf0d593d7ae766de004c39c2d34f710a7..4a218ee2e9387fa61e925b34e88257d631224401 100644 (file)
@@ -109,7 +109,7 @@ class HomeAssistantPlayer(Player):
     async def get_config_entries(self) -> list[ConfigEntry]:
         """Return all (provider/player specific) Config Entries for the player."""
         base_entries = await super().get_config_entries()
-        base_entries = (*base_entries, *DEFAULT_PLAYER_CONFIG_ENTRIES)
+        base_entries = [*base_entries, *DEFAULT_PLAYER_CONFIG_ENTRIES]
         if self.extra_data.get("esphome_supported_audio_formats"):
             # optimized config for new ESPHome mediaplayer
             supported_sample_rates: list[int] = []
@@ -133,32 +133,42 @@ class HomeAssistantPlayer(Player):
                 # simply use the default config of the media pipeline
                 supported_sample_rates = [48000]
                 supported_bit_depths = [16]
-            return [
+
+            config_entries = [
                 *base_entries,
                 # New ESPHome mediaplayer (used in Voice PE) uses FLAC 48khz/16 bits
                 CONF_ENTRY_FLOW_MODE_ENFORCED,
                 CONF_ENTRY_HTTP_PROFILE_FORCED_2,
-                create_output_codec_config_entry(True, codec),
-                CONF_ENTRY_ENABLE_ICY_METADATA_HIDDEN,
-                create_sample_rates_config_entry(
-                    supported_sample_rates=supported_sample_rates,
-                    supported_bit_depths=supported_bit_depths,
-                    hidden=True,
-                ),
-                # although the Voice PE supports announcements,
-                # it does not support volume for announcements
-                *HIDDEN_ANNOUNCE_VOLUME_CONFIG_ENTRIES,
             ]
 
+            if codec is not None:
+                config_entries.append(create_output_codec_config_entry(True, codec))
+
+            config_entries.extend(
+                [
+                    CONF_ENTRY_ENABLE_ICY_METADATA_HIDDEN,
+                    create_sample_rates_config_entry(
+                        supported_sample_rates=supported_sample_rates,
+                        supported_bit_depths=supported_bit_depths,
+                        hidden=True,
+                    ),
+                    # although the Voice PE supports announcements,
+                    # it does not support volume for announcements
+                    *HIDDEN_ANNOUNCE_VOLUME_CONFIG_ENTRIES,
+                ]
+            )
+
+            return config_entries
+
         # add alert if player is a known player type that has a native provider in MA
         if self.extra_data.get("hass_domain") in WARN_HASS_INTEGRATIONS:
-            base_entries = (CONF_ENTRY_WARN_HASS_INTEGRATION, *base_entries)
+            base_entries = [CONF_ENTRY_WARN_HASS_INTEGRATION, *base_entries]
 
         # enable flow mode by default if player does not report enqueue support
         if MediaPlayerEntityFeature.MEDIA_ENQUEUE not in self.extra_data["hass_supported_features"]:
-            base_entries = (*base_entries, CONF_ENTRY_FLOW_MODE_DEFAULT_ENABLED)
+            base_entries = [*base_entries, CONF_ENTRY_FLOW_MODE_DEFAULT_ENABLED]
 
-        return list(base_entries)
+        return base_entries
 
     async def play(self) -> None:
         """Handle PLAY command on the player."""
@@ -223,7 +233,7 @@ class HomeAssistantPlayer(Player):
 
     async def play_media(self, media: PlayerMedia) -> None:
         """Handle PLAY MEDIA on given player."""
-        extra_data = {
+        extra_data: dict[str, Any] = {
             # passing metadata to the player
             # so far only supported by google cast, but maybe others can follow
             "metadata": {
index aa33ca091643413c9ed0bed75d24f0457b23c28e..4b6f10b68a38f4ea7178d3355b4a887296dfa71c 100644 (file)
@@ -7,6 +7,7 @@ Requires the Home Assistant Plugin.
 
 from __future__ import annotations
 
+from collections.abc import Callable
 from typing import TYPE_CHECKING, Any, cast
 
 from music_assistant.mass import MusicAssistant
@@ -31,7 +32,7 @@ class HomeAssistantPlayerProvider(PlayerProvider):
     """Home Assistant PlayerProvider for Music Assistant."""
 
     hass_prov: HomeAssistantProvider
-    on_unload_callbacks: list[callable] | None = None
+    on_unload_callbacks: list[Callable[[], None]] | None = None
 
     def __init__(
         self,
index f1d73c73fae156ceed926f10b0c6ced9dff3e93d..cfbf1cd4d5d49e04b84fff9cbc28e818bf18c4d3 100644 (file)
@@ -144,7 +144,6 @@ exclude = [
   '^music_assistant/providers/apple_music/.*$',
   '^music_assistant/providers/bluesound/.*$',
   '^music_assistant/providers/chromecast/.*$',
-  '^music_assistant/providers/hass_players/.*$',
   '^music_assistant/providers/player_group/.*$',
   '^music_assistant/providers/qobuz/.*$',
   '^music_assistant/providers/siriusxm/.*$',