Add unique_id to zwave node entity (#14201)
* Add unique_id to zwave node entity * Wait 30s before adding zwave node if its unique_id is not ready * Use only node_id in unique_id. Update name, manufacturer, and product attributes on node update.
This commit is contained in:
parent
351e8921fa
commit
f72d568374
6 changed files with 113 additions and 10 deletions
|
@ -81,6 +81,7 @@ class ZWaveNodeEntity(ZWaveBaseEntity):
|
|||
self._name = node_name(self.node)
|
||||
self._product_name = node.product_name
|
||||
self._manufacturer_name = node.manufacturer_name
|
||||
self._unique_id = self._compute_unique_id()
|
||||
self._attributes = {}
|
||||
self.wakeup_interval = None
|
||||
self.location = None
|
||||
|
@ -95,6 +96,11 @@ class ZWaveNodeEntity(ZWaveBaseEntity):
|
|||
dispatcher.connect(
|
||||
self.network_scene_activated, ZWaveNetwork.SIGNAL_SCENE_EVENT)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
"""Unique ID of Z-wave node."""
|
||||
return self._unique_id
|
||||
|
||||
def network_node_changed(self, node=None, value=None, args=None):
|
||||
"""Handle a changed node on the network."""
|
||||
if node and node.node_id != self.node_id:
|
||||
|
@ -138,8 +144,14 @@ class ZWaveNodeEntity(ZWaveBaseEntity):
|
|||
self.wakeup_interval = None
|
||||
|
||||
self.battery_level = self.node.get_battery_level()
|
||||
self._product_name = self.node.product_name
|
||||
self._manufacturer_name = self.node.manufacturer_name
|
||||
self._name = node_name(self.node)
|
||||
self._attributes = attributes
|
||||
|
||||
if not self._unique_id:
|
||||
self._unique_id = self._compute_unique_id()
|
||||
|
||||
self.maybe_schedule_update()
|
||||
|
||||
def network_node_event(self, node, value):
|
||||
|
@ -229,3 +241,8 @@ class ZWaveNodeEntity(ZWaveBaseEntity):
|
|||
attrs[ATTR_WAKEUP] = self.wakeup_interval
|
||||
|
||||
return attrs
|
||||
|
||||
def _compute_unique_id(self):
|
||||
if self._manufacturer_name and self._product_name:
|
||||
return 'node-{}'.format(self.node_id)
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue