SecKatie / ha-wyzeapi

Home Assistant Integration for Wyze devices.
722 stars 112 forks source link

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

Closed cchan0535 closed 4 weeks ago

cchan0535 commented 3 months ago

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)

wor1dedit commented 3 months ago

Having the same issue

brg468 commented 3 months ago

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

dslucki commented 3 months ago

I am having the same issue

syst3mboot commented 2 months ago

Same issue here

brg468 commented 2 months ago

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

jscherry commented 2 months ago

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

brg468 commented 2 months ago

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

dslucki commented 2 months ago

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: @.***>

brg468 commented 2 months ago

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.

dslucki commented 2 months ago

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: @.***>

syst3mboot commented 2 months ago

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.

brg468 commented 2 months ago

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

dslucki commented 2 months ago

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!

twoolums commented 2 months ago

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?

brg468 commented 2 months ago

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

twoolums commented 2 months ago

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

bh56 commented 2 months ago

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?

brg468 commented 2 months ago

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

bh56 commented 2 months ago

Is the maintainer Home Assistant or SecKatie?

brg468 commented 2 months ago

SecKatie

github-actions[bot] commented 4 weeks ago

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.

cchan0535 commented 4 weeks ago

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.