ZHA Broken in 2023.6?

ZHA no longer loads and i see the following error in the logs:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/loader.py", line 813, in get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1204, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/usr/src/homeassistant/homeassistant/components/zha/__init__.py", line 20, in <module>
    from . import websocket_api
  File "/usr/src/homeassistant/homeassistant/components/zha/websocket_api.py", line 23, in <module>
    from .api import (
  File "/usr/src/homeassistant/homeassistant/components/zha/api.py", line 12, in <module>
    from .core.const import (
  File "/usr/src/homeassistant/homeassistant/components/zha/core/__init__.py", line 3, in <module>
    from .device import ZHADevice
  File "/usr/src/homeassistant/homeassistant/components/zha/core/device.py", line 35, in <module>
    from . import const
  File "/usr/src/homeassistant/homeassistant/components/zha/core/const.py", line 7, in <module>
    import bellows.zigbee.application
  File "/usr/local/lib/python3.11/site-packages/bellows/zigbee/application.py", line 31, in <module>
    import bellows.ezsp
  File "/usr/local/lib/python3.11/site-packages/bellows/ezsp/__init__.py", line 24, in <module>
    import bellows.uart
  File "/usr/local/lib/python3.11/site-packages/bellows/uart.py", line 11, in <module>
    import zigpy.serial
  File "/usr/local/lib/python3.11/site-packages/zigpy/serial.py", line 9, in <module>
    import serial_asyncio as pyserial_asyncio
  File "/usr/local/lib/python3.11/site-packages/serial_asyncio/__init__.py", line 408, in <module>
    @asyncio.coroutine
     ^^^^^^^^^^^^^^^^^
AttributeError: module 'asyncio' has no attribute 'coroutine'

From my reading it looks like coroutine was removed from asyncio in Python 3.11.

As you might imagine, ZHA being broken would have made quite a fuss :wink:

That one seems specific to your setup, of which we know nothing.

Yep, which is why I was confused why I could not find anything in the forums. My system is pretty vanilla using HassOS:

Home Assistant 2023.6.3
Supervisor 2023.06.2
Operating System 10.3
Frontend 20230608.0 - latest

Running on raspberry pi 4 (ssd).

My zigbee stick is the HUSBZB-1.

According to this SO post coroutine was removed from asyncio in 3.11 (which I know 2023.6 upgraded to):

I assume some dependency needs to be updated, but I wasn’t sure how to.

You wouldn’t have a custom integration with an old dependency on pyserial-asyncio, would you (<0.4)?
There you can find those coroutine decorators, but not in the 0.6 that HA itself downloads.

Yep that was it. I had an old custom integration that I hadn’t updated in a while. Thanks for pointing me in the correct direction.

It seems I have the same problem. Is there somewhere a guide to migrate away from the pyserial-syncio? I can’t find it.

[edit]I figured it out.
Using replacing import serial_asyncio with import serial_asyncio_fast as serial_asyncio seems to do the trick for fixing the custom integration.[/edit]

[edit2]The problem with ZHA remains. How do I get rid of the deprecated pyserial-syncio so it doesn’t cause a conflict anymore?[/edit2]

I had missed the dependency declaration in the manifest.json of the custom component.

So the solution consists of:

  • Using replacing import serial_asyncio with import serial_asyncio_fast as serial_asyncio seems to do the trick for fixing the custom integration.
  • Replacing pyserial_asyncio==0.4 by pyserial_asyncio_fast==0.13 in manifest.json of the custom component (versions may vary depending on the plugin)
  • Restart the Home Assistant docker container to pull in the right dependencies and to leave out the deprecated one.