Zha fails on quirks name import since upgrade to Python 3.7.3

Hi, I was using HA 0.90.1 in a venv with Python 3.5,3 (the latest built for Raspbian) but decided to upgrade Python into a replacement venv following Python 3.6 upgrade of a virtualenv. With Python 3.7 being reasonably mature now, I used the 3.7.3 source and built as per those instructions with a couple of minor additions (sudo apt install libffi-dev and make -j4 ). Whilst doing this I also upgraded HA to 0.90.2.

Now when I start up I get the following error, which results in no Zigbee devices working in my configuration.

Error setting up entry /dev/ttyAMA0 for zha

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/config_entries.py", line 302, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/srv/homeassistant/lib/python3.7/site-packages/homeassistant/components/zha/__init__.py", line 109, in async_setup_entry
    import zhaquirks  # noqa
  File "/srv/homeassistant/lib/python3.7/site-packages/zhaquirks/__init__.py", line 66, in <module>
    importlib.import_module(modname)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/srv/homeassistant/lib/python3.7/site-packages/zhaquirks/xiaomi/aqara/cube_aqgl01.py", line 7, in <module>
    from zigpy.quirks.xiaomi import AqaraMagicCubeSensor
ImportError: cannot import name 'AqaraMagicCubeSensor' from 'zigpy.quirks.xiaomi' (/srv/homeassistant/lib/python3.7/site-packages/zigpy/quirks/xiaomi/__init__.py)

A couple of similar looking issues here are this and that, but the suggested solutions were to use a virtual environment, which I already am.

Any suggestions welcome

I tried a different way of recreating the virtual environment. The article above obtains a list of packages from the old venv, and installs these into the new venv. Instead I tried following You just won the lottery. How do you build the most stable HA server?

This suggests just blowing away the old venv and populating the new one by simply installing the latest version of HA, which will automatically pull in all the python dependencies it needs, and at the correct versions.

That worked much better, I no longer get the errors, and my ZHA devices are back :slight_smile:

2 Likes

Having same issue, did you get it resolved?

Hi @salinaju, welcome to the HA community.

Thanks for reporting this problem too. I managed to recreate my virtual environment in a much simpler way, and that seemed to work just fine afterwards. I wrote up some notes and instructions at https://github.com/artmg/MuGammaPi/wiki/Home-Assistant#upgrade-python

I may also have updated Home Assistant too - you’ll find instructions for that on the same page. I hope this works out for you.

Hi @artmg

I’m having this same problem. I followed the instructions you provided and no luck. By default, it seems that ‘pip3 install homeassistant’ doesn’t install zigpy - and once I install zigpy, I start getting the error you pasted above “ImportError: cannot import name ‘AqaraMagicCubeSensor’ from ‘zigpy.quirks.xiaomi’ (/srv/homeassistant/lib/python3.7/site-packages/zigpy/quirks/xiaomi/init.py)”

Any ideas?

Hi @beatsWorking, welcome to the HA community :smile:

Normally the python requirements would be installed by pip, and then the first thing hass does when you run it manually is to download any extras required by your config. I have just reviewed the instruction I linked above, and realised that there was one step I missed out…

After stopping the service you need to remove or rename the folder containing the old venv. So that would be …

# first ensure the service is stopped for the upgrade
sudo systemctl stop home-assistant@homeassistant

# save the old environment
sudo mv /srv/homeassistant{,.`date +%y%m%d`}
# permission a folder for the new one
sudo mkdir /srv/homeassistant
sudo chown homeassistant:homeassistant /srv/homeassistant

# back in the user context set up the new venv
sudo -u homeassistant -H -s

now continue as per the link. Please let me know if that helps, and I will update the article.

@artmg - I was deleted the old venv, so I don’t think that’s it. If I follow the steps you provided, I get a “no version available” error and a “timeout” error. Then I install zigpy and zigpy-deconz and I get the error you got above “ImportError: cannot import name ‘AqaraMagicCubeSensor’…”.

I’m wondering if there’s another package that hass isn’t catching that I need to install manually…

@beatsWorking I am pretty sure that I did this on a clean Raspbian lite image, and only needed sudo apt install -y python3 python3-venv python3-pip as system dependencies, and that the python and hass modules all came down with the instructions shown. At one point I did have python3 -m pip install wheel in there too, but I have since blown away that venv and all worked fine on later attempts.

So just to understand where these errors occur… “no version available” happens when you … ? And where does the timeout happen. Perhaps if you could paste the command lines you use and a sample of the terminal output immediately before the errors, it may help to diagnose. Also, please specify which exact versions of python3 and homeassistant are being pulled down.

Oh, and actually there is one other thing I noticed - you are using zigpy-deconz, whereas I have been using zha - I wonder if there is not a bug or breaking change in zigpy that the zha developer has fixed, but that has not yet been addressed in deconz? Anyhow, if you first start with the diags I mention above, then that will help understand exactly where this error is arising. Thanks.