Fix: handle missing sample_bytes in esphome config
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 25 Apr 2025 23:04:14 +0000 (01:04 +0200)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Fri, 25 Apr 2025 23:04:14 +0000 (01:04 +0200)
music_assistant/providers/hass_players/__init__.py

index 60b307bba417926b3b427d054f191c361172c323..bbdcb4fa7df28cc3a051ee66c67f37ea96fdca8e 100644 (file)
@@ -223,10 +223,10 @@ class HomeAssistantPlayers(PlayerProvider):
                 codec = supported_format["format"]
                 if supported_format["sample_rate"] not in supported_sample_rates:
                     supported_sample_rates.append(supported_format["sample_rate"])
-                bit_depth = supported_format["sample_bytes"] * 8
+                bit_depth = (supported_format["sample_bytes"] or 2) * 8
                 if bit_depth not in supported_bit_depths:
                     supported_bit_depths.append(bit_depth)
-            if not supported_sample_rates:
+            if not supported_sample_rates or not supported_bit_depths:
                 # esphome device with no media pipeline configured
                 # simply use the default config of the media pipeline
                 supported_sample_rates = [48000]