From 4201b5cbcc21122b8e8c9a4673b5232ed71c3477 Mon Sep 17 00:00:00 2001 From: Mathieu Date: Mon, 13 Sep 2021 15:46:52 +0200 Subject: [PATCH] (HA) Added fuzzy match on overriden entities and improved intents --- .../homeassistant/homeassistant_client.py | 23 +++++++++++++------ .../vocab/fr-fr/homeassistant_turn_off.intent | 6 ++--- .../vocab/fr-fr/homeassistant_turn_on.intent | 8 +++---- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/jarvis/skills/productivity/homeassistant/homeassistant_client.py b/jarvis/skills/productivity/homeassistant/homeassistant_client.py index 93f15bb..bb17d20 100644 --- a/jarvis/skills/productivity/homeassistant/homeassistant_client.py +++ b/jarvis/skills/productivity/homeassistant/homeassistant_client.py @@ -58,7 +58,7 @@ def find_entity(name, types): # Check if the friendly name is overriden manually (from the config files) if is_overridden(name): try: - actionable_entity = get_client().get_entity(entity_id=get_entity_with_overriden_name(name)) + actionable_entity = get_client().get_entity(entity_id=get_entity_with_overridden_name(name)) result = { "id": actionable_entity.entity_id, @@ -67,7 +67,7 @@ def find_entity(name, types): "best_score": 101} return result except ParameterMissingError: - print("[Error] : Entity with id : " + get_entity_with_overriden_name(name) + " doesn't exists.") + print("[Error] : Entity with id : " + get_entity_with_overridden_name(name) + " doesn't exists.") return None elif json_data: @@ -117,7 +117,7 @@ def register_overrides(): overridden_entities[entity] = friendly_names if len(overridden_entities) >= 1: - print("[HomeAssistant] Override for entities : " + str(list(overridden_entities.keys()))) + print("[HomeAssistantSkill] Override for entities : " + str(list(overridden_entities.keys()))) def is_overridden(entity_friendly_name): @@ -128,10 +128,18 @@ def is_overridden(entity_friendly_name): return False -def get_entity_with_overriden_name(friendly_name): +def get_entity_with_overridden_name(friendly_name): + scores = dict() for key, value in overridden_entities.items(): - if friendly_name in value: - return key + for val in value: + score = fuzz.token_sort_ratio(friendly_name, val) + if score > 50: + scores[score] = key + + if len(scores) >= 1: + return sorted(scores.items(), reverse=True)[0][1] + + return None def init(): @@ -139,4 +147,5 @@ def init(): get_client() # register all the overrides entity from the config/homeassistant/override/ folder - register_overrides() + if not overridden_entities: + register_overrides() diff --git a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent index 4b8526c..1682f5e 100644 --- a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent +++ b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_off.intent @@ -1,3 +1,3 @@ -(éteint|arrête|arrêter) (voir|) {entity} ((dans|) {location}|) -tu peux (éteindre|arrête) (le|la) {entity} ((dans|) {location}|) -tu peux (éteindre|arrête) l'{entity} ((dans|) {location}|) \ No newline at end of file +(éteint|arrête|arrêter) (voir|) {entity} ((dans|à|au) {location}|) +tu peux (éteindre|arrête) (le|la) {entity} ((dans|à|au) {location}|) +tu peux (éteindre|arrête) l'{entity} ((dans|à|au) {location}|) \ No newline at end of file diff --git a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent index 7e49051..6766aa4 100644 --- a/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent +++ b/jarvis/skills/productivity/homeassistant/vocab/fr-fr/homeassistant_turn_on.intent @@ -1,4 +1,4 @@ -(allume|démarre) (voir|) (la|le|) {entity} ((dans|) {location}|) -(allume|démarre) (voir|) l'{entity} ((dans|) {location}|) -tu peux (allumer|démarrer) (le|la|) {entity} ((dans|) {location}|) -tu peux (allumer|démarrer) l'{entity} ((dans|) {location}|) \ No newline at end of file +(allume|démarre) (voir|) (la|le|) {entity} ((dans) {location}|) +(allume|démarre) (voir|) l'{entity} ((dans|à|au) {location}|) +tu peux (allumer|démarrer) (le|la|) {entity} ((dans|à|au) {location}|) +tu peux (allumer|démarrer) l'{entity} ((dans|à|au) {location}|) \ No newline at end of file