-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
Add exception translations to ring integration #136468
Draft
sdb9696
wants to merge
1
commit into
home-assistant:dev
Choose a base branch
from
sdb9696:ring/exception_translations
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+98
−20
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,7 +24,7 @@ | |
UpdateFailed, | ||
) | ||
|
||
from .const import SCAN_INTERVAL | ||
from .const import DOMAIN, SCAN_INTERVAL | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
@@ -33,20 +33,45 @@ async def _call_api[*_Ts, _R]( | |
hass: HomeAssistant, | ||
target: Callable[[*_Ts], Coroutine[Any, Any, _R]], | ||
*args: *_Ts, | ||
msg_suffix: str = "", | ||
func_name: str, | ||
device_name: str | None = None, | ||
) -> _R: | ||
device_placeholder = {"device": device_name} if device_name else {} | ||
translation_prefix = "device_api_" if device_name else "api_" | ||
try: | ||
return await target(*args) | ||
except AuthenticationError as err: | ||
# Raising ConfigEntryAuthFailed will cancel future updates | ||
# and start a config flow with SOURCE_REAUTH (async_step_reauth) | ||
raise ConfigEntryAuthFailed from err | ||
raise ConfigEntryAuthFailed( | ||
translation_domain=DOMAIN, | ||
translation_key=f"{translation_prefix}authentication", | ||
translation_placeholders={ | ||
"func": func_name, | ||
"exc": str(err), | ||
Comment on lines
+50
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's OK to include the stringified exception IF it's something understandable and useful to the user and isn't already, or can't be, represented by the exception translation message itself. Can you give some examples of what might be added here? |
||
**device_placeholder, | ||
}, | ||
) from err | ||
except RingTimeout as err: | ||
raise UpdateFailed( | ||
f"Timeout communicating with API{msg_suffix}: {err}" | ||
translation_domain=DOMAIN, | ||
translation_key=f"{translation_prefix}timeout", | ||
translation_placeholders={ | ||
"func": func_name, | ||
"exc": str(err), | ||
**device_placeholder, | ||
}, | ||
) from err | ||
except RingError as err: | ||
raise UpdateFailed(f"Error communicating with API{msg_suffix}: {err}") from err | ||
raise UpdateFailed( | ||
translation_domain=DOMAIN, | ||
translation_key=f"{translation_prefix}error", | ||
translation_placeholders={ | ||
"func": func_name, | ||
"exc": str(err), | ||
**device_placeholder, | ||
}, | ||
) from err | ||
|
||
|
||
class RingDataCoordinator(DataUpdateCoordinator[RingDevices]): | ||
|
@@ -72,7 +97,9 @@ async def _async_update_data(self) -> RingDevices: | |
update_method: str = ( | ||
"async_update_data" if self.first_call else "async_update_devices" | ||
) | ||
await _call_api(self.hass, getattr(self.ring_api, update_method)) | ||
await _call_api( | ||
self.hass, getattr(self.ring_api, update_method), func_name=update_method | ||
) | ||
self.first_call = False | ||
devices: RingDevices = self.ring_api.devices() | ||
subscribed_device_ids = set(self.async_contexts()) | ||
|
@@ -88,14 +115,16 @@ async def _async_update_data(self) -> RingDevices: | |
self.hass, | ||
lambda device: device.async_history(limit=10), | ||
device, | ||
msg_suffix=f" for device {device.name}", # device_id is the mac | ||
func_name="async_history", | ||
device_name=device.name, | ||
) | ||
) | ||
tg.create_task( | ||
_call_api( | ||
self.hass, | ||
device.async_update_health_data, | ||
msg_suffix=f" for device {device.name}", | ||
func_name="async_update_health_data", | ||
device_name=device.name, | ||
) | ||
) | ||
except ExceptionGroup as eg: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation details do not belong in user-facing error messages. If this is useful for diagnostics or troubleshooting, then log it instead.