Add a load_platform mechanism (#2012)

* discovery.load_platform method

* rm grep
This commit is contained in:
Johann Kellerman 2016-05-10 07:48:03 +02:00 committed by Paulus Schoutsen
parent 1d0bc1ee66
commit ec9544b9c3
3 changed files with 42 additions and 0 deletions

View file

@ -55,12 +55,24 @@ class EntityComponent(object):
self._setup_platform(p_type, p_config)
if self.discovery_platforms:
# Discovery listener for all items in discovery_platforms array
# passed from a component's setup method (e.g. light/__init__.py)
discovery.listen(
self.hass, self.discovery_platforms.keys(),
lambda service, info:
self._setup_platform(self.discovery_platforms[service], {},
info))
# Generic discovery listener for loading platform dynamically
# Refer to: homeassistant.components.discovery.load_platform()
def load_platform_callback(service, info):
"""Callback to load a platform."""
platform = info.pop(discovery.LOAD_PLATFORM)
self._setup_platform(platform, {}, info if info else None)
discovery.listen(
self.hass, discovery.LOAD_PLATFORM + '.' + self.domain,
load_platform_callback)
def extract_from_service(self, service):
"""Extract all known entities from a service call.