Fix: always use fallback default supported samplerate for esphome player
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 8 Mar 2025 00:31:38 +0000 (01:31 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Sat, 8 Mar 2025 00:35:51 +0000 (01:35 +0100)
music_assistant/constants.py
music_assistant/providers/hass_players/__init__.py

index 53f5b571b62d0f576729cf1184078daf41bb3c54..459c1e8c384771d0ed5cbc0cd78d01a12735a60c 100644 (file)
@@ -569,6 +569,11 @@ def create_sample_rates_config_entry(
 ) -> ConfigEntry:
     """Create sample rates config entry based on player specific helpers."""
     assert CONF_ENTRY_SAMPLE_RATES.options
+    # if no supported sample rates are defined, we apply the default 44100 as only option
+    if not supported_sample_rates and max_sample_rate is None:
+        supported_sample_rates = [44100]
+    if not supported_bit_depths and max_bit_depth is None:
+        supported_bit_depths = [16]
     final_supported_sample_rates = supported_sample_rates or []
     final_supported_bit_depths = supported_bit_depths or []
     conf_entry = ConfigEntry.from_dict(CONF_ENTRY_SAMPLE_RATES.to_dict())
@@ -576,11 +581,6 @@ def create_sample_rates_config_entry(
     options: list[ConfigValueOption] = []
     default_value: list[str] = []
 
-    if not supported_sample_rates and max_sample_rate is None:
-        supported_sample_rates = [44100]
-    if not supported_bit_depths and max_bit_depth is None:
-        supported_bit_depths = [16]
-
     for option in CONF_ENTRY_SAMPLE_RATES.options:
         option_value = cast(str, option.value)
         sample_rate_str, bit_depth_str = option_value.split(MULTI_VALUE_SPLITTER, 1)
index 42bccb2d1a4d08bcf960253c743a988690d87706..b408ed1e0808f0be27a331a129bd20e70f0a39e8 100644 (file)
@@ -216,7 +216,11 @@ class HomeAssistantPlayers(PlayerProvider):
                 bit_depth = supported_format["sample_bytes"] * 8
                 if bit_depth not in supported_bit_depths:
                     supported_bit_depths.append(bit_depth)
-
+            if not supported_sample_rates:
+                # esphome device with no media pipeline configured
+                # simply use the default config of the media pipeline
+                supported_sample_rates = [48000]
+                supported_bit_depths = [16]
             return (
                 *base_entries,
                 # New ESPHome mediaplayer (used in Voice PE) uses FLAC 48khz/16 bits