change autodiscovery
This commit is contained in:
parent
a687bdb388
commit
e0e9d3c57b
7 changed files with 45 additions and 22 deletions
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue