Fix getters that ignored labels. (#5903)

* Fix getters that ignored labels.

* Try 5 times for changed dict

* fix lint

* Add decorator with retrying functions.

* Fix lint

* use retries instead of decorator
This commit is contained in:
Andrey 2017-02-13 01:42:09 +02:00 committed by Paulus Schoutsen
parent 9b0a3e4c5a
commit f4372a7df5

View File

@ -236,7 +236,7 @@ def nice_print_node(node):
print("\n\n\n") print("\n\n\n")
def get_config_value(node, value_index): def get_config_value(node, value_index, tries=5):
"""Return the current configuration value for a specific index.""" """Return the current configuration value for a specific index."""
try: try:
for value in node.values.values(): for value in node.values.values():
@ -246,14 +246,24 @@ def get_config_value(node, value_index):
except RuntimeError: except RuntimeError:
# If we get an runtime error the dict has changed while # If we get an runtime error the dict has changed while
# we was looking for a value, just do it again # we was looking for a value, just do it again
return get_config_value(node, value_index) return None if tries <= 0 else get_config_value(
node, value_index, tries=tries - 1)
return None
def _get_wakeup(node): def _get_wakeup(node, tries=5):
"""Return wakeup interval of the node or None if node is not wakable.""" """Return wakeup interval of the node or None if node is not wakable."""
try:
if node.can_wake_up(): if node.can_wake_up():
for value_id in node.get_values(class_id=const.COMMAND_CLASS_WAKE_UP): for value_id in node.get_values(
class_id=const.COMMAND_CLASS_WAKE_UP):
return node.values[value_id].data return node.values[value_id].data
except RuntimeError:
# If we get an runtime error the dict has changed while
# we was looking for a value, just do it again
return None if tries <= 0 else _get_wakeup(
node, tries=tries - 1)
return None return None
@ -671,7 +681,6 @@ class ZWaveDeviceEntity(Entity):
def _value_handler(self, method=None, class_id=None, index=None, def _value_handler(self, method=None, class_id=None, index=None,
label=None, data=None, member=None, **kwargs): label=None, data=None, member=None, **kwargs):
"""Get the values for a given command_class with arguments.""" """Get the values for a given command_class with arguments."""
varname = member
if class_id is not None: if class_id is not None:
kwargs[CLASS_ID] = class_id kwargs[CLASS_ID] = class_id
_LOGGER.debug('method=%s, class_id=%s, index=%s, label=%s, data=%s,' _LOGGER.debug('method=%s, class_id=%s, index=%s, label=%s, data=%s,'
@ -686,8 +695,12 @@ class ZWaveDeviceEntity(Entity):
if index is not None and value.index != index: if index is not None and value.index != index:
continue continue
if label is not None: if label is not None:
label_found = False
for entry in label: for entry in label:
if entry is not None and value.label != entry: if value.label == entry:
label_found = True
break
if not label_found:
continue continue
if method == 'set': if method == 'set':
value.data = data value.data = data
@ -695,7 +708,7 @@ class ZWaveDeviceEntity(Entity):
if data is not None and value.data != data: if data is not None and value.data != data:
continue continue
if member is not None: if member is not None:
results = getattr(value, varname) results = getattr(value, member)
else: else:
results = value results = value
break break