Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _parse_audio_mime_type(mime_type: str) -> dict[str, int]:
integers if found, otherwise None.

"""
if not mime_type.startswith("audio/L"):
if not mime_type.lower().startswith("audio/l"):
LOGGER.warning("Received unexpected MIME type %s", mime_type)
raise HomeAssistantError(f"Unsupported audio MIME type: {mime_type}")

Expand All @@ -65,9 +65,9 @@ def _parse_audio_mime_type(mime_type: str) -> dict[str, int]:
with suppress(ValueError, IndexError):
rate_str = param.split("=", 1)[1]
rate = int(rate_str)
elif param.startswith("audio/L"):
elif param.lower().startswith("audio/l"):
# Keep bits_per_sample as default if conversion fails
with suppress(ValueError, IndexError):
bits_per_sample = int(param.split("L", 1)[1])
bits_per_sample = int(param.upper().split("L", 1)[1])

return {"bits_per_sample": bits_per_sample, "rate": rate}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Tests for the Google Generative AI Conversation helpers."""

from __future__ import annotations

import pytest

from homeassistant.components.google_generative_ai_conversation.helpers import (
_parse_audio_mime_type,
)
from homeassistant.exceptions import HomeAssistantError


def test_parse_audio_mime_type_uppercase() -> None:
"""Test parsing uppercase MIME type audio/L16;rate=24000."""
result = _parse_audio_mime_type("audio/L16;rate=24000")
assert result == {"bits_per_sample": 16, "rate": 24000}


def test_parse_audio_mime_type_lowercase() -> None:
"""Test parsing lowercase MIME type audio/l16; rate=24000; channels=1."""
result = _parse_audio_mime_type("audio/l16; rate=24000; channels=1")
assert result == {"bits_per_sample": 16, "rate": 24000}


def test_parse_audio_mime_type_unsupported_raises() -> None:
"""Test that an unsupported MIME type raises HomeAssistantError."""
with pytest.raises(HomeAssistantError):
_parse_audio_mime_type("video/mp4")
Loading