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.
pull/8385/head
Russell Cloran 2017-07-06 23:02:22 -07:00 committed by Paulus Schoutsen
parent b1bba3675d
commit 46ce26eb7a
1 changed files with 14 additions and 5 deletions

View File

@ -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):