al-one / hass-xiaomi-miot

Automatic integrate all Xiaomi devices to HomeAssistant via miot-spec, support Wi-Fi, BLE, ZigBee devices. 小米米家智能家居设备接入Hass集成
https://miot-spec.com
Apache License 2.0
4.63k stars 659 forks source link

在 home assistant 2021.11.5 版本上,操作设备会报如下错误 #267

Open nhchmg opened 2 years ago

nhchmg commented 2 years ago

Non-thread-safe operation invoked on an event loop other than the current one

Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/homeassistant/components/websocket_api/commands.py", line 185, in handle_call_service await hass.services.async_call( File "/usr/local/lib/python3.8/dist-packages/homeassistant/core.py", line 1495, in async_call task.result() File "/usr/local/lib/python3.8/dist-packages/homeassistant/core.py", line 1530, in _execute_service await handler.job.target(service_call) File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/entity_component.py", line 213, in handle_service await self.hass.helpers.service.entity_service_call( File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/service.py", line 667, in entity_service_call future.result() # pop exception if have File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/entity.py", line 863, in async_request_call await coro File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/service.py", line 704, in _handle_entity_call await result File "/usr/local/lib/python3.8/dist-packages/homeassistant/components/cover/init.py", line 276, in async_open_cover await self.hass.async_add_executor_job(ft.partial(self.open_cover, *kwargs)) File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(self.args, self.kwargs) File "/inhost/custom_components/xiaomi_miot/cover.py", line 241, in open_cover return self.motor_control(open_cover=True, kwargs) File "/inhost/custom_components/xiaomi_miot/cover.py", line 233, in motor_control ret = self.set_property(self._prop_motor_control, val) File "/inhost/custom_components/xiaomi_miot/init.py", line 1402, in set_property result = self.set_miot_property(siid, piid, value) File "/inhost/custom_components/xiaomi_miot/init.py", line 1456, in set_miot_property self.async_write_ha_state() File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/entity.py", line 486, in async_write_ha_state self._async_write_ha_state() File "/usr/local/lib/python3.8/dist-packages/homeassistant/helpers/entity.py", line 596, in _async_write_ha_state self.hass.states.async_set( File "/usr/local/lib/python3.8/dist-packages/homeassistant/core.py", line 1232, in async_set self._bus.async_fire( File "/usr/local/lib/python3.8/dist-packages/homeassistant/core.py", line 734, in async_fire self._hass.async_add_hass_job(job, event) File "/usr/local/lib/python3.8/dist-packages/homeassistant/core.py", line 365, in async_add_hass_job self.loop.call_soon(hassjob.target, *args) File "/usr/lib/python3.8/asyncio/base_events.py", line 721, in call_soon self._check_thread() File "/usr/lib/python3.8/asyncio/base_events.py", line 758, in _check_thread raise RuntimeError( RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one

al-one commented 2 years ago

该报错日志最近还有产生吗?

schneivo77 commented 2 years ago

Hi, I'm getting the same error when I send commands to my Smartmi Airpurifier (zhimi.airpurifier.za1).

The command works, so the airpurifier turns on/off when I use the xiami-miot switch for example, but the error messages appear everytime.

Here's the error from the logs that appears when I use the on/off switch:

2022-03-05 13:08:25 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140684693088432] Non-thread-safe operation invoked on an event loop other than the current one
Traceback (most recent call last):
  File "/workspaces/core/homeassistant/components/websocket_api/commands.py", line 192, in handle_call_service
    await hass.services.async_call(
  File "/workspaces/core/homeassistant/core.py", line 1636, in async_call
    task.result()
  File "/workspaces/core/homeassistant/core.py", line 1673, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/workspaces/core/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/workspaces/core/homeassistant/helpers/service.py", line 668, in entity_service_call
    future.result()  # pop exception if have
  File "/workspaces/core/homeassistant/helpers/entity.py", line 931, in async_request_call
    await coro
  File "/workspaces/core/homeassistant/helpers/service.py", line 705, in _handle_entity_call
    await result
  File "/workspaces/core/homeassistant/helpers/entity.py", line 993, in async_turn_off
    await self.hass.async_add_executor_job(ft.partial(self.turn_off, **kwargs))
  File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/workspaces/core/config/custom_components/xiaomi_miot/switch.py", line 154, in turn_off
    return self.set_parent_property(val)
  File "/workspaces/core/config/custom_components/xiaomi_miot/__init__.py", line 2185, in set_parent_property
    ret = self.call_parent('set_miot_property', prop.service.iid, prop.iid, val)
  File "/workspaces/core/config/custom_components/xiaomi_miot/__init__.py", line 2142, in call_parent
    ret = getattr(self._parent, f)(*args, **kwargs)
  File "/workspaces/core/config/custom_components/xiaomi_miot/__init__.py", line 1650, in set_miot_property
    self.async_write_ha_state()
  File "/workspaces/core/homeassistant/helpers/entity.py", line 539, in async_write_ha_state
    self._async_write_ha_state()
  File "/workspaces/core/homeassistant/helpers/entity.py", line 663, in _async_write_ha_state
    self.hass.states.async_set(
  File "/workspaces/core/homeassistant/core.py", line 1373, in async_set
    self._bus.async_fire(
  File "/workspaces/core/homeassistant/core.py", line 862, in async_fire
    self._hass.async_add_hass_job(job, event)
  File "/workspaces/core/homeassistant/core.py", line 446, in async_add_hass_job
    self.loop.call_soon(hassjob.target, *args)
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 748, in call_soon
    self._check_thread()
  File "/usr/local/lib/python3.9/asyncio/base_events.py", line 785, in _check_thread
    raise RuntimeError(
RuntimeError: Non-thread-safe operation invoked on an event loop other than the current one

I'm running the latest version of Home Assistant (core-2022.4.0.dev0) with VSC Remote Containers (so it runs in a docker container) and use the latest github version of xiaomi-miot (0.5.3).