From b1a3ad6ac3eb81724d7f3737c583b17b5426da02 Mon Sep 17 00:00:00 2001 From: Artem Draft Date: Thu, 8 Jan 2026 01:09:46 +0300 Subject: [PATCH] Improve Bravia TV logging messages (#160394) --- .../components/braviatv/coordinator.py | 53 ++++++++++++++++--- .../components/braviatv/strings.json | 17 ++++++ 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/braviatv/coordinator.py b/homeassistant/components/braviatv/coordinator.py index 41b3923a716..9768d1c088d 100644 --- a/homeassistant/components/braviatv/coordinator.py +++ b/homeassistant/components/braviatv/coordinator.py @@ -22,7 +22,7 @@ from homeassistant.components.media_player import MediaType from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_CLIENT_ID, CONF_PIN from homeassistant.core import HomeAssistant -from homeassistant.exceptions import ConfigEntryAuthFailed +from homeassistant.exceptions import ConfigEntryAuthFailed, HomeAssistantError from homeassistant.helpers.debounce import Debouncer from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -56,8 +56,31 @@ def catch_braviatv_errors[_BraviaTVCoordinatorT: BraviaTVCoordinator, **_P]( """Catch Bravia errors and log message.""" try: await func(self, *args, **kwargs) + except BraviaNotFound as err: + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="command_error_not_found", + translation_placeholders={ + "device": self.config_entry.title, + }, + ) from err + except (BraviaConnectionError, BraviaConnectionTimeout, BraviaTurnedOff) as err: + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="command_error_offline", + translation_placeholders={ + "device": self.config_entry.title, + }, + ) from err except BraviaError as err: - _LOGGER.error("Command error: %s", err) + raise HomeAssistantError( + translation_domain=DOMAIN, + translation_key="command_error", + translation_placeholders={ + "device": self.config_entry.title, + "error": repr(err), + }, + ) from err await self.async_request_refresh() return wrapper @@ -165,17 +188,35 @@ class BraviaTVCoordinator(DataUpdateCoordinator[None]): if self.skipped_updates < 10: self.connected = False self.skipped_updates += 1 - _LOGGER.debug("Update skipped, Bravia API service is reloading") + _LOGGER.debug( + "Update for %s skipped: the Bravia API service is reloading", + self.config_entry.title, + ) return - raise UpdateFailed("Error communicating with device") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="update_error_not_found", + translation_placeholders={ + "device": self.config_entry.title, + }, + ) from err except (BraviaConnectionError, BraviaConnectionTimeout, BraviaTurnedOff): self.is_on = False self.connected = False - _LOGGER.debug("Update skipped, Bravia TV is off") + _LOGGER.debug( + "Update for %s skipped: the TV is turned off", self.config_entry.title + ) except BraviaError as err: self.is_on = False self.connected = False - raise UpdateFailed("Error communicating with device") from err + raise UpdateFailed( + translation_domain=DOMAIN, + translation_key="update_error", + translation_placeholders={ + "device": self.config_entry.title, + "error": repr(err), + }, + ) from err async def async_update_volume(self) -> None: """Update volume information.""" diff --git a/homeassistant/components/braviatv/strings.json b/homeassistant/components/braviatv/strings.json index 9af0e920927..6f08f905817 100644 --- a/homeassistant/components/braviatv/strings.json +++ b/homeassistant/components/braviatv/strings.json @@ -55,5 +55,22 @@ "name": "Terminate apps" } } + }, + "exceptions": { + "command_error": { + "message": "Error sending command to {device}: {error}" + }, + "command_error_not_found": { + "message": "Error sending command to {device}: the Bravia API service is reloading" + }, + "command_error_offline": { + "message": "Error sending command to {device}: the TV is turned off" + }, + "update_error": { + "message": "Error updating data for {device}: {error}" + }, + "update_error_not_found": { + "message": "Error updating data for {device}: the Bravia API service is stuck" + } } }