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

Unable to use library in HomeAssistant #12

Open
kingy444 opened this issue Aug 16, 2024 · 5 comments
Open

Unable to use library in HomeAssistant #12

kingy444 opened this issue Aug 16, 2024 · 5 comments

Comments

@kingy444
Copy link

First of all 🥳 for the publushing of the API https://developer.electrolux.one/documentation/reference

I have been improving on the homeassistant_electrolux_status project and nearing stage where i can submit a PR to the project (its a very extensive rewrite)

Looking at the differences (0.0.16...0.0.18) it doesnt seem to be too important for that - but thought i would raise the issue

The __version__ variable was removed in 94459e1
Adding it back in locally I can again use the package

2024-08-16 06:01:48.064 ERROR (MainThread) [homeassistant.setup] Setup failed for 'electrolux_status': Unable to import component: cannot import name '__version__' from partially initialized module 'pyelectroluxocp' (most likely due to a circular import) (/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/__init__.py)
Traceback (most recent call last):
  File "/workspaces/core/homeassistant/loader.py", line 1007, in async_get_component
    comp = await self.hass.async_add_import_executor_job(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/core/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/core/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/workspaces/core/homeassistant/components/electrolux_status/__init__.py", line 25, in <module>
    from .coordinator import ElectroluxCoordinator
  File "/workspaces/core/homeassistant/components/electrolux_status/coordinator.py", line 11, in <module>
    from pyelectroluxocp import OneAppApi
  File "/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/__init__.py", line 5, in <module>
    from .oneAppApi import OneAppApi
  File "/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/oneAppApi.py", line 7, in <module>
    from .oneAppApiClient import ClientToken, OneAppApiClient, UserToken
  File "/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/oneAppApiClient.py", line 9, in <module>
    from pyelectroluxocp import __version__
ImportError: cannot import name '__version__' from partially initialized module 'pyelectroluxocp' (most likely due to a circular import) (/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/workspaces/core/homeassistant/setup.py", line 334, in _async_setup_component
    component = await integration.async_get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/core/homeassistant/loader.py", line 1027, in async_get_component
    self._component_future.result()
  File "/workspaces/core/homeassistant/loader.py", line 1019, in async_get_component
    comp = self._get_component()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/core/homeassistant/loader.py", line 1067, in _get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/workspaces/core/homeassistant/util/loop.py", line 200, in protected_loop_func
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/workspaces/core/homeassistant/components/electrolux_status/__init__.py", line 25, in <module>
    from .coordinator import ElectroluxCoordinator
  File "/workspaces/core/homeassistant/components/electrolux_status/coordinator.py", line 11, in <module>
    from pyelectroluxocp import OneAppApi
  File "/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/__init__.py", line 5, in <module>
    from .oneAppApi import OneAppApi
  File "/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/oneAppApi.py", line 7, in <module>
    from .oneAppApiClient import ClientToken, OneAppApiClient, UserToken
  File "/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/oneAppApiClient.py", line 9, in <module>
    from pyelectroluxocp import __version__
ImportError: cannot import name '__version__' from partially initialized module 'pyelectroluxocp' (most likely due to a circular import) (/home/vscode/.local/ha-venv/lib/python3.12/site-packages/pyelectroluxocp/__init__.py)
@Woyken
Copy link
Owner

Woyken commented Aug 27, 2024

Do you really need the __version__ import?

If you really need to have version, you can use this

import importlib.metadata

version = importlib.metadata.version('pyelectroluxocp')

@kingy444
Copy link
Author

I believe the issue is coming from within the package. You are still referencing the __version__ variable here:

from pyelectroluxocp import __version__

If i remove that import and hard code the version here the package runs:

"User-Agent": "pyelectroluxocp/" + __version__,

@Woyken
Copy link
Owner

Woyken commented Aug 27, 2024

Oh no, sorry about that 🤦

@Woyken
Copy link
Owner

Woyken commented Aug 27, 2024

Can you try importing 0.0.19?

@kingy444
Copy link
Author

Can you try importing 0.0.19?

Yep - 0.0.19 is working after making applying that fix 👍

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

No branches or pull requests

2 participants