mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
change autodiscovery
This commit is contained in:
parent
a687bdb388
commit
e0e9d3c57b
@ -55,6 +55,11 @@ SUPPORT_HM_EVENT_AS_BINMOD = [
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""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,
|
return homematic.setup_hmdevice_entity_helper(HMBinarySensor,
|
||||||
config,
|
config,
|
||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
@ -17,11 +17,9 @@ import time
|
|||||||
import logging
|
import logging
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, \
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP, \
|
||||||
EVENT_PLATFORM_DISCOVERED, \
|
|
||||||
ATTR_SERVICE, \
|
|
||||||
ATTR_DISCOVERED, \
|
ATTR_DISCOVERED, \
|
||||||
STATE_UNKNOWN
|
STATE_UNKNOWN
|
||||||
from homeassistant.loader import get_component
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
import homeassistant.bootstrap
|
import homeassistant.bootstrap
|
||||||
|
|
||||||
@ -149,26 +147,10 @@ def system_callback_handler(hass, config, src, *args):
|
|||||||
# When devices of this type are found
|
# When devices of this type are found
|
||||||
# they are setup in HA and an event is fired
|
# they are setup in HA and an event is fired
|
||||||
if found_devices:
|
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
|
# Fire discovery event
|
||||||
hass.bus.fire(
|
discovery.load_platform(hass, component_name, DOMAIN, {
|
||||||
EVENT_PLATFORM_DISCOVERED, {
|
ATTR_DISCOVER_DEVICES: found_devices
|
||||||
ATTR_SERVICE: discovery_type,
|
}, config)
|
||||||
ATTR_DISCOVERED: {
|
|
||||||
ATTR_DISCOVER_DEVICES:
|
|
||||||
found_devices,
|
|
||||||
ATTR_DISCOVER_CONFIG: ''
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
for dev in devices_not_created:
|
for dev in devices_not_created:
|
||||||
if dev in HOMEMATIC_DEVICES:
|
if dev in HOMEMATIC_DEVICES:
|
||||||
@ -282,6 +264,17 @@ def _create_ha_name(name, channel, param):
|
|||||||
return "{} {} {}".format(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):
|
def setup_hmdevice_entity_helper(hmdevicetype, config, add_callback_devices):
|
||||||
"""Helper to setup Homematic devices."""
|
"""Helper to setup Homematic devices."""
|
||||||
if HOMEMATIC is None:
|
if HOMEMATIC is None:
|
||||||
|
@ -29,6 +29,11 @@ DEPENDENCIES = ['homematic']
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""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,
|
return homematic.setup_hmdevice_entity_helper(HMLight,
|
||||||
config,
|
config,
|
||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
@ -29,6 +29,11 @@ DEPENDENCIES = ['homematic']
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""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,
|
return homematic.setup_hmdevice_entity_helper(HMRollershutter,
|
||||||
config,
|
config,
|
||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
@ -41,6 +41,11 @@ HM_UNIT_HA_CAST = {
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""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,
|
return homematic.setup_hmdevice_entity_helper(HMSensor,
|
||||||
config,
|
config,
|
||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
@ -28,6 +28,11 @@ DEPENDENCIES = ['homematic']
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""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,
|
return homematic.setup_hmdevice_entity_helper(HMSwitch,
|
||||||
config,
|
config,
|
||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
@ -28,6 +28,11 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
def setup_platform(hass, config, add_callback_devices, discovery_info=None):
|
||||||
"""Setup the platform."""
|
"""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,
|
return homematic.setup_hmdevice_entity_helper(HMThermostat,
|
||||||
config,
|
config,
|
||||||
add_callback_devices)
|
add_callback_devices)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user