1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Make sure zwave nodes/entities enter the registry is proper state. (#14251)

* When zwave node's info is parsed remove it and re-add back.

* Delay value entity if not ready

* If node is ready consider it parsed even if manufacturer/product are missing.

* Add annotations
This commit is contained in:
Andrey
2018-05-08 22:30:28 +03:00
committed by Paulus Schoutsen
parent e12994a0cd
commit 10505d542a
4 changed files with 92 additions and 30 deletions

View File

@@ -1,6 +1,9 @@
"""Zwave util methods."""
import asyncio
import logging
import homeassistant.util.dt as dt_util
from . import const
_LOGGER = logging.getLogger(__name__)
@@ -67,3 +70,23 @@ def node_name(node):
"""Return the name of the node."""
return node.name or '{} {}'.format(
node.manufacturer_name, node.product_name)
async def check_has_unique_id(entity, ready_callback, timeout_callback, loop):
"""Wait for entity to have unique_id."""
start_time = dt_util.utcnow()
while True:
waited = int((dt_util.utcnow()-start_time).total_seconds())
if entity.unique_id:
ready_callback(waited)
return
elif waited >= const.NODE_READY_WAIT_SECS:
# Wait up to NODE_READY_WAIT_SECS seconds for unique_id to appear.
timeout_callback(waited)
return
await asyncio.sleep(1, loop=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