Skip to content

Use config entry to setup platforms#13752

Merged
balloob merged 5 commits intodevfrom
config-entry-platform
Apr 9, 2018
Merged

Use config entry to setup platforms#13752
balloob merged 5 commits intodevfrom
config-entry-platform

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented Apr 8, 2018

Description:

Architecture diagram

The config entries journey continues 😎 Have been very happy with the architecture thus far. Have not needed a refactor yet.

In this PR, remove the use of "discovery" in favor of being able to delegate a config entry to another component. By default a config entry is passed to the component the entry belongs to. The owning component can choose to delegate it to another component to set it up too (using hass.config_entries.delegate_entry(entry, component)). This will only work if the other component is capable of this, which will be the case of all Entity Components. In this case I have only added it to the light component.

The EntityComponent has been updated to create a new EntityPlatform to manage the entities of the config entry and set up the config entry.

This change also paves the way for the following future functionality:

  • Support config entry unloading by leveraging the existing platform reset functionality
  • Link config entry ID to entities in the entity registry, which paves the way for:
    • Showing in UI which entities belong to which config entry
    • Clean up entity registry when we remove a config entry

CC @Kane610 because you've been playing with config entries too

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.

self.platform_name, wait_time)
async_track_point_in_time(
hass, self.async_setup(platform_config, discovery_info, tries),
hass, self._async_setup_platform(async_create_setup_task, tries),
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 (81 > 79 characters)

Comment thread homeassistant/config_entries.py Outdated
await async_setup_component(
self.hass, entry.domain, self._hass_config)

async def delegate_entry(self, entry, component):
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.

I am not happy with the name "delegate_entry". As delegation means to "entrust (a task or responsibility) to another person" (per Google). In this case, the main component will setup the entry and then want other components to handle the entry too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about chain?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

forward_entry?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Looks good so far.

Copy link
Copy Markdown
Member

@pvizeli pvizeli left a comment

Choose a reason for hiding this comment

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

Amazing

@balloob balloob changed the title WIP: Use config entry to setup platforms Use config entry to setup platforms Apr 9, 2018
@balloob balloob merged commit 73de749 into dev Apr 9, 2018
@balloob balloob deleted the config-entry-platform branch April 9, 2018 14:09
@balloob balloob mentioned this pull request Apr 27, 2018
Adminiuga pushed a commit to Adminiuga/home-assistant that referenced this pull request Jun 25, 2018
* Use config entry to setup platforms

* Rename to async_forward_entry

* Add tests

* Catch if platform not exists for entry
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
@ghost ghost removed the platform: light.hue label Mar 21, 2019
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.

6 participants