Daanoz / ha-google-photos

Home Assistant Google Photos integration
MIT License
84 stars 5 forks source link

Choosing new album makes entities unavaible #11

Closed Cptkex82 closed 1 year ago

Cptkex82 commented 1 year ago

Version of the custom_component

0.4.3

Configuration


Add your logs here.

Describe the bug

Adding the Integrations work fine, i can see the two test images i have in favorites. Changing to the desired album (name fotoram 210130 till 230325) submits as okey, but then all sensors become unavailble.

Debug log

Logger: homeassistant.components.select
Source: custom_components/google_photos/coordinator.py:67
Integration: Select (documentation, issues)
First occurred: 10:35:20 (1 occurrences)
Last logged: 10:35:20

Error while setting up google_photos platform for select
Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 452, in _async_update_data
    await self.update_data()
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 366, in update_data
    await self._refresh_album_list()
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 435, in _refresh_album_list
    await self._get_album_list()
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 424, in _get_album_list
    self.album_list = await self.hass.async_add_executor_job(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 442, in _async_update_data
    async with async_timeout.timeout(30):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/async_timeout/__init__.py", line 129, in __aexit__
    self._do_exit(exc_type)
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/async_timeout/__init__.py", line 212, in _do_exit
    raise asyncio.TimeoutError
TimeoutError

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

Traceback (most recent call last):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/homeassistant/helpers/update_coordinator.py", line 239, in _async_refresh
    self.data = await self._async_update_data()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 454, in _async_update_data
    raise UpdateFailed(f"Error communicating with API: {err}") from err
homeassistant.helpers.update_coordinator.UpdateFailed: Error communicating with API: 

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

Traceback (most recent call last):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/homeassistant/helpers/entity_platform.py", line 293, in _async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/select.py", line 34, in async_setup_entry
    coordinator = await coordinator_manager.get_coordinator(album_id)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/coordinator.py", line 67, in get_coordinator
    await self.coordinator_first_refresh.get(album_id)
homeassistant.exceptions.ConfigEntryNotReady: Error communicating with API: 
Cptkex82 commented 1 year ago

If its relevant, reloading the integrations requires a restart with the following error:


This error originated from a custom integration.

Logger: homeassistant.config_entries
Source: custom_components/google_photos/__init__.py:80
Integration: Google Photos (documentation, issues)
First occurred: 10:45:04 (1 occurrences)
Last logged: 10:45:04

Error unloading entry kexan82@gmail.com for google_photos
Traceback (most recent call last):
  File "/srv/homeassistant/venv_3.11.0/lib/python3.11/site-packages/homeassistant/config_entries.py", line 539, in async_unload
    result = await component.async_unload_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/homeassistant/.homeassistant/custom_components/google_photos/__init__.py", line 80, in async_unload_entry
    for service_name in hass.services.async_services()[DOMAIN]:
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^
KeyError: 'google_photos'
Cptkex82 commented 1 year ago

changed name of folder to fotoram_230325 and restarted and the error is gone. Could the space in the name have caused the issue? folder has 3900 images but the media count on the fotoram folder says 0. It displays the folder preview image but cant switch images.

Favourites folder shows correct number (2) though and can change image.

Cptkex82 commented 1 year ago

Extracted 127 images from fotoram album to a test album. Added and it displays the correct number of images. It would seem that the problem is related to the large number of images in fotoram?

darrynlowe commented 1 year ago

I had a similar problem with an album with 20,000 images. A small ~200 image album worked fine, but the big one caused things to die.

Daanoz commented 1 year ago

Thanks for the report, will have to think how to solve this. Currently I need the entire list of media items from the album, which seems to be a problem. Maybe I can try to load them more slowly or something.

Cptkex82 commented 1 year ago

i just tried 497 images and it works. if its of any interest, im running HA core on a rpi 3b.

Daanoz commented 1 year ago

Had to move some stuff around to get this working in an acceptable manner. I'm a bit constrained with the Google api on solving this. Ended up with the following:

This allows the integration to start quickly, downside being that for the first couple of images that are shown the pool of items will be small when a random item is selected, but I think that's acceptable. Ideally I would only need to load all items once, but there is no way that I found I can check if the album has changed, so the only way is reloading everything.

Cptkex82 commented 1 year ago

i´ve updated the integration. The sensors dont go unavailible when i choose the 4000+ folder but its still not showing any images. The count is 0 after +1 day. tried renaming och re-adding the integration to no avail. Test album 400+ still works though so a step in the right direction. Cannot see any errors.

Daanoz commented 1 year ago

Hmm, that's strange, I would at least expect 100 photo's to be loaded. After reloading the integration also no error is shown? Could you try removing (Via the device page) and re-adding the album?

Cptkex82 commented 1 year ago

no errors.

ive done the following. -removed integration -removed hacs installation -rebooted -installed via hacs -rebooted -created new photos album with the old images -readded integration -checked working state (no errors) -added the "new" photo album (no errors)

As of right now, i can see a count of 400 so it seems to be working now. Must have been some old bit of settings related to the old folder perhaps?

anyways thanks for the help, this can be closed!

Daanoz commented 1 year ago

Alright, let me know if you run into new issues!