Skip to content

Custom component loading cleanup#14211

Merged
pvizeli merged 7 commits intodevfrom
custom-component-cleanup
May 1, 2018
Merged

Custom component loading cleanup#14211
pvizeli merged 7 commits intodevfrom
custom-component-cleanup

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented May 1, 2018

Description:

Our custom component loading scheme was quite the hack. It mounts the config dir as a Python path and then does hacks doing from custom_components import bla. However, this means that putting a Python scripts in your config dir would also make them loadable ! Create <config>/requests.py and you will override the requests lib and break a bunch of things. Not good.

So this is a rewrite. It will no longer mount the config dir, instead we load from the config dir based on name/path. We will also now cache the components and custom components on a per HASS instance basis, meaning that a bunch of tests that relied on 'test' component being set in another test, will break.

Breaking change: It's temporarily not possible to override scene or automation platforms unless they have the same config format as existing platform.

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@balloob balloob requested a review from a team as a code owner May 1, 2018 00:05
async def test_adding_unknown_device_to_config(mock_device_tracker_conf, hass):
"""Test the adding of unknown devices to configuration file."""
scanner = get_component('device_tracker.test').SCANNER
scanner = get_component(self.hass, 'device_tracker.test').SCANNER
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

undefined name 'self'

Comment thread homeassistant/loader.py Outdated
return OrderedSet()

dep_load_order = _load_order_component(dependency, load_order, loading)
dep_load_order = _load_order_component(hass, dependency, load_order, loading)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (85 > 79 characters)

Comment thread homeassistant/loader.py
"dependencies are installed"), path)

_LOGGER.error("Unable to find component %s", comp_name)
def _load_module(path, name):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This didn't make much sense for me initially either, this blog post really helped: https://manikos.github.io/how-pythons-import-machinery-works

@balloob balloob requested review from a team and kellerza as code owners May 1, 2018 17:18
@balloob balloob changed the title WIP: Custom component cleanup Custom component loading cleanup May 1, 2018
@pvizeli pvizeli merged commit 83d300f into dev May 1, 2018
@pvizeli pvizeli deleted the custom-component-cleanup branch May 1, 2018 18:57
@pvizeli
Copy link
Copy Markdown
Member

pvizeli commented May 1, 2018

Nice cleanup and usage of hass.components

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants