Use fuzzy matching for conversation entity matching
Entity may not be picked up exactly by the speech recognition. Instead of doing an exact string match, look for names which are phonetically similar and choose the best match above a certain threshold. This helps as entity names may often be pronoun's (Dave's bedroom) and this allows for some minor mistakes i.e "the bedroom" will successfully match against a switch called "bedroom" It introduces a new library dependency, fuzzywuzzy for comparisons.pull/748/head
parent
66fca475c6
commit
a3f805d88e
homeassistant/components
|
@ -9,6 +9,7 @@ https://home-assistant.io/components/conversation/
|
|||
import logging
|
||||
import re
|
||||
|
||||
|
||||
from homeassistant import core
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
||||
|
@ -21,9 +22,13 @@ ATTR_TEXT = "text"
|
|||
|
||||
REGEX_TURN_COMMAND = re.compile(r'turn (?P<name>(?: |\w)+) (?P<command>\w+)')
|
||||
|
||||
REQUIREMENTS = ['fuzzywuzzy==0.8.0']
|
||||
|
||||
|
||||
def setup(hass, config):
|
||||
""" Registers the process service. """
|
||||
from fuzzywuzzy import process as fuzzyExtract
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
def process(service):
|
||||
|
@ -42,9 +47,11 @@ def setup(hass, config):
|
|||
|
||||
name, command = match.groups()
|
||||
|
||||
entity_ids = [
|
||||
state.entity_id for state in hass.states.all()
|
||||
if state.name.lower() == name]
|
||||
entities = {state.entity_id: state.name for state in hass.states.all()}
|
||||
|
||||
entity_ids = fuzzyExtract.extractOne(name,
|
||||
entities,
|
||||
score_cutoff=65)[2]
|
||||
|
||||
if not entity_ids:
|
||||
logger.error(
|
||||
|
|
|
@ -12,6 +12,9 @@ PyMata==2.07a
|
|||
# homeassistant.components.device_tracker.icloud
|
||||
https://github.com/picklepete/pyicloud/archive/80f6cd6decc950514b8dc43b30c5bded81b34d5f.zip#pyicloud==0.8.0
|
||||
|
||||
# homeassistant.components.conversation
|
||||
fuzzywuzzy==0.8.0
|
||||
|
||||
# homeassistant.components.device_tracker.netgear
|
||||
pynetgear==0.3
|
||||
|
||||
|
|
Loading…
Reference in New Issue