Catch error when searching for scenes or automations (#31288)

This commit is contained in:
Paulus Schoutsen 2020-01-29 14:46:48 -08:00 committed by GitHub
parent e9e44dbd97
commit 881437c085
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 5 deletions

View file

@ -59,6 +59,8 @@ class Searcher:
# These types won't be further explored. Config entries + Output types.
DONT_RESOLVE = {"scene", "automation", "script", "group", "config_entry", "area"}
# These types exist as an entity and so need cleanup in results
EXIST_AS_ENTITY = {"script", "scene", "automation", "group"}
def __init__(
self,
@ -85,13 +87,18 @@ class Searcher:
# Clean up entity_id items, from the general "entity" type result,
# that are also found in the specific entity domain type.
self.results["entity"] -= self.results["script"]
self.results["entity"] -= self.results["scene"]
self.results["entity"] -= self.results["automation"]
self.results["entity"] -= self.results["group"]
for result_type in self.EXIST_AS_ENTITY:
self.results["entity"] -= self.results[result_type]
# Remove entry into graph from search results.
self.results[item_type].remove(item_id)
to_remove_item_type = item_type
if item_type == "entity":
domain = split_entity_id(item_id)[0]
if domain in self.EXIST_AS_ENTITY:
to_remove_item_type = domain
self.results[to_remove_item_type].remove(item_id)
# Filter out empty sets.
return {key: val for key, val in self.results.items() if val}

View file

@ -189,6 +189,23 @@ async def test_search(hass):
results == expected_combined
), f"Results for {search_type}/{search_id} do not match up"
for search_type, search_id in (
("entity", "automation.non_existing"),
("entity", "scene.non_existing"),
("entity", "group.non_existing"),
("entity", "script.non_existing"),
("entity", "light.non_existing"),
("area", "non_existing"),
("config_entry", "non_existing"),
("device", "non_existing"),
("group", "group.non_existing"),
("scene", "scene.non_existing"),
("script", "script.non_existing"),
("automation", "automation.non_existing"),
):
searcher = search.Searcher(hass, device_reg, entity_reg)
assert searcher.async_search(search_type, search_id) == {}
async def test_ws_api(hass, hass_ws_client):
"""Test WS API."""