Catch bad devices when Google Sync (#39377)
This commit is contained in:
parent
b882304ec2
commit
8302a7879e
2 changed files with 72 additions and 4 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue