Skip to content

Retry when the device or cloud is briefly unavailable - #1196

Merged
frenck merged 1 commit into
mainfrom
frenck/retry-transient-errors
Oct 3, 2026
Merged

frenck merged 1 commit into
mainfrom
frenck/retry-transient-errors

Conversation

@frenck

@frenck frenck commented Oct 3, 2026

Copy link
Copy Markdown
Owner

Proposed Changes

(Describe the changes and rationale behind them)

Found in a review of everything that changed since v1.4.1, checked against how Home Assistant uses the library.

Transient errors were no longer retried. In v1.4.1 both clients used raise_for_status=True, so an error response became a ClientResponseError, turned into a LaMetricConnectionError, and was retried. Since #1181 every error response raises a plain LaMetricError with the message of the server, which is never retried. A brief 502, 503 or 504 from the cloud now failed setup on the first try, and because Home Assistant's config flow only catches LaMetricConnectionError, people got "unknown" instead of "cannot connect".

502, 503 and 504 now raise a LaMetricConnectionError again, saying the device or cloud is temporarily unavailable. Reads retry them like before. Changes to the device do not, following #1186: the device may already have acted on them. Other error responses still raise right away.

aiohttp.ConnectionTimeoutError counts as never sent. aiohttp only raises it while the connection is still being made, so a change cannot have reached the device yet and is safe to retry.

The tests for retrying changes now run for POST, PUT and DELETE, so a check on the method that only covers POST would no longer slip through.

Related Issues

(Github link to related issues or pull requests)

Follow up on #1181 and #1186.

Since passing on the error messages of the device and the cloud, every
error response raised a LaMetricError that was never retried. A brief
502, 503 or 504 from the cloud now failed right away, where it used to
be retried. Home Assistant only treats connection errors as "cannot
connect", so people got an unknown error instead.

Those three statuses are connection errors again. Reads retry them,
changes do not, as the device may already have acted on them.

aiohttp's ConnectionTimeoutError now also counts as never sent, as it
is only raised while the connection is still being made.
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Oct 3, 2026
@frenck
frenck merged commit 86378c4 into main Oct 3, 2026
32 checks passed
@frenck
frenck deleted the frenck/retry-transient-errors branch October 3, 2026 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant