mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
First batch of (minor) fixes as suggested by @balloob
This commit is contained in:
parent
dfe1b8d934
commit
04748e3ad1
@ -15,7 +15,6 @@ homematic:
|
|||||||
"""
|
"""
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
from collections import OrderedDict
|
|
||||||
from homeassistant.const import EVENT_HOMEASSISTANT_STOP,\
|
from homeassistant.const import EVENT_HOMEASSISTANT_STOP,\
|
||||||
EVENT_PLATFORM_DISCOVERED,\
|
EVENT_PLATFORM_DISCOVERED,\
|
||||||
ATTR_SERVICE,\
|
ATTR_SERVICE,\
|
||||||
@ -157,31 +156,27 @@ def system_callback_handler(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:
|
||||||
try:
|
component = get_component(component_name)
|
||||||
component = get_component(component_name)
|
config = {component.DOMAIN: found_devices}
|
||||||
config = {component.DOMAIN: found_devices}
|
|
||||||
|
|
||||||
# Ensure component is loaded
|
# Ensure component is loaded
|
||||||
homeassistant.bootstrap.setup_component(
|
homeassistant.bootstrap.setup_component(
|
||||||
_HM_DISCOVER_HASS,
|
_HM_DISCOVER_HASS,
|
||||||
component.DOMAIN,
|
component.DOMAIN,
|
||||||
config)
|
config)
|
||||||
|
|
||||||
# Fire discovery event
|
# Fire discovery event
|
||||||
_HM_DISCOVER_HASS.bus.fire(
|
_HM_DISCOVER_HASS.bus.fire(
|
||||||
EVENT_PLATFORM_DISCOVERED, {
|
EVENT_PLATFORM_DISCOVERED, {
|
||||||
ATTR_SERVICE: discovery_type,
|
ATTR_SERVICE: discovery_type,
|
||||||
ATTR_DISCOVERED: {
|
ATTR_DISCOVERED: {
|
||||||
ATTR_DISCOVER_DEVICES:
|
ATTR_DISCOVER_DEVICES:
|
||||||
found_devices,
|
found_devices,
|
||||||
ATTR_DISCOVER_CONFIG: ''
|
ATTR_DISCOVER_CONFIG: ''
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
# pylint: disable=broad-except
|
)
|
||||||
except Exception as err:
|
|
||||||
_LOGGER.error("Failed to autotetect %s with" +
|
|
||||||
"error '%s'", component_name, str(err))
|
|
||||||
for dev in devices_not_created:
|
for dev in devices_not_created:
|
||||||
if dev in HOMEMATIC_DEVICES:
|
if dev in HOMEMATIC_DEVICES:
|
||||||
try:
|
try:
|
||||||
@ -207,39 +202,37 @@ def _get_devices(device_type, keys):
|
|||||||
keys = HOMEMATIC.devices
|
keys = HOMEMATIC.devices
|
||||||
for key in keys:
|
for key in keys:
|
||||||
device = HOMEMATIC.devices[key]
|
device = HOMEMATIC.devices[key]
|
||||||
if device.__class__.__name__ in HM_DEVICE_TYPES[device_type]:
|
if device.__class__.__name__ not in HM_DEVICE_TYPES[device_type]:
|
||||||
elements = device.ELEMENT + 1
|
continue
|
||||||
metadata = {}
|
elements = device.ELEMENT + 1
|
||||||
|
metadata = {}
|
||||||
|
|
||||||
# Load metadata if needed to generate a param list
|
# Load metadata if needed to generate a param list
|
||||||
if device_type is DISCOVER_SENSORS:
|
if device_type is DISCOVER_SENSORS:
|
||||||
metadata.update(device.SENSORNODE)
|
metadata.update(device.SENSORNODE)
|
||||||
elif device_type is DISCOVER_BINARY_SENSORS:
|
elif device_type is DISCOVER_BINARY_SENSORS:
|
||||||
metadata.update(device.BINARYNODE)
|
metadata.update(device.BINARYNODE)
|
||||||
|
|
||||||
# Also add supported events as binary type
|
# Also add supported events as binary type
|
||||||
for event, channel in device.EVENTNODE.items():
|
for event, channel in device.EVENTNODE.items():
|
||||||
if event in SUPPORT_HM_EVENT_AS_BINMOD:
|
if event in SUPPORT_HM_EVENT_AS_BINMOD:
|
||||||
metadata.update({event: channel})
|
metadata.update({event: channel})
|
||||||
|
|
||||||
params = _create_params_list(device, metadata)
|
params = _create_params_list(device, metadata)
|
||||||
|
|
||||||
# Generate options for 1...n elements with 1...n params
|
# Generate options for 1...n elements with 1...n params
|
||||||
for channel in range(1, elements):
|
for channel in range(1, elements):
|
||||||
for param in params[channel]:
|
for param in params[channel]:
|
||||||
name = _create_ha_name(name=device.NAME,
|
name = _create_ha_name(name=device.NAME,
|
||||||
channel=channel,
|
channel=channel,
|
||||||
param=param)
|
param=param)
|
||||||
ordered_device_dict = OrderedDict()
|
device_dict = dict(platform="homematic", address=key,
|
||||||
ordered_device_dict["platform"] = "homematic"
|
name=name, button=channel)
|
||||||
ordered_device_dict["address"] = key
|
if param is not None:
|
||||||
ordered_device_dict["name"] = name
|
device_dict["param"] = param
|
||||||
ordered_device_dict["button"] = channel
|
|
||||||
if param is not None:
|
|
||||||
ordered_device_dict["param"] = param
|
|
||||||
|
|
||||||
# Add new device
|
# Add new device
|
||||||
device_arr.append(ordered_device_dict)
|
device_arr.append(device_dict)
|
||||||
_LOGGER.debug("%s autodiscovery: %s", device_type, str(device_arr))
|
_LOGGER.debug("%s autodiscovery: %s", device_type, str(device_arr))
|
||||||
return device_arr
|
return device_arr
|
||||||
|
|
||||||
@ -282,15 +275,15 @@ def _create_ha_name(name, channel, param):
|
|||||||
|
|
||||||
# Has multiple elements/channels
|
# Has multiple elements/channels
|
||||||
if channel > 1 and param is None:
|
if channel > 1 and param is None:
|
||||||
return name + " " + str(channel)
|
return "{} {}".format(name, channel)
|
||||||
|
|
||||||
# With multiple param first elements
|
# With multiple param first elements
|
||||||
if channel == 1 and param is not None:
|
if channel == 1 and param is not None:
|
||||||
return name + " " + param
|
return "{} {}".format(name, param)
|
||||||
|
|
||||||
# Multiple param on object with multiple elements
|
# Multiple param on object with multiple elements
|
||||||
if channel > 1 and param is not None:
|
if channel > 1 and param is not None:
|
||||||
return name + " " + str(channel) + " " + param
|
return "{} {} {}".format(name, channel, param)
|
||||||
|
|
||||||
|
|
||||||
def setup_hmdevice_entity_helper(hmdevicetype, config, add_callback_devices):
|
def setup_hmdevice_entity_helper(hmdevicetype, config, add_callback_devices):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user