home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.07k stars 31.09k forks source link

Error with custom components #8051

Closed woutercoppens closed 7 years ago

woutercoppens commented 7 years ago

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version): 0.46.1

Python release (python3 --version): 3.5.2 Hassio release: 0.8

Component/platform: custom component

Description of problem: I wrote a custom component to control the openmotics hub: https://www.openmotics.com/ The source code can be found at: https://github.com/woutercoppens/home-assistant

When I copy my modules in the modules directory of Home Assistant, everything works fine. However when I put my modules in the custom_components directory, I get all kinds of errors (see traceback).

Each time Home Assistant is upgraded, I have to copy the modules back into the components directory.

Right now it is not possible to create custom components that consists of multiple modules. Expected:

Problem-relevant configuration.yaml entries and steps to reproduce:

openmotics:
  username: wouter
  password: ******
  host: 192.168.0.135

Traceback (if applicable):

2017-06-15 10:30:38 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.switch.openmotics. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/homeassistant/loader.py", line 141, in get_component
    module = importlib.import_module(path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/config/custom_components/switch/openmotics.py", line 9, in <module>
    from homeassistant.components.openmotics import (OM_LOGIN, OM_SWITCHES, OM_OUTPUT_STATUS)
ImportError: No module named 'homeassistant.components.openmotics'
2017-06-15 10:30:39 ERROR (MainThread) [homeassistant.loader] Unable to find component switch.openmotics
2017-06-15 10:30:39 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform switch.openmotics: Platform not found.
2017-06-15 10:30:39 WARNING (Thread-4) [homeassistant.components.emulated_hue] Listen IP address not specified, auto-detected address is 192.168.0.5
2017-06-15 10:30:40 WARNING (Thread-4) [homeassistant.components.emulated_hue] When targetting Google Home, listening port has to be port 80
2017-06-15 10:30:42 WARNING (MainThread) [homeassistant.setup] Setup of light is taking over 10 seconds.
2017-06-15 10:30:42 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.light.openmotics. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/homeassistant/loader.py", line 141, in get_component
    module = importlib.import_module(path)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/config/custom_components/light/openmotics.py", line 9, in <module>
    from homeassistant.components.openmotics import (OM_LOGIN, OM_LIGHTS, OM_OUTPUT_STATUS)
ImportError: No module named 'homeassistant.components.openmotics'
2017-06-15 10:30:42 ERROR (MainThread) [homeassistant.loader] Unable to find component light.openmotics
2017-06-15 10:30:42 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform light.openmotics: Platform not found.

Additional info: I even tried to replace 'from homeassistant.components.openmotics import ...' with 'from 'homeassistant.custom_components.openmotics import ...', but that doesn't work neither.

fabaff commented 7 years ago

Instead of

from homeassistant.components.openmotics import (OM_LOGIN, OM_LIGHTS, OM_OUTPUT_STATUS)

use

from custom_components.openmotics import (OM_LOGIN, OM_LIGHTS, OM_OUTPUT_STATUS)
woutercoppens commented 7 years ago

Other people are having the same problem, so please add this to the documentation.