diff --git a/homeassistant/components/google_assistant/smart_home.py b/homeassistant/components/google_assistant/smart_home.py index 71e0d252fe1..50ef200d171 100644 --- a/homeassistant/components/google_assistant/smart_home.py +++ b/homeassistant/components/google_assistant/smart_home.py @@ -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) diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index f3bd42c1181..521f52a99eb 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -1129,3 +1129,62 @@ async def test_reachable_devices(hass): "requestId": REQ_ID, "payload": {"devices": [{"verificationId": "light.ceiling_lights"}]}, } + + +async def test_sync_message_recovery(hass, caplog): + """Test a sync message recovers from bad entities.""" + light = DemoLight( + None, + "Demo Light", + state=False, + hs_color=(180, 75), + ) + light.hass = hass + light.entity_id = "light.demo_light" + await light.async_update_ha_state() + + hass.states.async_set( + "light.bad_light", + "on", + { + "min_mireds": "badvalue", + "supported_features": hass.components.light.SUPPORT_COLOR_TEMP, + }, + ) + + result = await sh.async_handle_message( + hass, + BASIC_CONFIG, + "test-agent", + {"requestId": REQ_ID, "inputs": [{"intent": "action.devices.SYNC"}]}, + const.SOURCE_CLOUD, + ) + + assert result == { + "requestId": REQ_ID, + "payload": { + "agentUserId": "test-agent", + "devices": [ + { + "id": "light.demo_light", + "name": {"name": "Demo Light"}, + "attributes": { + "colorModel": "hsv", + "colorTemperatureRange": { + "temperatureMaxK": 6535, + "temperatureMinK": 2000, + }, + }, + "traits": [ + "action.devices.traits.Brightness", + "action.devices.traits.OnOff", + "action.devices.traits.ColorSetting", + ], + "willReportState": False, + "type": "action.devices.types.LIGHT", + }, + ], + }, + } + + assert "Error serializing light.bad_light" in caplog.text