Sort entries also by query matching
This commit is contained in:
parent
db63cab455
commit
4bc0e85bad
12
__init__.py
12
__init__.py
@ -22,7 +22,6 @@ configurationFileName = "homeassistant_config.json"
|
|||||||
configuration_directory = os.path.join(configLocation())
|
configuration_directory = os.path.join(configLocation())
|
||||||
configuration_file = os.path.join(configuration_directory, configurationFileName)
|
configuration_file = os.path.join(configuration_directory, configurationFileName)
|
||||||
config = {}
|
config = {}
|
||||||
#config["sort_order"] = [["light", "switch"], ["scene", "group"], ["automation"]]
|
|
||||||
config["sort_order"] = {"light": 1, "switch": 1, "scene": 2, "group": 2, "automation": 3}
|
config["sort_order"] = {"light": 1, "switch": 1, "scene": 2, "group": 2, "automation": 3}
|
||||||
|
|
||||||
icon_files = {
|
icon_files = {
|
||||||
@ -116,9 +115,7 @@ def showEntities(query):
|
|||||||
subtext="Enter a query to control your Home Assistant",
|
subtext="Enter a query to control your Home Assistant",
|
||||||
actions=[UrlAction("Open in Browser", config["hass_url"])])
|
actions=[UrlAction("Open in Browser", config["hass_url"])])
|
||||||
|
|
||||||
action_word = query.string.split()[0].lower().strip()
|
entity_query_list = query.string.split()
|
||||||
#is_action_word = action_word in action_words
|
|
||||||
entity_query_list = query.string.split()#[1:] if is_action_word else query.string.split()
|
|
||||||
|
|
||||||
if not entity_query_list:
|
if not entity_query_list:
|
||||||
return Item(id=__title__,
|
return Item(id=__title__,
|
||||||
@ -144,9 +141,14 @@ def showEntities(query):
|
|||||||
text="Error while getting entity states from Home Assistant",
|
text="Error while getting entity states from Home Assistant",
|
||||||
subtext=str(error))
|
subtext=str(error))
|
||||||
|
|
||||||
# Sort entries
|
# Sort entries by class
|
||||||
entities = sorted(response.json(), key=lambda e: config["sort_order"].get_matching(e["entity_id"].split(".")[0]))
|
entities = sorted(response.json(), key=lambda e: config["sort_order"].get_matching(e["entity_id"].split(".")[0]))
|
||||||
|
|
||||||
|
# Sort entries by query matching
|
||||||
|
entities = sorted(entities, key=lambda e:
|
||||||
|
RegexDict({query.string.lower() + ".": 0, ".": 1})
|
||||||
|
.get_matching(e["attributes"]["friendly_name"].lower() if "friendly_name" in e["attributes"] else e["entity_id"]))
|
||||||
|
|
||||||
# Parse all entities and states
|
# Parse all entities and states
|
||||||
for entity in entities:
|
for entity in entities:
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user