Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions homeassistant/components/homematic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
ATTR_MESSAGE = 'message'
ATTR_MODE = 'mode'
ATTR_TIME = 'time'
ATTR_UNIQUE_ID = 'unique_id'

EVENT_KEYPRESS = 'homematic.keypress'
EVENT_IMPULSE = 'homematic.impulse'
Expand Down Expand Up @@ -173,6 +174,7 @@
vol.Required(ATTR_INTERFACE): cv.string,
vol.Optional(ATTR_CHANNEL, default=1): vol.Coerce(int),
vol.Optional(ATTR_PARAM): cv.string,
vol.Optional(ATTR_UNIQUE_ID): cv.string,
})

CONFIG_SCHEMA = vol.Schema({
Expand Down Expand Up @@ -530,16 +532,21 @@ def _get_devices(hass, discovery_type, keys, interface):
_LOGGER.debug("%s: Handling %s: %s: %s",
discovery_type, key, param, channels)
for channel in channels:
name = _create_ha_name(
name = _create_ha_id(
name=device.NAME, channel=channel, param=param,
count=len(channels)
)
unique_id = _create_ha_id(
name=key, channel=channel, param=param,
count=len(channels)
)
device_dict = {
CONF_PLATFORM: "homematic",
ATTR_ADDRESS: key,
ATTR_INTERFACE: interface,
ATTR_NAME: name,
ATTR_CHANNEL: channel
ATTR_CHANNEL: channel,
ATTR_UNIQUE_ID: unique_id
}
if param is not None:
device_dict[ATTR_PARAM] = param
Expand All @@ -554,7 +561,7 @@ def _get_devices(hass, discovery_type, keys, interface):
return device_arr


def _create_ha_name(name, channel, param, count):
def _create_ha_id(name, channel, param, count):
"""Generate a unique entity id."""
# HMDevice is a simple device
if count == 1 and param is None:
Expand Down Expand Up @@ -725,6 +732,7 @@ def __init__(self, config):
self._interface = config.get(ATTR_INTERFACE)
self._channel = config.get(ATTR_CHANNEL)
self._state = config.get(ATTR_PARAM)
self._unique_id = config.get(ATTR_UNIQUE_ID)
self._data = {}
self._homematic = None
self._hmdevice = None
Expand All @@ -740,6 +748,11 @@ def async_added_to_hass(self):
"""Load data init callbacks."""
yield from self.hass.async_add_job(self.link_homematic)

@property
def unique_id(self):
"""Return unique ID. HomeMatic entity IDs are unique by default."""
return self._unique_id.replace(" ", "_")

@property
def should_poll(self):
"""Return false. HomeMatic states are pushed by the XML-RPC Server."""
Expand Down