Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exception handling in Microsoft TTS #92556

Merged
merged 1 commit into from
May 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions homeassistant/components/microsoft/tts.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Support for the Microsoft Cognitive Services text-to-speech service."""
from http.client import HTTPException
import logging

from pycsspeechtts import pycsspeechtts
from requests.exceptions import HTTPError
import voluptuous as vol

from homeassistant.components.tts import CONF_LANG, PLATFORM_SCHEMA, Provider
Expand Down Expand Up @@ -194,7 +194,7 @@ def get_tts_audio(self, message, language, options):
contour=self._contour,
text=message,
)
except HTTPException as ex:
except HTTPError as ex:
_LOGGER.error("Error occurred for Microsoft TTS: %s", ex)
return (None, None)
return ("mp3", data)
6 changes: 2 additions & 4 deletions tests/components/microsoft/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from pycsspeechtts import pycsspeechtts
import pytest
from requests import HTTPError

from homeassistant.components import media_source, tts
from homeassistant.components.media_player import (
Expand All @@ -14,7 +13,7 @@
from homeassistant.components.microsoft.tts import SUPPORTED_LANGUAGES
from homeassistant.config import async_process_ha_core_config
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ServiceNotFound
from homeassistant.exceptions import HomeAssistantError, ServiceNotFound
from homeassistant.setup import async_setup_component

from tests.common import async_mock_service
Expand Down Expand Up @@ -231,7 +230,6 @@ async def test_service_say_error(hass: HomeAssistant, mock_tts, calls) -> None:
)

assert len(calls) == 1
# Note: the integration currently catches HTTPException instead of HTTPError.
with pytest.raises(HTTPError):
with pytest.raises(HomeAssistantError):
await get_media_source_url(hass, calls[0].data[ATTR_MEDIA_CONTENT_ID])
assert len(mock_tts.mock_calls) == 2