SecKatie / ha-wyzeapi

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

[Bug] Integration requires re-setup on every reboot #579

Closed ulek closed 3 weeks ago

ulek commented 2 months ago

Describe the bug After rebooting home assistant the integration doesn't have any devices and entities.

To Reproduce Reboot home assistant instance

Expected behavior All of the wyze devices are available after reboot

System configuration System: HA Yellow HA Version: 2024.5 started with 2024.4 WyzeApi Version: 0.1.24

unfortunately when I tried reboot this this time it worked fine. I will try to catch a log next time it happens

bh56 commented 2 months ago

I think I'm seeing this issue as well. I'm frequently getting "Failed to setup" recently and have to delete and re-add to get going again.

GreggTom commented 2 months ago

Error Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble 2024.5.2 Just started with HA update. Wyze will not work

ulek commented 2 months ago

Remembered that I caught some logs on my phone.

2024-04-30 06:34:52.380 ERROR (MainThread) [custom_components.wyzeapi.token_manager] TokenManager detected a login issue please re-login.
2024-04-30 06:34:52.383 ERROR (MainThread) [homeassistant.components.lock] Error while setting up wyzeapi platform for lock
Traceback (most recent call last):
  File "/config/custom_components/wyzeapi/token_manager.py", line 45, in inner_function
    await func(*args, **kwargs)
  File "/config/custom_components/wyzeapi/lock.py", line 45, in async_setup_entry
    locks = [WyzeLock(lock_service, lock) for lock in await lock_service.get_locks()]
                                                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wyzeapy/services/lock_service.py", line 42, in get_locks
    self._devices = await self.get_object_list()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/wyzeapy/services/base_service.py", line 122, in get_object_list
    check_for_errors_standard(response_json)
  File "/usr/local/lib/python3.12/site-packages/wyzeapy/utils.py", line 80, in check_for_errors_standard
    raise AccessTokenError
wyzeapy.exceptions.AccessTokenError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 356, in _async_setup_platform
    await asyncio.shield(awaitable)
  File "/config/custom_components/wyzeapi/token_manager.py", line 50, in inner_function
    raise ConfigEntryAuthFailed("Unable to login, please re-login.") from err
homeassistant.exceptions.ConfigEntryAuthFailed: Unable to login, please re-login.
2024-04-30 06:34:52.407 ERROR (MainThread) [custom_components.wyzeapi.token_manager] TokenManager detected a login issue please re-login.
2024-04-30 06:34:52.408 ERROR (MainThread) [custom_components.wyzeapi.token_manager] TokenManager detected a login issue please re-login.
2024-04-30 06:34:52.413 ERROR (MainThread) [homeassistant.components.switch] Error while setting up wyzeapi platform for switch
GreggTom commented 2 months ago

New error with trying to load wyze.

Error Config flow could not be loaded: {"message":"Invalid handler specified"} HA Ver 2024.5.2

bh56 commented 2 months ago

Is Wyze's change to the API related to this? https://github.com/SecKatie/ha-wyzeapi/issues/576; I reverted back to 2024.5.1. Deleted and re-added and the integration appears to be working again. So, does seem like HA ver. 2024.5.2 broke this integration

brg468 commented 2 months ago

I just tried upgrading to 2024.5.2 and couldn't duplicate the issue. Mine is loading fine.

bh56 commented 2 months ago

Try reloading the integration, then it seems to not be able to load.

brg468 commented 2 months ago

Tried that, tried totally removing everything including from HACS and starting from scratch. The only thing that maybe I did different was I think I deleted everything first and then upgraded HA. So if you haven't tried totally deleting Wyze from HA and HACS maybe that would work?

GreggTom commented 2 months ago

Removed Wyze from HA and HACS. Still same problem when loading. Error Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble Restarted HA both times same problem HA 2024.5.2

GreggTom commented 2 months ago

Logger: aiohttp.server Source: /usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py:421 First occurred: 2:42:07 PM (1 occurrences) Last logged: 2:42:07 PM

