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

No module named 'custom_components.zha_toolkit.const' #278

Closed
aauzi opened this issue Jan 2, 2025 · 4 comments
Closed

No module named 'custom_components.zha_toolkit.const' #278

aauzi opened this issue Jan 2, 2025 · 4 comments

Comments

@aauzi
Copy link

aauzi commented Jan 2, 2025

Hi,
after a git pull and restart of the component, the initialization failed with the following backtrace:

  File "/opt/homeassistant/.homeassistant/custom_components/zha_toolkit/__init__.py", line 20, in <module>
    from .const import DOMAIN
ModuleNotFoundError: No module named 'custom_components.zha_toolkit.const'

my workaround was to create the file: custom_components/zha_toolkit/const/__init__.py

diff --git a/custom_components/zha_toolkit/const/__init__.py b/custom_components/zha_toolkit/const/__init__.py
new file mode 100644
index 0000000..0510443
--- /dev/null
+++ b/custom_components/zha_toolkit/const/__init__.py
@@ -0,0 +1 @@
+DOMAIN = "zha_toolkit"
@mdeweerd
Copy link
Owner

mdeweerd commented Jan 2, 2025

Thank you for the feedback.

This was not released yet and I was not expecting that the project is pulled for using it ;-). I'll be more carefull when adding things to the main branch.

This is something that I do not understand about python yet.
I'ld expect 'from .const import DOMAIN' to get DOMAIN from const.py, but it doesnt when this is used in init.py and it does when used in another file...

I've changed the code a bit.

@aauzi
Copy link
Author

aauzi commented Jan 2, 2025

YW.
In fact you made me doubt about that workaround and I've checked the doc

Actually the following change DOES work very well, as well (after reverting what I've done tonight):

diff --git a/custom_components/zha_toolkit/const.py b/custom_components/zha_toolkit/const.py
new file mode 100644
index 0000000..0510443
--- /dev/null
+++ b/custom_components/zha_toolkit/const.py
@@ -0,0 +1 @@
+DOMAIN = "zha_toolkit"

Python's not that counterintuitive finally ;-) (at least with Python 3.13.1).

And, yes, I pull the main branch regularly.
I could stick to the releases but it's so interesting that I'm curious to see what you come up with.
I've learned a lot about zigbee thanks to you.

Many thanks for that.

PS: Do not change your coding habits, it's easy enough to set a tag and check it out if the main branch becomes 'too wild'.

@mdeweerd
Copy link
Owner

mdeweerd commented Jan 2, 2025

Happy to see that this helps with learning about zigbee.

I'll leave the code as is - normally I make the updates in dev so updating main is kind of the exception.

The changes are to add the config flow so that editing the configuration.yaml can be avoided.

Possibly all that remains to be done is to activate it by adding the appropriate "config_flow": true to manifest.json .

https://developers.home-assistant.io/docs/config_entries_config_flow_handler/#updating-the-manifest
https://developers.home-assistant.io/docs/creating_integration_manifest/

@mdeweerd
Copy link
Owner

mdeweerd commented Jan 6, 2025

Closing as this is fixed - the const.py file was not under version control.

@mdeweerd mdeweerd closed this as completed Jan 6, 2025
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