mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Merge pull request #748 from davidedmundson/fuzzy
Use fuzzy matching for conversation entity matching
This commit is contained in:
commit
f2aeb2a6f9
@ -9,6 +9,7 @@ https://home-assistant.io/components/conversation/
|
|||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
from homeassistant import core
|
from homeassistant import core
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF)
|
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+)')
|
REGEX_TURN_COMMAND = re.compile(r'turn (?P<name>(?: |\w)+) (?P<command>\w+)')
|
||||||
|
|
||||||
|
REQUIREMENTS = ['fuzzywuzzy==0.8.0']
|
||||||
|
|
||||||
|
|
||||||
def setup(hass, config):
|
def setup(hass, config):
|
||||||
""" Registers the process service. """
|
""" Registers the process service. """
|
||||||
|
from fuzzywuzzy import process as fuzzyExtract
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
def process(service):
|
def process(service):
|
||||||
@ -42,9 +47,11 @@ def setup(hass, config):
|
|||||||
|
|
||||||
name, command = match.groups()
|
name, command = match.groups()
|
||||||
|
|
||||||
entity_ids = [
|
entities = {state.entity_id: state.name for state in hass.states.all()}
|
||||||
state.entity_id for state in hass.states.all()
|
|
||||||
if state.name.lower() == name]
|
entity_ids = fuzzyExtract.extractOne(name,
|
||||||
|
entities,
|
||||||
|
score_cutoff=65)[2]
|
||||||
|
|
||||||
if not entity_ids:
|
if not entity_ids:
|
||||||
logger.error(
|
logger.error(
|
||||||
|
@ -12,6 +12,9 @@ PyMata==2.07a
|
|||||||
# homeassistant.components.device_tracker.icloud
|
# homeassistant.components.device_tracker.icloud
|
||||||
pyicloud==0.7.2
|
pyicloud==0.7.2
|
||||||
|
|
||||||
|
# homeassistant.components.conversation
|
||||||
|
fuzzywuzzy==0.8.0
|
||||||
|
|
||||||
# homeassistant.components.device_tracker.netgear
|
# homeassistant.components.device_tracker.netgear
|
||||||
pynetgear==0.3
|
pynetgear==0.3
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user