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:
Paulus Schoutsen 2018-04-09 10:09:08 -04:00 committed by GitHub
parent cb51553c2d
commit 73de749411
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 271 additions and 45 deletions

View file

@ -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.