SecKatie / ha-wyzeapi

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

Access tokens stop working #3

Closed SecKatie closed 4 years ago

SecKatie commented 4 years ago

Sometimes an access token will cease to work. I can detect this by no 'device_list' being returned.

SecKatie commented 4 years ago

v0.3.1-beta has been created to test and see if this issue is resolved.

SecKatie commented 4 years ago

If anyone experiences this issue please install the latest v0.3.1-beta.3 and let me know if you have any issues.

basesnow commented 4 years ago

running v0.3.1-beta4. here is my log file. home-assistant.log

markrickert commented 4 years ago

I've been running the beta and haven't seen any issues to speak of.

SecKatie commented 4 years ago

I have discovered a thread safety issue. v0.3.0 works and if you come across AccessTokenErrors please delete wyzeconfig.ini and restart.

basesnow commented 4 years ago

Thanks, this worked for me.

aeckard87 commented 4 years ago

also updated to v0.3.1-beta4 and confirmed working, thanks!

DaveHenning commented 4 years ago

I'm still having issues. On beta.5.

FWIW I had the pre-HACS version installed when it stopped working. I installed the HACS version (non beta) and removed the old one with no luck, then updated to b5.

Relevant log:

2019-12-22 12:45:58 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for wyzeapi which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-12-22 12:45:58 WARNING (SyncWorker_15) [homeassistant.components.flux_led.light] Failed to connect to bulb 192.168.1.230, flux_tv_leds
2019-12-22 12:45:59 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform wyzeapi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/wyzeapi/light.py", line 58, in setup_platform
    add_entities(WyzeBulb(light) for light in wyze.list_bulbs())
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 88, in list_bulbs
    for device in self.get_devices():
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 80, in get_devices
    data = do_request(url, payload, self)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 36, in do_request
    return request_helper(url, payload, api)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 25, in request_helper
    api.initialize()
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 26, in initialize
    updateConfig(self._device_id, self._access_token)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_config.py", line 18, in updateConfig
    config.add_section('auth')
  File "/usr/local/lib/python3.7/configparser.py", line 1205, in add_section
    super().add_section(section)
  File "/usr/local/lib/python3.7/configparser.py", line 658, in add_section
    raise DuplicateSectionError(section)
configparser.DuplicateSectionError: Section 'auth' already exists
kcrexchan commented 4 years ago

I'm still having issues. On beta.5.

FWIW I had the pre-HACS version installed when it stopped working. I installed the HACS version (non beta) and removed the old one with no luck, then updated to b5.

Relevant log:

2019-12-22 12:45:58 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for wyzeapi which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-12-22 12:45:58 WARNING (SyncWorker_15) [homeassistant.components.flux_led.light] Failed to connect to bulb 192.168.1.230, flux_tv_leds
2019-12-22 12:45:59 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform wyzeapi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/wyzeapi/light.py", line 58, in setup_platform
    add_entities(WyzeBulb(light) for light in wyze.list_bulbs())
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 88, in list_bulbs
    for device in self.get_devices():
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 80, in get_devices
    data = do_request(url, payload, self)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 36, in do_request
    return request_helper(url, payload, api)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 25, in request_helper
    api.initialize()
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 26, in initialize
    updateConfig(self._device_id, self._access_token)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_config.py", line 18, in updateConfig
    config.add_section('auth')
  File "/usr/local/lib/python3.7/configparser.py", line 1205, in add_section
    super().add_section(section)
  File "/usr/local/lib/python3.7/configparser.py", line 658, in add_section
    raise DuplicateSectionError(section)
configparser.DuplicateSectionError: Section 'auth' already exists

I have the same problem and I install master through HACS and the problem goes away. @DaveHenning, can you try and confirm if that works for you?

SecKatie commented 4 years ago

Hello everyone! Thank you for testing out the betas! I am reading these however with the holidays I have not had a chance to sit down and work on this. I will be looking at putting in some work after Christmas.

DaveHenning commented 4 years ago

I'm still having issues. On beta.5. FWIW I had the pre-HACS version installed when it stopped working. I installed the HACS version (non beta) and removed the old one with no luck, then updated to b5. Relevant log:

2019-12-22 12:45:58 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for wyzeapi which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-12-22 12:45:58 WARNING (SyncWorker_15) [homeassistant.components.flux_led.light] Failed to connect to bulb 192.168.1.230, flux_tv_leds
2019-12-22 12:45:59 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform wyzeapi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/wyzeapi/light.py", line 58, in setup_platform
    add_entities(WyzeBulb(light) for light in wyze.list_bulbs())
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 88, in list_bulbs
    for device in self.get_devices():
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 80, in get_devices
    data = do_request(url, payload, self)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 36, in do_request
    return request_helper(url, payload, api)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 25, in request_helper
    api.initialize()
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 26, in initialize
    updateConfig(self._device_id, self._access_token)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_config.py", line 18, in updateConfig
    config.add_section('auth')
  File "/usr/local/lib/python3.7/configparser.py", line 1205, in add_section
    super().add_section(section)
  File "/usr/local/lib/python3.7/configparser.py", line 658, in add_section
    raise DuplicateSectionError(section)
