mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 23:57:06 +00:00
Translate raised exceptions for Squeezebox (#144842)
* initial * tweak * review updates
This commit is contained in:
parent
2050b0b375
commit
9a0fed89bd
@ -19,7 +19,7 @@ from homeassistant.components.media_player import (
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.network import is_internal_request
|
from homeassistant.helpers.network import is_internal_request
|
||||||
|
|
||||||
from .const import UNPLAYABLE_TYPES
|
from .const import DOMAIN, UNPLAYABLE_TYPES
|
||||||
|
|
||||||
LIBRARY = [
|
LIBRARY = [
|
||||||
"favorites",
|
"favorites",
|
||||||
@ -315,7 +315,14 @@ async def build_item_response(
|
|||||||
children.append(child_media)
|
children.append(child_media)
|
||||||
|
|
||||||
if children is None:
|
if children is None:
|
||||||
raise BrowseError(f"Media not found: {search_type} / {search_id}")
|
raise BrowseError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="browse_media_not_found",
|
||||||
|
translation_placeholders={
|
||||||
|
"type": str(search_type),
|
||||||
|
"id": str(search_id),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
assert media_class["item"] is not None
|
assert media_class["item"] is not None
|
||||||
if not search_id:
|
if not search_id:
|
||||||
@ -398,7 +405,13 @@ async def generate_playlist(
|
|||||||
media_id = payload["search_id"]
|
media_id = payload["search_id"]
|
||||||
|
|
||||||
if media_type not in browse_media.squeezebox_id_by_type:
|
if media_type not in browse_media.squeezebox_id_by_type:
|
||||||
raise BrowseError(f"Media type not supported: {media_type}")
|
raise BrowseError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="browse_media_type_not_supported",
|
||||||
|
translation_placeholders={
|
||||||
|
"media_type": str(media_type),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
browse_id = (browse_media.squeezebox_id_by_type[media_type], media_id)
|
browse_id = (browse_media.squeezebox_id_by_type[media_type], media_id)
|
||||||
if media_type.startswith("app-"):
|
if media_type.startswith("app-"):
|
||||||
@ -412,4 +425,11 @@ async def generate_playlist(
|
|||||||
if result and "items" in result:
|
if result and "items" in result:
|
||||||
items: list = result["items"]
|
items: list = result["items"]
|
||||||
return items
|
return items
|
||||||
raise BrowseError(f"Media not found: {media_type} / {media_id}")
|
raise BrowseError(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="browse_media_not_found",
|
||||||
|
translation_placeholders={
|
||||||
|
"type": str(media_type),
|
||||||
|
"id": str(media_id),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
@ -18,6 +18,7 @@ if TYPE_CHECKING:
|
|||||||
from . import SqueezeboxConfigEntry
|
from . import SqueezeboxConfigEntry
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
|
DOMAIN,
|
||||||
PLAYER_UPDATE_INTERVAL,
|
PLAYER_UPDATE_INTERVAL,
|
||||||
SENSOR_UPDATE_INTERVAL,
|
SENSOR_UPDATE_INTERVAL,
|
||||||
SIGNAL_PLAYER_REDISCOVERED,
|
SIGNAL_PLAYER_REDISCOVERED,
|
||||||
@ -65,7 +66,10 @@ class LMSStatusDataUpdateCoordinator(DataUpdateCoordinator):
|
|||||||
data: dict | None = await self.lms.async_prepared_status()
|
data: dict | None = await self.lms.async_prepared_status()
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
raise UpdateFailed("No data from status poll")
|
raise UpdateFailed(
|
||||||
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="coordinator_no_data",
|
||||||
|
)
|
||||||
_LOGGER.debug("Raw serverstatus %s=%s", self.lms.name, data)
|
_LOGGER.debug("Raw serverstatus %s=%s", self.lms.name, data)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -471,7 +471,11 @@ class SqueezeBoxMediaPlayerEntity(SqueezeboxEntity, MediaPlayerEntity):
|
|||||||
if announce:
|
if announce:
|
||||||
if media_type not in MediaType.MUSIC:
|
if media_type not in MediaType.MUSIC:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
"Announcements must have media type of 'music'. Playlists are not supported"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="invalid_announce_media_type",
|
||||||
|
translation_placeholders={
|
||||||
|
"media_type": str(media_type),
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
extra = kwargs.get(ATTR_MEDIA_EXTRA, {})
|
extra = kwargs.get(ATTR_MEDIA_EXTRA, {})
|
||||||
@ -480,7 +484,11 @@ class SqueezeBoxMediaPlayerEntity(SqueezeboxEntity, MediaPlayerEntity):
|
|||||||
announce_volume = get_announce_volume(extra)
|
announce_volume = get_announce_volume(extra)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"{ATTR_ANNOUNCE_VOLUME} must be a number greater than 0 and less than or equal to 1"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="invalid_announce_volume",
|
||||||
|
translation_placeholders={
|
||||||
|
"announce_volume": ATTR_ANNOUNCE_VOLUME,
|
||||||
|
},
|
||||||
) from None
|
) from None
|
||||||
else:
|
else:
|
||||||
self._player.set_announce_volume(announce_volume)
|
self._player.set_announce_volume(announce_volume)
|
||||||
@ -489,7 +497,11 @@ class SqueezeBoxMediaPlayerEntity(SqueezeboxEntity, MediaPlayerEntity):
|
|||||||
announce_timeout = get_announce_timeout(extra)
|
announce_timeout = get_announce_timeout(extra)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"{ATTR_ANNOUNCE_TIMEOUT} must be a whole number greater than 0"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="invalid_announce_timeout",
|
||||||
|
translation_placeholders={
|
||||||
|
"announce_timeout": ATTR_ANNOUNCE_TIMEOUT,
|
||||||
|
},
|
||||||
) from None
|
) from None
|
||||||
else:
|
else:
|
||||||
self._player.set_announce_timeout(announce_timeout)
|
self._player.set_announce_timeout(announce_timeout)
|
||||||
@ -595,13 +607,21 @@ class SqueezeBoxMediaPlayerEntity(SqueezeboxEntity, MediaPlayerEntity):
|
|||||||
other_player = ent_reg.async_get(other_player_entity_id)
|
other_player = ent_reg.async_get(other_player_entity_id)
|
||||||
if other_player is None:
|
if other_player is None:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"Could not find player with entity_id {other_player_entity_id}"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="join_cannot_find_other_player",
|
||||||
|
translation_placeholders={
|
||||||
|
"other_player_entity_id": str(other_player_entity_id)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if other_player_id := other_player.unique_id:
|
if other_player_id := other_player.unique_id:
|
||||||
await self._player.async_sync(other_player_id)
|
await self._player.async_sync(other_player_id)
|
||||||
else:
|
else:
|
||||||
raise ServiceValidationError(
|
raise ServiceValidationError(
|
||||||
f"Could not join unknown player {other_player_entity_id}"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="join_cannot_join_unknown_player",
|
||||||
|
translation_placeholders={
|
||||||
|
"other_player_entity_id": str(other_player_entity_id)
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_unjoin_player(self) -> None:
|
async def async_unjoin_player(self) -> None:
|
||||||
|
@ -156,5 +156,34 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"exceptions": {
|
||||||
|
"invalid_announce_media_type": {
|
||||||
|
"message": "Only type 'music' can be played as announcement (received type {media_type})."
|
||||||
|
},
|
||||||
|
"invalid_announce_volume": {
|
||||||
|
"message": "{announce_volume} must be a number greater than 0 and less than or equal to 1."
|
||||||
|
},
|
||||||
|
"invalid_announce_timeout": {
|
||||||
|
"message": "{announce_timeout} must be a number greater than 0."
|
||||||
|
},
|
||||||
|
"join_cannot_find_other_player": {
|
||||||
|
"message": "Could not find player with entity_id {other_player_entity_id}."
|
||||||
|
},
|
||||||
|
"join_cannot_join_unknown_player": {
|
||||||
|
"message": "Could not join unknown player {other_player_entity_id}."
|
||||||
|
},
|
||||||
|
"coordinator_no_data": {
|
||||||
|
"message": "No data from status poll."
|
||||||
|
},
|
||||||
|
"browse_media_not_found": {
|
||||||
|
"message": "Media not found: {type} / {id}."
|
||||||
|
},
|
||||||
|
"browse_media_type_not_supported": {
|
||||||
|
"message": "Media type not supported: {media_type}."
|
||||||
|
},
|
||||||
|
"update_restart_failed": {
|
||||||
|
"message": "Error trying to update LMS Plugins: Restart failed."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ from homeassistant.helpers.event import async_call_later
|
|||||||
|
|
||||||
from . import SqueezeboxConfigEntry
|
from . import SqueezeboxConfigEntry
|
||||||
from .const import (
|
from .const import (
|
||||||
|
DOMAIN,
|
||||||
SERVER_MODEL,
|
SERVER_MODEL,
|
||||||
STATUS_QUERY_VERSION,
|
STATUS_QUERY_VERSION,
|
||||||
STATUS_UPDATE_NEWPLUGINS,
|
STATUS_UPDATE_NEWPLUGINS,
|
||||||
@ -161,7 +162,8 @@ class ServerStatusUpdatePlugins(ServerStatusUpdate):
|
|||||||
self.restart_triggered = False
|
self.restart_triggered = False
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
raise HomeAssistantError(
|
raise HomeAssistantError(
|
||||||
"Error trying to update LMS Plugins: Restart failed"
|
translation_domain=DOMAIN,
|
||||||
|
translation_key="update_restart_failed",
|
||||||
)
|
)
|
||||||
|
|
||||||
async def _async_update_catchall(self, now: datetime | None = None) -> None:
|
async def _async_update_catchall(self, now: datetime | None = None) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user