Merge pull request #748 from davidedmundson/fuzzy
Use fuzzy matching for conversation entity matchingpull/770/head
commit
f2aeb2a6f9
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
|
||||
pyicloud==0.7.2
|
||||
|
||||
# homeassistant.components.conversation
|
||||
fuzzywuzzy==0.8.0
|
||||
|
||||
# homeassistant.components.device_tracker.netgear
|
||||
pynetgear==0.3
|
||||
|
||||
|
|
Loading…
Reference in New Issue