Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 5 additions & 41 deletions homeassistant/components/zha/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,6 @@ async def async_device_initialized(self, device, join):
if endpoint_id == 0: # ZDO
continue

discovered_info = await _discover_endpoint_info(endpoint)

component = None
profile_clusters = ([], [])
device_key = "{}-{}".format(device.ieee, endpoint_id)
Expand Down Expand Up @@ -212,10 +210,11 @@ async def async_device_initialized(self, device, join):
'endpoint': endpoint,
'in_clusters': {c.cluster_id: c for c in in_clusters},
'out_clusters': {c.cluster_id: c for c in out_clusters},
'manufacturer': endpoint.manufacturer,
'model': endpoint.model,
'new_join': join,
'unique_id': device_key,
}
discovery_info.update(discovered_info)
self._hass.data[DISCOVERY_KEY][device_key] = discovery_info

await discovery.async_load_platform(
Expand All @@ -234,7 +233,6 @@ async def async_device_initialized(self, device, join):
device_key,
zha_const.SINGLE_INPUT_CLUSTER_DEVICE_CLASS,
'in_clusters',
discovered_info,
join,
)

Expand All @@ -246,7 +244,6 @@ async def async_device_initialized(self, device, join):
device_key,
zha_const.SINGLE_OUTPUT_CLUSTER_DEVICE_CLASS,
'out_clusters',
discovered_info,
join,
)

Expand All @@ -257,7 +254,7 @@ def register_entity(self, ieee, entity_obj):
async def _attempt_single_cluster_device(self, endpoint, cluster,
profile_clusters, device_key,
device_classes, discovery_attr,
entity_info, is_new_join):
is_new_join):
"""Try to set up an entity from a "bare" cluster."""
if cluster.cluster_id in profile_clusters:
return
Expand All @@ -277,12 +274,13 @@ async def _attempt_single_cluster_device(self, endpoint, cluster,
'endpoint': endpoint,
'in_clusters': {},
'out_clusters': {},
'manufacturer': endpoint.manufacturer,
'model': endpoint.model,
'new_join': is_new_join,
'unique_id': cluster_key,
'entity_suffix': '_{}'.format(cluster.cluster_id),
}
discovery_info[discovery_attr] = {cluster.cluster_id: cluster}
discovery_info.update(entity_info)
self._hass.data[DISCOVERY_KEY][cluster_key] = discovery_info

await discovery.async_load_platform(
Expand Down Expand Up @@ -369,40 +367,6 @@ def zdo_command(self, tsn, command_id, args):
pass


async def _discover_endpoint_info(endpoint):
"""Find some basic information about an endpoint."""
extra_info = {
'manufacturer': None,
'model': None,
}
if 0 not in endpoint.in_clusters:
return extra_info

async def read(attributes):
"""Read attributes and update extra_info convenience function."""
result, _ = await endpoint.in_clusters[0].read_attributes(
attributes,
allow_cache=True,
)
extra_info.update(result)

await read(['manufacturer', 'model'])
if extra_info['manufacturer'] is None or extra_info['model'] is None:
# Some devices fail at returning multiple results. Attempt separately.
await read(['manufacturer'])
await read(['model'])

for key, value in extra_info.items():
if isinstance(value, bytes):
try:
extra_info[key] = value.decode('ascii').strip()
except UnicodeDecodeError:
# Unsure what the best behaviour here is. Unset the key?
pass

return extra_info


def get_discovery_info(hass, discovery_info):
"""Get the full discovery info for a device.

Expand Down