(HA) Added fuzzy match on overriden entities and improved intents

This commit is contained in:
Mathieu 2021-09-13 15:46:52 +02:00
parent 2796d86fca
commit 4201b5cbcc
3 changed files with 23 additions and 14 deletions

View File

@ -58,7 +58,7 @@ def find_entity(name, types):
# Check if the friendly name is overriden manually (from the config files) # Check if the friendly name is overriden manually (from the config files)
if is_overridden(name): if is_overridden(name):
try: 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 = { result = {
"id": actionable_entity.entity_id, "id": actionable_entity.entity_id,
@ -67,7 +67,7 @@ def find_entity(name, types):
"best_score": 101} "best_score": 101}
return result return result
except ParameterMissingError: 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 return None
elif json_data: elif json_data:
@ -117,7 +117,7 @@ def register_overrides():
overridden_entities[entity] = friendly_names overridden_entities[entity] = friendly_names
if len(overridden_entities) >= 1: 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): def is_overridden(entity_friendly_name):
@ -128,10 +128,18 @@ def is_overridden(entity_friendly_name):
return False 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(): for key, value in overridden_entities.items():
if friendly_name in value: for val in value:
return key 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(): def init():
@ -139,4 +147,5 @@ def init():
get_client() get_client()
# register all the overrides entity from the config/homeassistant/override/ folder # register all the overrides entity from the config/homeassistant/override/ folder
register_overrides() if not overridden_entities:
register_overrides()

View File

@ -1,3 +1,3 @@
(éteint|arrête|arrêter) (voir|) {entity} ((dans|) {location}|) (éteint|arrête|arrêter) (voir|) {entity} ((dans|à|au) {location}|)
tu peux (éteindre|arrête) (le|la) {entity} ((dans|) {location}|) tu peux (éteindre|arrête) (le|la) {entity} ((dans|à|au) {location}|)
tu peux (éteindre|arrête) l'{entity} ((dans|) {location}|) tu peux (éteindre|arrête) l'{entity} ((dans|à|au) {location}|)

View File

@ -1,4 +1,4 @@
(allume|démarre) (voir|) (la|le|) {entity} ((dans|) {location}|) (allume|démarre) (voir|) (la|le|) {entity} ((dans) {location}|)
(allume|démarre) (voir|) l'{entity} ((dans|) {location}|) (allume|démarre) (voir|) l'{entity} ((dans|à|au) {location}|)
tu peux (allumer|démarrer) (le|la|) {entity} ((dans|) {location}|) tu peux (allumer|démarrer) (le|la|) {entity} ((dans|à|au) {location}|)
tu peux (allumer|démarrer) l'{entity} ((dans|) {location}|) tu peux (allumer|démarrer) l'{entity} ((dans|à|au) {location}|)