Error handling request Traceback (most recent call last): File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request resp = await request_handler(request) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle resp = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 88, in ban_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/aiohttp_session/init.py", line 199, in factory response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 295, in auth_middleware return await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware response = await handler(request) ^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle result = await handler(request, request.match_info) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/decorators.py", line 71, in with_admin return await func(self, request, *args, *kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper return await method(view, request, data, args, kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 172, in post return await self._post_impl(request, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 179, in _post_impl return await super()._post_impl(request, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 84, in _post_impl result = await self._flow_mgr.async_init( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1215, in async_init flow, result = await self._async_init(flow_id, handler, context, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1235, in _async_init flow = await self.async_create_flow(handler, context=context, data=data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/config_entries.py", line 1372, in async_create_flow handler = await _async_get_flow_handler( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2683, in _async_get_flow_handler await _load_integration(hass, domain, hass_config) File "/usr/src/homeassistant/homeassistant/config_entries.py", line 2660, in _load_integration await async_process_deps_reqs(hass, hass_config, integration) File "/usr/src/homeassistant/homeassistant/setup.py", line 559, in async_process_deps_reqs await requirements.async_get_integration_with_requirements( File "/usr/src/homeassistant/homeassistant/requirements.py", line 53, in async_get_integration_with_requirements return await manager.async_get_integration_with_requirements(domain) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/requirements.py", line 179, in async_get_integration_with_requirements await self._async_process_integration(integration, done) File "/usr/src/homeassistant/homeassistant/requirements.py", line 195, in _async_process_integration await self.async_process_requirements( File "/usr/src/homeassistant/homeassistant/requirements.py", line 277, in async_process_requirements self._raise_for_failed_requirements(name, missing) File "/usr/src/homeassistant/homeassistant/requirements.py", line 305, in _raise_for_failed_requirements raise RequirementsNotFound(integration, [req]) homeassistant.requirements.RequirementsNotFound: Requirements for wyzeapi not found: ['wyzeapy==0.5.21'].

ulek commented 2 months ago

@brg468 this is definitely bit temperamental on my end. Sometimes it will not work for the reboots then work for next two etc. Had times where it only loaded some of my devices (cameras but not bulbs, bulbs but not cameras) Haven't noticed any sort of consistency one way or another.

GreggTom commented 2 months ago

Error Config flow could not be loaded: {"message":"Invalid handler specified"}

GreggTom commented 2 months ago

Logger: homeassistant.config_entries Source: config_entries.py:2664 First occurred: 3:07:54 PM (1 occurrences) Last logged: 3:07:54 PM

Error occurred loading flow for integration wyzeapi: No module named 'wyzeapy'

brg468 commented 2 months ago

@GreggTom I don't think your issue is related to the original issue here. Something is off with your setup. Try removing everything again from HA and HACS, and make sure you have noha-wyzeapifolder in custom_components after that. Also if you ever tried adding wyzeapyfolder to you config make sure that's gone too.

brg468 commented 2 months ago

The main issue might be a symptom of the token expiration issue that was corrected here: https://github.com/SecKatie/wyzeapy/pull/83

Unfortunately it's not part of the current version, but there are steps outlined here to run the updated code for now: https://github.com/SecKatie/ha-wyzeapi/issues/567#issuecomment-2065548636

Might be worth a try for anyone with the original issue.

ulek commented 2 months ago

@brg468 I will check #576 and see if I can get updated code to run and see how that changes things

ulek commented 2 months ago

@brg468 Finally managed to get to executing your recommendations. Upgraded to HA Yellow not too long a go, and that is my first real foray into SBC. rebooted couple of times and it looks like it is fine but I will monitor and see if I have any issues.

Thanks for the pointers

ulek commented 1 month ago

@brg468 looks like no joy for me at the moment. 2024.5.4 came and back to failed to set up and token_manager.py issues

brg468 commented 1 month ago

@ulek You have the wyzeapy folder from my branch in your config folder still?

ulek commented 1 month ago

Yep.

With a caveat that I have not deleted it but not sure if update did something to it

Edit edit.

Yep confirmed that I still see wyzeapy in my config folder

brg468 commented 1 month ago

The HA update shouldn’t have changed anything.

I’m not sure what else to try, I can’t replicate this issue, I’ve never had a failed to setup issue, and only rarely had a token issue before that update. It makes me wonder if there’s something going on with HA Yellow that credentials aren’t being stored/updated correctly.

ulek commented 1 month ago

Not impossible. But it did run for quite a while without any issues. But it looks like there is something funky even though I have the wyzeapy from your branch in the config folder the log suggests that calls to it the one from custom components.

File "/config/custom_components/wyzeapi/token_manager.py", line 45, in inner_function

Hardware veteran but software wise know just enough how to be dangerous so correct me I'm wrong.

I will definitely try to delete and copy the wyzeapy back to yellow to see what happen

brg468 commented 1 month ago

That’s correct, wyzeapi is still being accessed from custom_components, but the dependency lib is wyzeapy (a little confusing I know) which holds the files that were updated. So the stack trace will still reference back to the files in custom_components eventually. Putting the wyzeapy folder in config is just a workaround because that folder and other dependencies are usually buried in an inaccessible location on most installs.

ulek commented 1 month ago

yea figured there would be some dependency reference that is not transparent here.

I have reuploaded the folder and it seems to be ok again.

Will see how well that holds up

github-actions[bot] commented 3 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.