Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZHA Toolkit fails to initialise on Home Assistant Core: 2023.7.2 #176

Closed
mitchins opened this issue Jul 14, 2023 · 8 comments · Fixed by #177
Closed

ZHA Toolkit fails to initialise on Home Assistant Core: 2023.7.2 #176

mitchins opened this issue Jul 14, 2023 · 8 comments · Fixed by #177

Comments

@mitchins
Copy link

mitchins commented Jul 14, 2023

Upgraded from 2023.7.1 to 2023.7.2

Configuration invalid!
Component error: zha_toolkit - cannot import name 'version' from 'zigpy' (/usr/local/lib/python3.11/site-packages/zigpy/init.py)

Home Assistant 2023.7.2
Supervisor 2023.07.1
Operating System 10.3
Frontend 20230705.1 - latest

Digging into this further, we see in: custom_components/zha_toolkit/utils.py
16: from zigpy import __version__ as zigpy_version

This (latest) commit in ZigPy against init.py seems to have broken it:
zigpy/zigpy@50f2e6e

To be specific the 0.56.2 version is the issue, from here the version information is not embedded anymore, they prefer to use GIT versioning, but of course the python lib folder is not a working copy.

I was able to ascertain via a pip query on home assistant core that it is 0.56.2, is that something that can be done for ZHA Toolkit, or does someone have a smarter idea?

image

@kayloehmann
Copy link

Same here!

@ChristophCaina
Copy link
Contributor

yep same here.
Here are 'all' logs I could find for ZHA:

Logger: homeassistant.setup
Source: custom_components/zha_toolkit/utils.py:16
Integration: 🧰 ZHA Toolkit (documentation, issues)
First occurred: 06:58:27 (1 occurrences)
Last logged: 06:58:27

Setup failed for custom integration zha_toolkit: Unable to import component: cannot import name '__version__' from 'zigpy' (/usr/local/lib/python3.11/site-packages/zigpy/__init__.py)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 215, in _async_setup_component
    component = integration.get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  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 "/config/custom_components/zha_toolkit/__init__.py", line 11, in <module>
    from . import utils as u
  File "/config/custom_components/zha_toolkit/utils.py", line 16, in <module>
    from zigpy import __version__ as zigpy_version
ImportError: cannot import name '__version__' from 'zigpy' (/usr/local/lib/python3.11/site-packages/zigpy/__init__.py)
Logger: homeassistant.components.hassio
Source: components/hassio/__init__.py:568
Integration: Home Assistant Supervisor (documentation, issues)
First occurred: 07:01:47 (1 occurrences)
Last logged: 07:01:47

The system cannot restart because the configuration is not valid: Component error: zha_toolkit - cannot import name '__version__' from 'zigpy' (/usr/local/lib/python3.11/site-packages/zigpy/__init__.py)
Logger: homeassistant.components.websocket_api.http.connection
Source: components/hassio/__init__.py:579
Integration: Home Assistant WebSocket API (documentation, issues)
First occurred: 07:01:47 (1 occurrences)
Last logged: 07:01:47

[139735400947408] The system cannot restart because the configuration is not valid: Component error: zha_toolkit - cannot import name '__version__' from 'zigpy' (/usr/local/lib/python3.11/site-packages/zigpy/__init__.py)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 205, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1965, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2005, in _execute_service
    return await cast(
           ^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/hassio/__init__.py", line 579, in async_handle_core_service
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Component error: zha_toolkit - cannot import name '__version__' from 'zigpy' (/usr/local/lib/python3.11/site-packages/zigpy/__init__.py)

Maybe noteworthy:
Another integration I am using (SolarEdge Modbus) is throwing the same error about File "<frozen importlib._bootstrap>

@mitchins
Copy link
Author

mitchins commented Jul 14, 2023

I've managed to create a work around locally, it's a hack - no two ways about it, but it'll buy some time until a proper fix can be evaluated:

I've edited utils.py in the custom_components/zha_toolkit, and updated anything to do with zigpy imports (note that I moved the version import to the bottom so that a missing zigpy will fail first rather than assume a version).

from zigpy import types as t
from zigpy.exceptions import ControllerException, DeliveryError
from zigpy.zcl import foundation as f
try:
    from zigpy import __version__ as zigpy_version
except ImportError:
    __version__ = "0.56.2"

image

@pdecat
Copy link
Contributor

pdecat commented Jul 14, 2023

Here's my fix for this issue: #177

@mitchins
Copy link
Author

@pdecat thats the correct solution, nice.

@mdeweerd
Copy link
Owner

@pdecat Thank you for providing the fix.
I have merged this in v0.9.3, currently in pre-release mode ("beta") as I refactored to no longer the "packaging" module.

I am upgrading to 2023.7.2, and if ok the package will be put in "release" state.

@rofo69
Copy link

rofo69 commented Jul 14, 2023

Its not fully fixed in v0.9.3 which just got released, I am still seeing this in the logs:

Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 468, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 703, in _async_call_service_step
response_data = await self._async_run_long_action(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 665, in _async_run_long_action
return long_task.result()
^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 1965, in async_call
response_data = await coro
^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/core.py", line 2005, in _execute_service
return await cast(
^^^^^^^^^^^
File "/config/custom_components/zha_toolkit/init.py", line 704, in toolkit_service
"zigpy_version": zigpy.version,
^^^^^^^^^^^^^^^^^
AttributeError: module 'zigpy' has no attribute 'version'

The fix looks pretty simple.

@erkr
Copy link

erkr commented Jul 14, 2023

@mdeweerd
Thanks for the quick fixes!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants