Guard against missing states in Alexa state updates (#61152)
parent
4563d95d40
commit
af2e95d891
|
@ -182,12 +182,13 @@ async def async_send_add_or_update_message(hass, config, entity_ids):
|
|||
endpoints = []
|
||||
|
||||
for entity_id in entity_ids:
|
||||
domain = entity_id.split(".", 1)[0]
|
||||
|
||||
if domain not in ENTITY_ADAPTERS:
|
||||
if (domain := entity_id.split(".", 1)[0]) not in ENTITY_ADAPTERS:
|
||||
continue
|
||||
|
||||
alexa_entity = ENTITY_ADAPTERS[domain](hass, config, hass.states.get(entity_id))
|
||||
if (state := hass.states.get(entity_id)) is None:
|
||||
continue
|
||||
|
||||
alexa_entity = ENTITY_ADAPTERS[domain](hass, config, state)
|
||||
endpoints.append(alexa_entity.serialize_discovery())
|
||||
|
||||
payload = {"endpoints": endpoints, "scope": {"type": "BearerToken", "token": token}}
|
||||
|
|
|
@ -117,10 +117,18 @@ async def test_send_add_or_update_message(hass, aioclient_mock):
|
|||
{"friendly_name": "Test Contact Sensor", "device_class": "door"},
|
||||
)
|
||||
|
||||
await state_report.async_send_add_or_update_message(
|
||||
hass, DEFAULT_CONFIG, ["binary_sensor.test_contact", "zwave.bla"]
|
||||
hass.states.async_set(
|
||||
"zwave.bla",
|
||||
"wow_such_unsupported",
|
||||
)
|
||||
|
||||
entities = [
|
||||
"binary_sensor.test_contact",
|
||||
"binary_sensor.non_existing", # Supported, but does not exist
|
||||
"zwave.bla", # Unsupported
|
||||
]
|
||||
await state_report.async_send_add_or_update_message(hass, DEFAULT_CONFIG, entities)
|
||||
|
||||
assert len(aioclient_mock.mock_calls) == 1
|
||||
call = aioclient_mock.mock_calls
|
||||
|
||||
|
|
Loading…
Reference in New Issue