diff --git a/homeassistant/components/binary_sensor/homematic.py b/homeassistant/components/binary_sensor/homematic.py index d2005f99ba5..08ea2099445 100644 --- a/homeassistant/components/binary_sensor/homematic.py +++ b/homeassistant/components/binary_sensor/homematic.py @@ -55,6 +55,11 @@ SUPPORT_HM_EVENT_AS_BINMOD = [ def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" + if discovery_info: + return homematic.setup_hmdevice_discovery_helper(HMBinarySensor, + discovery_info, + add_callback_devices) + # Manual return homematic.setup_hmdevice_entity_helper(HMBinarySensor, config, add_callback_devices) diff --git a/homeassistant/components/homematic.py b/homeassistant/components/homematic.py index 6662c6bbe0d..5c23462e98d 100644 --- a/homeassistant/components/homematic.py +++ b/homeassistant/components/homematic.py @@ -17,11 +17,9 @@ import time import logging from functools import partial from homeassistant.const import EVENT_HOMEASSISTANT_STOP, \ - EVENT_PLATFORM_DISCOVERED, \ - ATTR_SERVICE, \ ATTR_DISCOVERED, \ STATE_UNKNOWN -from homeassistant.loader import get_component +from homeassistant.helpers import discovery from homeassistant.helpers.entity import Entity import homeassistant.bootstrap @@ -149,26 +147,10 @@ def system_callback_handler(hass, config, src, *args): # When devices of this type are found # they are setup in HA and an event is fired if found_devices: - component = get_component(component_name) - config = {component.DOMAIN: found_devices} - - # Ensure component is loaded - homeassistant.bootstrap.setup_component( - hass, - component.DOMAIN, - config) - # Fire discovery event - hass.bus.fire( - EVENT_PLATFORM_DISCOVERED, { - ATTR_SERVICE: discovery_type, - ATTR_DISCOVERED: { - ATTR_DISCOVER_DEVICES: - found_devices, - ATTR_DISCOVER_CONFIG: '' - } - } - ) + discovery.load_platform(hass, component_name, DOMAIN, { + ATTR_DISCOVER_DEVICES: found_devices + }, config) for dev in devices_not_created: if dev in HOMEMATIC_DEVICES: @@ -282,6 +264,17 @@ def _create_ha_name(name, channel, param): return "{} {} {}".format(name, channel, param) +def setup_hmdevice_discovery_helper(hmdevicetype, discovery_info, + add_callback_devices): + """Helper to setup Homematic devices with discovery info.""" + for config in discovery_info["devices"]: + ret = setup_hmdevice_entity_helper(hmdevicetype, config, + add_callback_devices) + if not ret: + _LOGGER.error("Setup discovery error with config %s", str(config)) + return True + + def setup_hmdevice_entity_helper(hmdevicetype, config, add_callback_devices): """Helper to setup Homematic devices.""" if HOMEMATIC is None: diff --git a/homeassistant/components/light/homematic.py b/homeassistant/components/light/homematic.py index 94dabb0f00a..159f3e4dbdc 100644 --- a/homeassistant/components/light/homematic.py +++ b/homeassistant/components/light/homematic.py @@ -29,6 +29,11 @@ DEPENDENCIES = ['homematic'] def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" + if discovery_info: + return homematic.setup_hmdevice_discovery_helper(HMLight, + discovery_info, + add_callback_devices) + # Manual return homematic.setup_hmdevice_entity_helper(HMLight, config, add_callback_devices) diff --git a/homeassistant/components/rollershutter/homematic.py b/homeassistant/components/rollershutter/homematic.py index e0dd5e5469f..737a7eb017d 100644 --- a/homeassistant/components/rollershutter/homematic.py +++ b/homeassistant/components/rollershutter/homematic.py @@ -29,6 +29,11 @@ DEPENDENCIES = ['homematic'] def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" + if discovery_info: + return homematic.setup_hmdevice_discovery_helper(HMRollershutter, + discovery_info, + add_callback_devices) + # Manual return homematic.setup_hmdevice_entity_helper(HMRollershutter, config, add_callback_devices) diff --git a/homeassistant/components/sensor/homematic.py b/homeassistant/components/sensor/homematic.py index 52ece78f59e..f6f3825199b 100644 --- a/homeassistant/components/sensor/homematic.py +++ b/homeassistant/components/sensor/homematic.py @@ -41,6 +41,11 @@ HM_UNIT_HA_CAST = { def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" + if discovery_info: + return homematic.setup_hmdevice_discovery_helper(HMSensor, + discovery_info, + add_callback_devices) + # Manual return homematic.setup_hmdevice_entity_helper(HMSensor, config, add_callback_devices) diff --git a/homeassistant/components/switch/homematic.py b/homeassistant/components/switch/homematic.py index 5a630f43022..16cc63a6708 100644 --- a/homeassistant/components/switch/homematic.py +++ b/homeassistant/components/switch/homematic.py @@ -28,6 +28,11 @@ DEPENDENCIES = ['homematic'] def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" + if discovery_info: + return homematic.setup_hmdevice_discovery_helper(HMSwitch, + discovery_info, + add_callback_devices) + # Manual return homematic.setup_hmdevice_entity_helper(HMSwitch, config, add_callback_devices) diff --git a/homeassistant/components/thermostat/homematic.py b/homeassistant/components/thermostat/homematic.py index a1ed06bc4bd..e654379d56e 100644 --- a/homeassistant/components/thermostat/homematic.py +++ b/homeassistant/components/thermostat/homematic.py @@ -28,6 +28,11 @@ _LOGGER = logging.getLogger(__name__) def setup_platform(hass, config, add_callback_devices, discovery_info=None): """Setup the platform.""" + if discovery_info: + return homematic.setup_hmdevice_discovery_helper(HMThermostat, + discovery_info, + add_callback_devices) + # Manual return homematic.setup_hmdevice_entity_helper(HMThermostat, config, add_callback_devices)