mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +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,7 +156,6 @@ 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}
|
||||||
|
|
||||||
@ -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:
|
for dev in devices_not_created:
|
||||||
if dev in HOMEMATIC_DEVICES:
|
if dev in HOMEMATIC_DEVICES:
|
||||||
try:
|
try:
|
||||||
@ -207,7 +202,8 @@ 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]:
|
||||||
|
continue
|
||||||
elements = device.ELEMENT + 1
|
elements = device.ELEMENT + 1
|
||||||
metadata = {}
|
metadata = {}
|
||||||
|
|
||||||
@ -230,16 +226,13 @@ def _get_devices(device_type, keys):
|
|||||||
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
|
|
||||||
ordered_device_dict["name"] = name
|
|
||||||
ordered_device_dict["button"] = channel
|
|
||||||
if param is not None:
|
if param is not None:
|
||||||
ordered_device_dict["param"] = param
|
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