Closed hjdarnel closed 4 years ago
This is still occurring regularly (every 2 days without a restart). Without any better logging there's no way to tell what's going on. All I get is the AccessTokenError
in the Supervisor Logs tab
Hey @hjdarnel,
I will work on getting additional logging around the affected area of code. Hopefully we can figure out what is going on.
I should have more time coming up soon due to the end of my school semester and I will be able to focus back on this project!
Thanks for submitting an issue! I hope that I will have a new beta for you to try out in the next week or two.
Thanks @JoshuaMulliken! I totally understand. From my limited knowledge of oauth it’s not refreshing the token properly. 🤷♂️
Anyway ping here when you get some logs put in and I can pull it and start investigating!
Although not experincing this as I restart my HA twice a day I have found some code to refresh a token that might work when token looses access: https://github.com/noelportugal/wyze-node/blob/master/index.js
I hope this still works and could be implemented too. Sadly I am no Python dev so cannot assist with this.
Yeah for now I might just restart every night or something to fix this.
On Sat, Apr 25, 2020 at 6:26 PM Arnd Brugman notifications@github.com wrote:
Although not experincing this as I restart my HA twice a day I have found some code to refresh a token that might work when token looses access: https://github.com/noelportugal/wyze-node/blob/master/index.js
I hope this still works and could be implemented too. Sadly I am no Python dev so cannot assist with this.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/40#issuecomment-619454201, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB4BDY55SZD62T7IQQWS2ITRONWTDANCNFSM4LWXLENA .
@JoshuaMulliken I've just tried this in PostMan and it returns a new access_token and refresh_token so it still works on the API of Wyze. Let me know if I can help implement it, although I'm not Python savvy, I might be able to point out where to add it.
Awesome thank you for the research. Right now the code try’s to login again in order to get a new access token. It seems to work with the lights but obviously switches are an issue. I will hopefully be able to get a beta with more debug logging soon. Exams are next week so once they are done I will have more free time to work on this.
Interestingly it doesn't have this issue with the lights. I think there is something funny going on with the switches.
I will say I only use the API for switches 😃
@hjdarnel can you download the latest from master. I have more logging in there. I plan on implementing refresh token support later but at least this will give us more insight
I've installed it, we'll need to give it some time for the access token to expire before it logs much 👍
Getting an error off master @JoshuaMulliken
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/setup.py", line 137, in _async_setup_component
component = integration.get_component()
File "/usr/src/homeassistant/homeassistant/loader.py", line 268, in get_component
cache[self.domain] = importlib.import_module(self.pkg_path)
File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/config/custom_components/wyzeapi/__init__.py", line 7, in <module>
from .wyzeapi.wyzeapi import WyzeApi
File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 37
url = "https://api.wyzecam.com/app/user/login"
^
IndentationError: unindent does not match any outer indentation level
Yep just fixed that one. Sorry about that. Can you try again?
I'm not sure if this is related, but I just installed through HACS (not sure which branch that is) and got this: 2020-05-01 20:55:03 ERROR (MainThread) [homeassistant.setup] Error during setup of component wyzeapi Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/setup.py", line 171, in _async_setup_component hass, processed_config File "/config/custom_components/wyzeapi/init.py", line 39, in async_setup await wyzeapi_account.async_init() File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 23, in async_init self._access_token = await self.async_login(self._user_name, self._password, self._device_id) File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 47, in async_login data = await self.async_do_request(url, payload) File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 113, in async_do_request return await WyzeRequest(url, payload).async_get_response() File "/config/custom_components/wyzeapi/wyzeapi/wyze_request.py", line 45, in async_get_response raise WyzeApiError("Payload: " + str(self._payload) + "\nResponse Data: " + str(data))
@psicard It seems like it cannot login. It is failing on startup so that would be my thought. Check the credentials. Remember 2fa doesn’t work with this.
@hjdarnel any new logs?
@JoshuaMulliken I actually haven't experienced the original issue since changing to pull from master instead of a numbered release. I wonder if the numbered releases were/are behind or something. I'll pull logs if it comes up though.
@hjdarnel That’s great! I am going to be switching to use the refresh token soon and it would be great to have a beta tester for that. Would you be able to do that when it comes along?
Sure, let me know when you have a working branch up and I can have HACS pull it
Oops. Yeah, I have 2FA turned on...
On Mon, May 4, 2020 at 11:43 AM Joshua Mulliken notifications@github.com wrote:
@psicard https://github.com/psicard It seems like it cannot login. It is failing on startup so that would be my thought. Check the credentials. Remember 2fa doesn’t work with this.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/JoshuaMulliken/ha-wyzeapi/issues/40#issuecomment-623575580, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAOQ2R4DENXQMZKDEBNWMT3RP3WE7ANCNFSM4LWXLENA .
@ArndBrugman Can you look at this pull request for me. Should this work to use the refresh token? https://github.com/JoshuaMulliken/ha-wyzeapi/pull/44
As mentioned I am no Python guy. It looks fine though. easiest way to validate is to rais an exeption right after:
try: return await WyzeRequest(url, payload).async_get_response() ---> HERE!!! (WELL Before the return of course ;) )
This will force to refresh the access token and retry for a second time. Note this is for validation/debugging only, not the actual release.
Also I see the function
def is_valid_login(self):
if self._access_token == None:
return False
return True
which would mean if we loose access token and are unable to refresh it we should invalidate access_token. OR: even better do a re-login that will try to login and if it fails it should wipe the self_access_token.
Hope this helps and is clear enough.
By the way: the devices returned also return the sensors, which is a great addition.
And: I have some 15 bulbs and a few sensor kits. Which makes updates to HA slow, slower that 30 seconds.
Updating wyzeapi light took longer than the scheduled update interval 0:00:30 2:56:23 PM – Light (WARNING) - message first occurred at 5:23:40 AM and shows up 544 times
Updating wyzeapi switch took longer than the scheduled update interval 0:00:30 2:56:23 PM – Switch (WARNING) - message first occurred at 5:23:40 AM and shows up 510 times
It would be good to do batch updates on all devices and use a cache for the reads in between. On my Hue Web App I only update complete status once every 2.5 seconds. and just display from cached values to make sure i do not overload the bridge. we could persue a similar approach and setup in this component.
Ok @hjdarnel the latest master should be using the refresh token so if you pull an update from master you can help test it
Describe the bug After a few days of uptime, the plugin starts to throw an error and my switches don't respond to input. Here's the log:
To Reproduce Steps to reproduce the behavior: Configure configuration.yml with username and password, restart HA and wait a few days (?)
Expected behavior the wyzeapi plugin should continue to work, as it does right after a restart.
System configuration System: HassIO on a Pi 3b HA Version: Home Assistant 0.107.5 WyzeApi Version: v0.4.2
configuration.yaml
with secrets
home-assistant.log I've added this debug option, I'll update with complete logs once I recreate the error with debug logs turned on