From 6c3e2021df523be5f47f23dfead4f0d0cb565a92 Mon Sep 17 00:00:00 2001 From: Andrey Date: Tue, 29 May 2018 04:49:38 +0300 Subject: [PATCH] Give unknown zwave nodes a better name (#14353) * Give unknown zwave nodes a better name * Update util.py --- homeassistant/components/zwave/util.py | 8 +++++--- tests/components/zwave/test_init.py | 5 +++-- tests/components/zwave/test_node_entity.py | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/zwave/util.py b/homeassistant/components/zwave/util.py index 1c0bb14f7e5..b62eeb67d32 100644 --- a/homeassistant/components/zwave/util.py +++ b/homeassistant/components/zwave/util.py @@ -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) diff --git a/tests/components/zwave/test_init.py b/tests/components/zwave/test_init.py index a25b725e500..e608dcccaba 100644 --- a/tests/components/zwave/test_init.py +++ b/tests/components/zwave/test_init.py @@ -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 diff --git a/tests/components/zwave/test_node_entity.py b/tests/components/zwave/test_node_entity.py index f4d9b3ef0e8..b91245d5a12 100644 --- a/tests/components/zwave/test_node_entity.py +++ b/tests/components/zwave/test_node_entity.py @@ -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)