tolwi / hassio-ecoflow-cloud

EcoFlow Cloud Integration for Home Assistant
281 stars 47 forks source link

HA 2024.4.2: Non-thread-safe operation invoked on an event loop other than the current one #229

Closed andrewjswan closed 1 month ago

andrewjswan commented 2 months ago
2024-04-09 13:41:51.590 INFO (SyncWorker_10) [custom_components.ecoflow_cloud.mqtt.ecoflow_mqtt] Re-connecting to MQTT Broker mqtt-e.ecoflow.com:8883
2024-04-09 13:41:51.784 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved:   File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 222, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 210, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1980, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1508, in _run_async_call_action
    hass.async_run_hass_job(job, time_tracker_utcnow())
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1602, in _interval_listener
    hass.async_run_hass_job(self._run_job, now, background=True)
  File "/usr/src/homeassistant/homeassistant/core.py", line 840, in async_run_hass_job
    return self.async_add_hass_job(
  File "/usr/src/homeassistant/homeassistant/core.py", line 695, in async_add_hass_job
    task = self.loop.run_in_executor(None, hassjob.target, *args)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 860, in run_in_executor
    return futures.wrap_future(
  File "/usr/local/lib/python3.12/asyncio/futures.py", line 417, in wrap_future
    new_future = loop.create_future()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 448, in create_future
    return futures.Future(loop=self)
Traceback (most recent call last):
  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/ecoflow_cloud/sensor.py", line 328, in __check_status
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1181, in _async_write_ha_state
    hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2181, in async_set
    self._bus._async_fire(  # pylint: disable=protected-access
  File "/usr/src/homeassistant/homeassistant/core.py", line 1459, in _async_fire
    self._hass.async_add_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 690, in async_add_hass_job
    self.loop.call_soon(hassjob.target, *args)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_thread()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 832, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
andrewjswan commented 2 months ago
2024-04-10 12:26:53.080 ERROR (Thread-11 (_thread_main)) [root] Uncaught thread exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.12/threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1164, in _loop
    rc = self.loop_read()
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 1556, in loop_read
    rc = self._packet_read()
         ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 2439, in _packet_read
    rc = self._packet_handle()
         ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3033, in _packet_handle
    return self._handle_publish()
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3327, in _handle_publish
    self._handle_on_message(message)
  File "/usr/local/lib/python3.12/site-packages/paho/mqtt/client.py", line 3570, in _handle_on_message
    on_message(self, self._userdata, message)
  File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 257, in on_json_message
    self.data.update_data(raw)
  File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 153, in update_data
    self.__broadcast()
  File "/config/custom_components/ecoflow_cloud/mqtt/ecoflow_mqtt.py", line 157, in __broadcast
    self.__params_observable.on_next(self.params)
  File "/usr/local/lib/python3.12/site-packages/reactivex/subject/subject.py", line 59, in on_next
    super().on_next(value)
  File "/usr/local/lib/python3.12/site-packages/reactivex/observer/observer.py", line 39, in on_next
    self._on_next_core(value)
  File "/usr/local/lib/python3.12/site-packages/reactivex/subject/subject.py", line 66, in _on_next_core
    observer.on_next(value)
  File "/usr/local/lib/python3.12/site-packages/reactivex/observer/autodetachobserver.py", line 28, in on_next
    self._on_next(value)
  File "/config/custom_components/ecoflow_cloud/entities/__init__.py", line 85, in _updated
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1181, in _async_write_ha_state
    hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2181, in async_set
    self._bus._async_fire(  # pylint: disable=protected-access
  File "/usr/src/homeassistant/homeassistant/core.py", line 1459, in _async_fire
    self._hass.async_add_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 690, in async_add_hass_job
    self.loop.call_soon(hassjob.target, *args)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_thread()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 832, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
andrewjswan commented 2 months ago
2024-04-10 12:27:54.899 ERROR (MainThread) [homeassistant] Error doing job: Future exception was never retrieved:   File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 222, in <module>
    sys.exit(main())
  File "/usr/src/homeassistant/homeassistant/__main__.py", line 210, in main
    exit_code = runner.run(runtime_conf)
  File "/usr/src/homeassistant/homeassistant/runner.py", line 189, in run
    return loop.run_until_complete(setup_and_run_hass(runtime_config))
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 672, in run_until_complete
    self.run_forever()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 639, in run_forever
    self._run_once()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 1980, in _run_once
    handle._run()
  File "/usr/local/lib/python3.12/asyncio/events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1508, in _run_async_call_action
    hass.async_run_hass_job(job, time_tracker_utcnow())
  File "/usr/src/homeassistant/homeassistant/core.py", line 837, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 1602, in _interval_listener
    hass.async_run_hass_job(self._run_job, now, background=True)
  File "/usr/src/homeassistant/homeassistant/core.py", line 840, in async_run_hass_job
    return self.async_add_hass_job(
  File "/usr/src/homeassistant/homeassistant/core.py", line 695, in async_add_hass_job
    task = self.loop.run_in_executor(None, hassjob.target, *args)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 860, in run_in_executor
    return futures.wrap_future(
  File "/usr/local/lib/python3.12/asyncio/futures.py", line 417, in wrap_future
    new_future = loop.create_future()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 448, in create_future
    return futures.Future(loop=self)
Traceback (most recent call last):
  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/ecoflow_cloud/sensor.py", line 328, in __check_status
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 998, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 1181, in _async_write_ha_state
    hass.states.async_set(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2181, in async_set
    self._bus._async_fire(  # pylint: disable=protected-access
  File "/usr/src/homeassistant/homeassistant/core.py", line 1459, in _async_fire
    self._hass.async_add_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 690, in async_add_hass_job
    self.loop.call_soon(hassjob.target, *args)
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 795, in call_soon
    self._check_thread()
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 832, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one
ajan1 commented 2 months ago

Same problem here.

andrewjswan commented 2 months ago

@tolwi Any news?

KarinBerg commented 1 month ago

Have you tried to modify these files from this pull request on your Home Assistant installation? Maybe it fixes also your error. https://github.com/tolwi/hassio-ecoflow-cloud/pull/234