From 46ce26eb7a879c85357c41fb784acc27f1527b29 Mon Sep 17 00:00:00 2001 From: Russell Cloran Date: Thu, 6 Jul 2017 23:02:22 -0700 Subject: [PATCH] zha: Try multiple reads to get manufacturer/model (#8308) Some devices don't seem to return the information properly when asked for multiple attributes in one read. This separates out the reads if it didn't work as expected the first time. Because this data is cached in bellows, I don't expect any extra reads in the "happy" case. --- homeassistant/components/zha/__init__.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/zha/__init__.py b/homeassistant/components/zha/__init__.py index 183ced3782..5937f1865f 100644 --- a/homeassistant/components/zha/__init__.py +++ b/homeassistant/components/zha/__init__.py @@ -264,11 +264,20 @@ def _discover_endpoint_info(endpoint): if 0 not in endpoint.clusters: return extra_info - result, _ = yield from endpoint.clusters[0].read_attributes( - ['manufacturer', 'model'], - allow_cache=True, - ) - extra_info.update(result) + @asyncio.coroutine + def read(attributes): + """Read attributes and update extra_info convenience function.""" + result, _ = yield from endpoint.clusters[0].read_attributes( + attributes, + allow_cache=True, + ) + extra_info.update(result) + + yield from read(['manufacturer', 'model']) + if extra_info['manufacturer'] is None or extra_info['model'] is None: + # Some devices fail at returning multiple results. Attempt separately. + yield from read(['manufacturer']) + yield from read(['model']) for key, value in extra_info.items(): if isinstance(value, bytes):