First batch of (minor) fixes as suggested by @balloob

This commit is contained in:
Daniel Perna 2016-06-25 15:10:19 +02:00
parent dfe1b8d934
commit 04748e3ad1

View File

@ -15,7 +15,6 @@ homematic:
"""
import time
import logging
from collections import OrderedDict
from homeassistant.const import EVENT_HOMEASSISTANT_STOP,\
EVENT_PLATFORM_DISCOVERED,\
ATTR_SERVICE,\
@ -157,7 +156,6 @@ def system_callback_handler(src, *args):
# When devices of this type are found
# they are setup in HA and an event is fired
if found_devices:
try:
component = get_component(component_name)
config = {component.DOMAIN: found_devices}
@ -178,10 +176,7 @@ def system_callback_handler(src, *args):
}
}
)
# 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:
if dev in HOMEMATIC_DEVICES:
try:
@ -207,7 +202,8 @@ def _get_devices(device_type, keys):
keys = HOMEMATIC.devices
for key in keys:
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]:
continue
elements = device.ELEMENT + 1
metadata = {}
@ -230,16 +226,13 @@ def _get_devices(device_type, keys):
name = _create_ha_name(name=device.NAME,
channel=channel,
param=param)
ordered_device_dict = OrderedDict()
ordered_device_dict["platform"] = "homematic"
ordered_device_dict["address"] = key
ordered_device_dict["name"] = name
ordered_device_dict["button"] = channel
device_dict = dict(platform="homematic", address=key,
name=name, button=channel)
if param is not None:
ordered_device_dict["param"] = param
device_dict["param"] = param
# Add new device
device_arr.append(ordered_device_dict)
device_arr.append(device_dict)
_LOGGER.debug("%s autodiscovery: %s", device_type, str(device_arr))
return device_arr
@ -282,15 +275,15 @@ def _create_ha_name(name, channel, param):
# Has multiple elements/channels
if channel > 1 and param is None:
return name + " " + str(channel)
return "{} {}".format(name, channel)
# With multiple param first elements
if channel == 1 and param is not None:
return name + " " + param
return "{} {}".format(name, param)
# Multiple param on object with multiple elements
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):