Skip to content

fix(setup): trigger reauth when Wyze rejects the refresh token - #998

Open
tnorman42 wants to merge 1 commit into
SecKatie:mainfrom
tnorman42:fix/reauth-on-refresh-token-error
Open

tnorman42 wants to merge 1 commit into
SecKatie:mainfrom
tnorman42:fix/reauth-on-refresh-token-error

Conversation

@tnorman42

Copy link
Copy Markdown

When the stored refresh token is no longer valid, Wyze responds with code 2002 ("refresh token is error"). wyzeapy surfaces this as a generic UnknownApiError rather than AccessTokenError, so async_setup_entry let it propagate and Home Assistant showed "Failed to set up" with no way to re-enter credentials, even though the config flow supports reauth.

Map code 2002 to ConfigEntryAuthFailed so Home Assistant starts the existing reauth flow. Other UnknownApiError codes are re-raised as before.

I was getting into this situation where the Wyze API was returning an error code 2002. Apparently my API token had been revoked, even though it appeared on Wyze's portal. After this bug fix, I was able to re-authenticate using a newly-generated API key.

Disclaimer: partially authored by Claude; verified by me, a real human software engineer :)

When the stored refresh token is no longer valid, Wyze responds with
code 2002 ("refresh token is error"). wyzeapy surfaces this as a generic
UnknownApiError rather than AccessTokenError, so async_setup_entry let
it propagate and Home Assistant showed "Failed to set up" with no way
to re-enter credentials, even though the config flow supports reauth.

Map code 2002 to ConfigEntryAuthFailed so Home Assistant starts the
existing reauth flow. Other UnknownApiError codes are re-raised as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tnorman42
tnorman42 requested a review from SecKatie as a code owner November 21, 2026 11:27
@CLAassistant

CLAassistant commented Nov 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@brg468

brg468 commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the contribution!

The problem with only applying this change here is that it doesn't help in the situation that the token is revoked while HA is running, which is likely what will happen most of the time (happened to me last night).

The change to wyzeapy in SecKatie/wyzeapy#407 should address that scenario as well as trigger a re-auth on restart by including the 2002 error as an AccessTokenError, while preventing the rate limiting that can occur when this error goes uncaught.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants