Catch bad devices when Google Sync (#39377)

This commit is contained in:
Paulus Schoutsen 2020-08-29 13:09:50 +02:00 committed by GitHub
parent b882304ec2
commit 8302a7879e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 4 deletions

View file

@ -83,15 +83,24 @@ async def async_devices_sync(hass, data, payload):
)
agent_user_id = data.config.get_agent_user_id(data.context)
devices = await asyncio.gather(
entities = async_get_entities(hass, data.config)
results = await asyncio.gather(
*(
entity.sync_serialize(agent_user_id)
for entity in async_get_entities(hass, data.config)
for entity in entities
if entity.should_expose()
)
),
return_exceptions=True,
)
devices = []
for entity, result in zip(entities, results):
if isinstance(result, Exception):
_LOGGER.error("Error serializing %s", entity.entity_id, exc_info=result)
else:
devices.append(result)
response = {"agentUserId": agent_user_id, "devices": devices}
await data.config.async_connect_agent_user(agent_user_id)