Use config entry to setup platforms (#13752)
* Use config entry to setup platforms * Rename to async_forward_entry * Add tests * Catch if platform not exists for entry
This commit is contained in:
parent
cb51553c2d
commit
73de749411
12 changed files with 271 additions and 45 deletions
|
@ -93,6 +93,26 @@ class EntityComponent(object):
|
|||
discovery.async_listen_platform(
|
||||
self.hass, self.domain, component_platform_discovered)
|
||||
|
||||
async def async_setup_entry(self, config_entry):
|
||||
"""Setup a config entry."""
|
||||
platform_type = config_entry.domain
|
||||
platform = await async_prepare_setup_platform(
|
||||
self.hass, self.config, self.domain, platform_type)
|
||||
|
||||
if platform is None:
|
||||
return False
|
||||
|
||||
key = config_entry.entry_id
|
||||
|
||||
if key in self._platforms:
|
||||
raise ValueError('Config entry has already been setup!')
|
||||
|
||||
self._platforms[key] = self._async_init_entity_platform(
|
||||
platform_type, platform
|
||||
)
|
||||
|
||||
return await self._platforms[key].async_setup_entry(config_entry)
|
||||
|
||||
@callback
|
||||
def async_extract_from_service(self, service, expand_group=True):
|
||||
"""Extract all known and available entities from a service call.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue