diff --git a/homeassistant/components/conversation.py b/homeassistant/components/conversation.py index 11e018846c2..dc8446412c4 100644 --- a/homeassistant/components/conversation.py +++ b/homeassistant/components/conversation.py @@ -8,9 +8,12 @@ import logging import re import warnings +import voluptuous as vol + from homeassistant import core from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON) +import homeassistant.helpers.config_validation as cv DOMAIN = "conversation" @@ -18,6 +21,10 @@ SERVICE_PROCESS = "process" ATTR_TEXT = "text" +SERVICE_PROCESS_SCHEMA = vol.Schema({ + vol.Required(ATTR_TEXT): vol.All(cv.string, vol.Lower), +}) + REGEX_TURN_COMMAND = re.compile(r'turn (?P(?: |\w)+) (?P\w+)') REQUIREMENTS = ['fuzzywuzzy==0.8.0'] @@ -32,11 +39,7 @@ def setup(hass, config): def process(service): """Parse text into commands.""" - if ATTR_TEXT not in service.data: - logger.error("Received process service call without a text") - return - - text = service.data[ATTR_TEXT].lower() + text = service.data[ATTR_TEXT] match = REGEX_TURN_COMMAND.match(text) if not match: @@ -67,6 +70,6 @@ def setup(hass, config): logger.error( 'Got unsupported command %s from text %s', command, text) - hass.services.register(DOMAIN, SERVICE_PROCESS, process) - + hass.services.register(DOMAIN, SERVICE_PROCESS, process, + schema=SERVICE_PROCESS_SCHEMA) return True