configparser.DuplicateSectionError: Section 'auth' already exists

I have the same problem and I install master through HACS and the problem goes away. @DaveHenning, can you try and confirm if that works for you?

This fixed it for me. Thanks!

basesnow commented 4 years ago

I'm still having issues. On beta.5. FWIW I had the pre-HACS version installed when it stopped working. I installed the HACS version (non beta) and removed the old one with no luck, then updated to b5. Relevant log:

2019-12-22 12:45:58 WARNING (MainThread) [homeassistant.loader] You are using a custom integration for wyzeapi which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you do experience issues with Home Assistant.
2019-12-22 12:45:58 WARNING (SyncWorker_15) [homeassistant.components.flux_led.light] Failed to connect to bulb 192.168.1.230, flux_tv_leds
2019-12-22 12:45:59 ERROR (MainThread) [homeassistant.components.light] Error while setting up platform wyzeapi
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 150, in _async_setup_platform
    await asyncio.wait_for(asyncio.shield(task), SLOW_SETUP_MAX_WAIT)
  File "/usr/local/lib/python3.7/asyncio/tasks.py", line 442, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/wyzeapi/light.py", line 58, in setup_platform
    add_entities(WyzeBulb(light) for light in wyze.list_bulbs())
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 88, in list_bulbs
    for device in self.get_devices():
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 80, in get_devices
    data = do_request(url, payload, self)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 36, in do_request
    return request_helper(url, payload, api)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_request.py", line 25, in request_helper
    api.initialize()
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi.py", line 26, in initialize
    updateConfig(self._device_id, self._access_token)
  File "/config/custom_components/wyzeapi/wyzeapi/wyzeapi_config.py", line 18, in updateConfig
    config.add_section('auth')
  File "/usr/local/lib/python3.7/configparser.py", line 1205, in add_section
    super().add_section(section)
  File "/usr/local/lib/python3.7/configparser.py", line 658, in add_section
    raise DuplicateSectionError(section)
configparser.DuplicateSectionError: Section 'auth' already exists

I have the same problem and I install master through HACS and the problem goes away. @DaveHenning, can you try and confirm if that works for you?

You mentioned that you originally installed before HACS. When you removed it, did you delete all the associated folders in the file system? I forgot to do that, I just reinstalled with the HACS version, assuming it overrode the original. Once I deleted the other folders/files it fixed all my issues.

DaveHenning commented 4 years ago

You mentioned that you originally installed before HACS. When you removed it, did you delete all the associated folders in the file system? I forgot to do that, I just reinstalled with the HACS version, assuming it overrode the original. Once I deleted the other folders/files it fixed all my issues.

At first, no. Once the HACS version didn't work that's when I went to beta5. Once that also didn't work I removed the old directory. Still didn't work but the switch to master did. There were reboots between all steps. I'm not sure if the master version fixed it or just the fact that it forced another reboot did, but it's working now.

markrickert commented 4 years ago

Thanks for this awesome library, @JoshuaMulliken! Have a great Christmas!

SecKatie commented 4 years ago

Hello everyone! I have made significant changes to how requests to the API are handled. This should improve reliability and I believe that it should be able to recover from AccessToken errors.

Please test beta.6 and let me know if you have any issues!

basesnow commented 4 years ago

The betas don't seem to show up in the available version drop down in HACS anymore. Not sure if it is something I did??

SecKatie commented 4 years ago

@basenow I marked them as prereleases. Select the three dot menu item on the integration. And click show beta

SecKatie commented 4 years ago

I believe that this is now fixed in v0.3.1!

cjackson234 commented 4 years ago

Getting the same error. Restarting HA once a week fixes it. Is there a way to ask for a fresh token after X number of failures?

SecKatie commented 4 years ago

@cjackson234 it attempts to get a new token on each failure. I have been having some issues as well but as far as I can tell they are on wyze clouds side

SecKatie commented 4 years ago

@cjackson234 I found a bug in the restore function! The application thought that it was consistently in an error state. I made a small change and I think it has fixed this issue.

cjackson234 commented 4 years ago

Can you create a new release so HACS sees it?

SecKatie commented 4 years ago

@cjackson234 I don’t think it’s as fixed as I thought it was. The issue is that I want to do concurrent requests to the bulbs so they turn on or off at once but I run into thread safety issues when I try to recover from an access token error

SecKatie commented 4 years ago

@cjackson234 There is a new beta available check it out! Also If you have switches that would be really helpful for me to get additional testing done of those. I do not have any

cjackson234 commented 4 years ago

Yes I have all switches and no light bulbs. So i'll let you know how it goes.

cjackson234 commented 4 years ago

I ran into an issue where items become uncontrollable if their initial state is on. Is there a thread somewhere we should continue this conversation?

SecKatie commented 4 years ago

@cjackson234 that is strange... can you create a new issue. I looked at the code and I have no idea what would be causing that

SecKatie commented 4 years ago

@cjackson234 do you have any updates on that?