mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
HomeMatic: Enable entity registry (#15950)
* Set unique ID * Excluding setups that resolve names * Added support for resolvenames again
This commit is contained in:
parent
3fbb56d5fb
commit
69b694ff26
@ -47,6 +47,7 @@ ATTR_ERRORCODE = 'error'
|
|||||||
ATTR_MESSAGE = 'message'
|
ATTR_MESSAGE = 'message'
|
||||||
ATTR_MODE = 'mode'
|
ATTR_MODE = 'mode'
|
||||||
ATTR_TIME = 'time'
|
ATTR_TIME = 'time'
|
||||||
|
ATTR_UNIQUE_ID = 'unique_id'
|
||||||
|
|
||||||
EVENT_KEYPRESS = 'homematic.keypress'
|
EVENT_KEYPRESS = 'homematic.keypress'
|
||||||
EVENT_IMPULSE = 'homematic.impulse'
|
EVENT_IMPULSE = 'homematic.impulse'
|
||||||
@ -173,6 +174,7 @@ DEVICE_SCHEMA = vol.Schema({
|
|||||||
vol.Required(ATTR_INTERFACE): cv.string,
|
vol.Required(ATTR_INTERFACE): cv.string,
|
||||||
vol.Optional(ATTR_CHANNEL, default=1): vol.Coerce(int),
|
vol.Optional(ATTR_CHANNEL, default=1): vol.Coerce(int),
|
||||||
vol.Optional(ATTR_PARAM): cv.string,
|
vol.Optional(ATTR_PARAM): cv.string,
|
||||||
|
vol.Optional(ATTR_UNIQUE_ID): cv.string,
|
||||||
})
|
})
|
||||||
|
|
||||||
CONFIG_SCHEMA = vol.Schema({
|
CONFIG_SCHEMA = vol.Schema({
|
||||||
@ -530,16 +532,21 @@ def _get_devices(hass, discovery_type, keys, interface):
|
|||||||
_LOGGER.debug("%s: Handling %s: %s: %s",
|
_LOGGER.debug("%s: Handling %s: %s: %s",
|
||||||
discovery_type, key, param, channels)
|
discovery_type, key, param, channels)
|
||||||
for channel in channels:
|
for channel in channels:
|
||||||
name = _create_ha_name(
|
name = _create_ha_id(
|
||||||
name=device.NAME, channel=channel, param=param,
|
name=device.NAME, channel=channel, param=param,
|
||||||
count=len(channels)
|
count=len(channels)
|
||||||
)
|
)
|
||||||
|
unique_id = _create_ha_id(
|
||||||
|
name=key, channel=channel, param=param,
|
||||||
|
count=len(channels)
|
||||||
|
)
|
||||||
device_dict = {
|
device_dict = {
|
||||||
CONF_PLATFORM: "homematic",
|
CONF_PLATFORM: "homematic",
|
||||||
ATTR_ADDRESS: key,
|
ATTR_ADDRESS: key,
|
||||||
ATTR_INTERFACE: interface,
|
ATTR_INTERFACE: interface,
|
||||||
ATTR_NAME: name,
|
ATTR_NAME: name,
|
||||||
ATTR_CHANNEL: channel
|
ATTR_CHANNEL: channel,
|
||||||
|
ATTR_UNIQUE_ID: unique_id
|
||||||
}
|
}
|
||||||
if param is not None:
|
if param is not None:
|
||||||
device_dict[ATTR_PARAM] = param
|
device_dict[ATTR_PARAM] = param
|
||||||
@ -554,7 +561,7 @@ def _get_devices(hass, discovery_type, keys, interface):
|
|||||||
return device_arr
|
return device_arr
|
||||||
|
|
||||||
|
|
||||||
def _create_ha_name(name, channel, param, count):
|
def _create_ha_id(name, channel, param, count):
|
||||||
"""Generate a unique entity id."""
|
"""Generate a unique entity id."""
|
||||||
# HMDevice is a simple device
|
# HMDevice is a simple device
|
||||||
if count == 1 and param is None:
|
if count == 1 and param is None:
|
||||||
@ -725,6 +732,7 @@ class HMDevice(Entity):
|
|||||||
self._interface = config.get(ATTR_INTERFACE)
|
self._interface = config.get(ATTR_INTERFACE)
|
||||||
self._channel = config.get(ATTR_CHANNEL)
|
self._channel = config.get(ATTR_CHANNEL)
|
||||||
self._state = config.get(ATTR_PARAM)
|
self._state = config.get(ATTR_PARAM)
|
||||||
|
self._unique_id = config.get(ATTR_UNIQUE_ID)
|
||||||
self._data = {}
|
self._data = {}
|
||||||
self._homematic = None
|
self._homematic = None
|
||||||
self._hmdevice = None
|
self._hmdevice = None
|
||||||
@ -740,6 +748,11 @@ class HMDevice(Entity):
|
|||||||
"""Load data init callbacks."""
|
"""Load data init callbacks."""
|
||||||
yield from self.hass.async_add_job(self.link_homematic)
|
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
|
@property
|
||||||
def should_poll(self):
|
def should_poll(self):
|
||||||
"""Return false. HomeMatic states are pushed by the XML-RPC Server."""
|
"""Return false. HomeMatic states are pushed by the XML-RPC Server."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user