mirror of
https://github.com/home-assistant/core
synced 2024-07-21 10:44:07 +00:00
Improve Bang & Olufsen error messages (#120587)
* Convert logger messages to raised errors where applicable * Modify exception types * Improve deezer / tidal error message * Update homeassistant/components/bang_olufsen/strings.json Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com> * Update homeassistant/components/bang_olufsen/media_player.py Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com> --------- Co-authored-by: Michael <35783820+mib1185@users.noreply.github.com>
This commit is contained in:
parent
9b2915efed
commit
2146a4729b
|
@ -45,7 +45,7 @@ from homeassistant.components.media_player import (
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import CONF_MODEL
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.exceptions import HomeAssistantError, ServiceValidationError
|
||||
from homeassistant.helpers.device_registry import DeviceInfo
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
|
@ -316,7 +316,7 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
|||
@callback
|
||||
def _async_update_playback_error(self, data: PlaybackError) -> None:
|
||||
"""Show playback error."""
|
||||
_LOGGER.error(data.error)
|
||||
raise HomeAssistantError(data.error)
|
||||
|
||||
@callback
|
||||
def _async_update_playback_progress(self, data: PlaybackProgress) -> None:
|
||||
|
@ -516,7 +516,9 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
|||
|
||||
self.async_write_ha_state()
|
||||
else:
|
||||
_LOGGER.error("Seeking is currently only supported when using Deezer")
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN, translation_key="non_deezer_seeking"
|
||||
)
|
||||
|
||||
async def async_media_previous_track(self) -> None:
|
||||
"""Send the previous track command."""
|
||||
|
@ -529,12 +531,14 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
|||
async def async_select_source(self, source: str) -> None:
|
||||
"""Select an input source."""
|
||||
if source not in self._sources.values():
|
||||
_LOGGER.error(
|
||||
"Invalid source: %s. Valid sources are: %s",
|
||||
source,
|
||||
list(self._sources.values()),
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="invalid_source",
|
||||
translation_placeholders={
|
||||
"invalid_source": source,
|
||||
"valid_sources": ",".join(list(self._sources.values())),
|
||||
},
|
||||
)
|
||||
return
|
||||
|
||||
key = [x for x in self._sources if self._sources[x] == source][0]
|
||||
|
||||
|
@ -559,12 +563,14 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
|||
media_type = MediaType.MUSIC
|
||||
|
||||
if media_type not in VALID_MEDIA_TYPES:
|
||||
_LOGGER.error(
|
||||
"%s is an invalid type. Valid values are: %s",
|
||||
media_type,
|
||||
VALID_MEDIA_TYPES,
|
||||
raise ServiceValidationError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="invalid_media_type",
|
||||
translation_placeholders={
|
||||
"invalid_media_type": media_type,
|
||||
"valid_media_types": ",".join(VALID_MEDIA_TYPES),
|
||||
},
|
||||
)
|
||||
return
|
||||
|
||||
if media_source.is_media_source_id(media_id):
|
||||
sourced_media = await media_source.async_resolve_media(
|
||||
|
@ -681,7 +687,14 @@ class BangOlufsenMediaPlayer(BangOlufsenEntity, MediaPlayerEntity):
|
|||
)
|
||||
|
||||
except ApiException as error:
|
||||
_LOGGER.error(json.loads(error.body)["message"])
|
||||
raise HomeAssistantError(
|
||||
translation_domain=DOMAIN,
|
||||
translation_key="play_media_error",
|
||||
translation_placeholders={
|
||||
"media_type": media_type,
|
||||
"error_message": json.loads(error.body)["message"],
|
||||
},
|
||||
) from error
|
||||
|
||||
async def async_browse_media(
|
||||
self,
|
||||
|
|
|
@ -28,6 +28,18 @@
|
|||
"exceptions": {
|
||||
"m3u_invalid_format": {
|
||||
"message": "Media sources with the .m3u extension are not supported."
|
||||
},
|
||||
"non_deezer_seeking": {
|
||||
"message": "Seeking is currently only supported when using Deezer"
|
||||
},
|
||||
"invalid_source": {
|
||||
"message": "Invalid source: {invalid_source}. Valid sources are: {valid_sources}"
|
||||
},
|
||||
"invalid_media_type": {
|
||||
"message": "{invalid_media_type} is an invalid type. Valid values are: {valid_media_types}."
|
||||
},
|
||||
"play_media_error": {
|
||||
"message": "An error occurred while attempting to play {media_type}: {error_message}."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue