Skip to content

Instantly share code, notes, and snippets.

@torarnv
Created June 25, 2019 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save torarnv/66dd2fef525b291d04f95c0b05801aa1 to your computer and use it in GitHub Desktop.
Save torarnv/66dd2fef525b291d04f95c0b05801aa1 to your computer and use it in GitHub Desktop.
commit 19c5cf6fd483aed643109c93a271600dcbc984a8
Author: Tor Arne Vestbø <torarnv@gmail.com>
Date: Tue Jun 25 22:00:28 2019 +0200
zwave: Base value entity ids on their associated node entity id
When multiple nodes of the same manufacturer and model are added
to home assistant the node entities will get unique entity ids
in the form of e.g:
- zwave.manufacturer_model
- zwave.manufacturer_model_2
- zwave.manufacturer_model_3
When those nodes then report their values, the value entities
will end up with similarly suffixed entity ids, e.g:
- light.manufacturer_model_level
- light.manufacturer_model_level_2
- light.manufacturer_model_level_3
This is okey for a node with a single value, but quickly gets
unruly for multi-value nodes. A better approach is to base the
value node entity id on the already unique and suffixed entity
id of the node:
- light.manufacturer_model_level
- light.manufacturer_model_2_level
- light.manufacturer_model_3_level
This scales better, and allows the user to mentally map each
value node entity to its node just by looking at the entity id.
diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py
index 51e956e33..88819adf8 100644
--- a/homeassistant/components/zwave/__init__.py
+++ b/homeassistant/components/zwave/__init__.py
@@ -908,8 +908,23 @@ class ZWaveDeviceEntityValues():
component, DOMAIN,
compute_value_unique_id(self._node, self.primary))
if entity_id is None:
- value_name = _value_name(self.primary)
- entity_id = generate_entity_id(component + '.{}', value_name, [])
+ _LOGGER.debug("No entity id for unique id %s, generating one",
+ compute_value_unique_id(self._node, self.primary))
+
+ node = self._node.node_id
+ node_key = 'node-{}'.format(node)
+ node_entity = self._hass.data[DATA_DEVICES].get(node_key)
+ if not node_entity:
+ _LOGGER.warning("Could not find node entity for %s", node_key)
+ return
+
+ node_base_id = node_entity.entity_id[len(DOMAIN) + 1:]
+ entity_id = generate_entity_id(component + '.{}',
+ '{} {}'.format(node_base_id, self.primary.label),
+ hass=self._hass)
+
+ _LOGGER.debug("Generated entity id: %s", entity_id)
+
node_config = self._device_config.get(entity_id)
# Configure node
@@ -944,6 +959,7 @@ class ZWaveDeviceEntityValues():
self._workaround_ignore = True
return
+ device.entity_id = entity_id
self._entity = device
@callback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment