ha-wyzeapi icon indicating copy to clipboard operation
ha-wyzeapi copied to clipboard

[Bug] Token refresh seems to be too slow for the TTL currently being enforced by Wyze

Open cchan0535 opened this issue 10 months ago • 13 comments

Describe the bug

First things first, thanks for building this integration!

On to the problem:

I lose access to my Wyze devices for exactly 24 hours every other day. I assume that this is happening because the integration internally has a 48hr refresh timer but Wyze has changed token TTL on their side without announcing it. Their documentation also still says 48 hours from what I can see. Nevertheless, my tokens are dying 24 hours to the minute (23:57 UTC in my case) after being issued and functionality doesn't return until WyzeAPI refreshes everything the following day.

To Reproduce Steps to reproduce the behavior:

  1. Configure the integration. See devices working.
  2. Enable debug logging.
  3. Wait exactly 24 hours.
  4. See devices stop working (flood of ErrMsg': 'USER_ACCOUNT_NOT_EXIST' and 'msg': 'access token is error' in the logs)
  5. Wait 24 more hours
  6. See integration refresh the token ([wyzeapy.wyze_auth_lib] Should refresh. Refreshing...)
  7. See device status queries suddenly start succeeding again
  8. Enjoy 24 more hours of functionality before the cycle repeats.

Expected behavior Tokens refresh frequently enough that I never lose access to my devices

System configuration WyzeApi Version: Current (fresh install on an HA Green)

cchan0535 avatar Apr 03 '24 00:04 cchan0535

Having the same issue

wor1dedit avatar Apr 03 '24 03:04 wor1dedit

I swear I pushed an update for this but maybe I never did. I’ll look into it more in a few days.

brg468 avatar Apr 03 '24 03:04 brg468

I am having the same issue

dslucki avatar Apr 12 '24 16:04 dslucki

Same issue here

syst3mboot avatar Apr 18 '24 13:04 syst3mboot

The fix is linked above, just waiting for it to be merged.

brg468 avatar Apr 18 '24 13:04 brg468

Is there any way to fix this before the new pull release?

jscherry avatar Apr 19 '24 00:04 jscherry

You can download from my branch and put the wyzeapy folder from src in your config folder, and that should work. Can’t promise it won’t break anything else but it shouldn’t. Remember to delete that folder when an official update comes out.

https://github.com/brg468/wyzeapy/tree/handle-token-refresh

brg468 avatar Apr 19 '24 00:04 brg468

I don't think I mind trying that. But I'm a noob and not really sure what to do. It sounds like you're saying to take https://github.com/brg468/wyzeapy/tree/handle-token-refresh/src/wyzeapy folder and replace it with my \config\custom_components\wyzeapi folder?

On Thu, Apr 18, 2024 at 5:43 PM Brian Rogers @.***> wrote:

You can download from my branch and put the wyzeapy folder from src in your config folder, and that should work. Can’t promise it won’t break anything else but it shouldn’t. Remember to delete that folder when an official update comes out.

https://github.com/brg468/wyzeapy/tree/handle-token-refresh

— Reply to this email directly, view it on GitHub https://github.com/SecKatie/ha-wyzeapi/issues/567#issuecomment-2065548636, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNJRDA62MZDGPBRL7HULZDY6BSEHAVCNFSM6AAAAABFUKVVJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGU2DQNRTGY . You are receiving this because you commented.Message ID: @.***>

dslucki avatar Apr 19 '24 01:04 dslucki

No leave your wyzeapi folder in custom components, but place the wyzeapy folder from my branch directly in your config folder(same place as configuration.yaml file) then restart. This will overwrite the dependency folder that’s not easily accessible on most HA setups.

brg468 avatar Apr 19 '24 02:04 brg468

Got it, thank you for the details. I will see if this works or not. I suppose I will have to wait 24 hours?

On Thu, Apr 18, 2024 at 7:05 PM Brian Rogers @.***> wrote:

No leave your wyzeapi folder in custom components, but place the wyzeapy folder from my branch directly in your config folder(same place as configuration.yaml file) then restart. This will overwrite the dependency folder that’s not easily accessible on most HA setups.

— Reply to this email directly, view it on GitHub https://github.com/SecKatie/ha-wyzeapi/issues/567#issuecomment-2065617307, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNJRDAJH6A7DYEGNDHLP23Y6B3WRAVCNFSM6AAAAABFUKVVJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGYYTOMZQG4 . You are receiving this because you commented.Message ID: @.***>

dslucki avatar Apr 19 '24 03:04 dslucki

Thank you so much, resolved the issue <3. Just for my own interest, where exactly is the dependencies folder on HA? Wanted to apply this change manually yesterday and searched through so many libs folders on the system but couldnt find wyzeapy anywhere, eventually just gave up.

syst3mboot avatar Apr 19 '24 20:04 syst3mboot

It depends on your install. On HA OS it’s basically impossible to find or purposly hidden, hence that workaround.

brg468 avatar Apr 19 '24 20:04 brg468

Got it, thank you for the details. I will see if this works or not. I suppose I will have to wait 24 hours? On Thu, Apr 18, 2024 at 7:05 PM Brian Rogers @.> wrote: No leave your wyzeapi folder in custom components, but place the wyzeapy folder from my branch directly in your config folder(same place as configuration.yaml file) then restart. This will overwrite the dependency folder that’s not easily accessible on most HA setups. — Reply to this email directly, view it on GitHub <#567 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGNJRDAJH6A7DYEGNDHLP23Y6B3WRAVCNFSM6AAAAABFUKVVJSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRVGYYTOMZQG4 . You are receiving this because you commented.Message ID: @.>

OK, this works as expected now. Thank you!

dslucki avatar Apr 24 '24 00:04 dslucki

You can download from my branch and put the wyzeapy folder from src in your config folder, and that should work. Can’t promise it won’t break anything else but it shouldn’t. Remember to delete that folder when an official update comes out.

https://github.com/brg468/wyzeapy/tree/handle-token-refresh

I get a 404 on this link/tree and looking through all your branches I don't see one call handle-token-refresh. Any suggestions so I can try to resolve my issue of 24 on 24 off with wyze in HA?

twoolums avatar May 16 '24 13:05 twoolums

Sorry I probably deleted that branch once the PR got merged. You can download the main branch from here now:

https://github.com/SecKatie/wyzeapy

brg468 avatar May 16 '24 13:05 brg468

No worries, I just wanted to make sure before I did that and maybe cause something else to break with it :)

twoolums avatar May 16 '24 13:05 twoolums

I rather not do a workaround. Can you clarify for me when this will be merged into an update that I won't have to do a workaround for?

bh56 avatar May 16 '24 14:05 bh56

Whenever the maintainer pushes a new version. Can’t really give you a timeframe beyond that.

brg468 avatar May 16 '24 14:05 brg468

Is the maintainer Home Assistant or SecKatie?

bh56 avatar May 16 '24 14:05 bh56

SecKatie

brg468 avatar May 16 '24 15:05 brg468

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 16 '24 01:06 github-actions[bot]

Apologies, I forked and fixed the issue myself immediately after posting so I lost track of the thread. Just switched back over to the official version and can confirm that the problem is resolved in the latest release.

Appreciate the fix! Closing the issue.

cchan0535 avatar Jun 16 '24 02:06 cchan0535