Give unknown zwave nodes a better name (#14353)
* Give unknown zwave nodes a better name * Update util.pypull/14681/head
parent
07255a29b4
commit
6c3e2021df
|
@ -68,8 +68,10 @@ def check_value_schema(value, schema):
|
|||
|
||||
def node_name(node):
|
||||
"""Return the name of the node."""
|
||||
return node.name or '{} {}'.format(
|
||||
node.manufacturer_name, node.product_name)
|
||||
if is_node_parsed(node):
|
||||
return node.name or '{} {}'.format(
|
||||
node.manufacturer_name, node.product_name)
|
||||
return 'Unknown Node {}'.format(node.node_id)
|
||||
|
||||
|
||||
async def check_has_unique_id(entity, ready_callback, timeout_callback, loop):
|
||||
|
@ -89,4 +91,4 @@ async def check_has_unique_id(entity, ready_callback, timeout_callback, loop):
|
|||
|
||||
def is_node_parsed(node):
|
||||
"""Check whether the node has been parsed or still waiting to be parsed."""
|
||||
return node.manufacturer_name and node.product_name
|
||||
return bool((node.manufacturer_name and node.product_name) or node.name)
|
||||
|
|
|
@ -238,7 +238,8 @@ async def test_unparsed_node_discovery(hass, mock_openzwave):
|
|||
|
||||
assert len(mock_receivers) == 1
|
||||
|
||||
node = MockNode(node_id=14, manufacturer_name=None, is_ready=False)
|
||||
node = MockNode(
|
||||
node_id=14, manufacturer_name=None, name=None, is_ready=False)
|
||||
|
||||
sleeps = []
|
||||
|
||||
|
@ -263,7 +264,7 @@ async def test_unparsed_node_discovery(hass, mock_openzwave):
|
|||
assert len(mock_logger.warning.mock_calls) == 1
|
||||
assert mock_logger.warning.mock_calls[0][1][1:] == \
|
||||
(14, const.NODE_READY_WAIT_SECS)
|
||||
assert hass.states.get('zwave.mock_node').state is 'unknown'
|
||||
assert hass.states.get('zwave.unknown_node_14').state is 'unknown'
|
||||
|
||||
|
||||
@asyncio.coroutine
|
||||
|
|
|
@ -363,6 +363,7 @@ class TestZWaveNodeEntity(unittest.TestCase):
|
|||
def test_unique_id_missing_data(self):
|
||||
"""Test unique_id."""
|
||||
self.node.manufacturer_name = None
|
||||
self.node.name = None
|
||||
entity = node_entity.ZWaveNodeEntity(self.node, self.zwave_network)
|
||||
|
||||
self.assertIsNone(entity.unique_id)
|
||||
|
|
Loading…
Reference in New Issue