Daanoz / ha-google-photos

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

Error calling next_media after core update 2024.5.0 #48

Closed goodlucknow closed 4 months ago

goodlucknow commented 4 months ago

Version of the custom_component

v0.6.2

Describe the bug

Error thrown when calling next_media.

Debug log


2024-05-01 23:54:52.984 WARNING (SyncWorker_0) [homeassistant.helpers.frame] Detected that custom integration 'google_photos' calls async_create_task from a thread at custom_components/google_photos/camera.py, line 135: self.hass.async_add_job(self.coordinator.select_next(mode)), please report it to the author of the 'google_photos' custom integration
2024-05-01 23:54:52.986 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: Detected that custom integration 'google_photos' calls async_create_task from a thread at custom_components/google_photos/camera.py, line 135: self.hass.async_add_job(self.coordinator.select_next(mode)). Please report it to the author of the 'google_photos' custom integration.
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/camera.py", line 135, in next_media
    self.hass.async_add_job(self.coordinator.select_next(mode))
  File "/usr/src/homeassistant/homeassistant/core.py", line 645, in async_add_job
    return self.async_create_task(target, eager_start=eager_start)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 816, in async_create_task
    self.verify_event_loop_thread("async_create_task")
  File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
    frame.report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'google_photos' calls async_create_task from a thread at custom_components/google_photos/camera.py, line 135: self.hass.async_add_job(self.coordinator.select_next(mode)). Please report it to the author of the 'google_photos' custom integration.
2024-05-01 23:54:52.989 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [281472507413696] 
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 793, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1731, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 451, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 503, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 533, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 501, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 736, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 699, in _async_run_long_action
    return await long_task
           ^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2738, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2779, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 975, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 1047, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/google_photos/camera.py", line 135, in next_media
    self.hass.async_add_job(self.coordinator.select_next(mode))
  File "/usr/src/homeassistant/homeassistant/core.py", line 645, in async_add_job
    return self.async_create_task(target, eager_start=eager_start)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 816, in async_create_task
    self.verify_event_loop_thread("async_create_task")
  File "/usr/src/homeassistant/homeassistant/core.py", line 440, in verify_event_loop_thread
    frame.report(
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 162, in report
    _report_integration(what, integration_frame, level, error_if_integration)
  File "/usr/src/homeassistant/homeassistant/helpers/frame.py", line 203, in _report_integration
    raise RuntimeError(
RuntimeError: Detected that custom integration 'google_photos' calls async_create_task from a thread at custom_components/google_photos/camera.py, line 135: self.hass.async_add_job(self.coordinator.select_next(mode)). Please report it to the author of the 'google_photos' custom integration.
goodlucknow commented 4 months ago

note that photos will still update if done automatically via update interval. this occurs when calling next media service manually.

goodlucknow commented 4 months ago

one workaround is a script that sets update interval to 10 seconds, waits 10 seconds, then sets update interval back to never, instead of calling next media service. just in case anyone else is also having this issue.

MasterDimi commented 4 months ago

Same here: Failed to call service google_photos/next_media. Detected that custom integration 'google_photos' calls async_create_task from a thread at custom_components/google_photos/camera.py, line 135: self.hass.async_add_job(self.coordinator.select_next(mode)). Please report it to the author of the 'google_photos' custom integration.

For now i will use the workaround

Daanoz commented 4 months ago

I have a pre-release version ready that should solve it: https://github.com/Daanoz/ha-google-photos/releases/tag/v0.6.3. If I don't see any issues the coming days I'll do a full release. Let me know if you encounter any issues.

goodlucknow commented 4 months ago

Magic, thanks so much. I'll try this out soon as I can.

goodlucknow commented 4 months ago

Installed here and all working, no errors so far