From e915dd00205fe150c8db502a636ba853c1780f26 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 10 Mar 2015 00:08:50 -0700 Subject: [PATCH 1/3] Add a basic conversation component --- homeassistant/components/conversation.py | 71 ++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 homeassistant/components/conversation.py diff --git a/homeassistant/components/conversation.py b/homeassistant/components/conversation.py new file mode 100644 index 00000000000..7ea35d34d7a --- /dev/null +++ b/homeassistant/components/conversation.py @@ -0,0 +1,71 @@ +""" +homeassistant.components.conversation +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Provides functionality to have conversations with Home Assistant. +This is more a proof of concept. +""" +import logging +import re + +import homeassistant +from homeassistant.const import ( + ATTR_FRIENDLY_NAME, ATTR_ENTITY_ID, SERVICE_TURN_ON, SERVICE_TURN_OFF) + +DOMAIN = "conversation" +DEPENDENCIES = [] + +SERVICE_PROCESS = "process" + +ATTR_TEXT = "text" + +REGEX_TURN_COMMAND = re.compile(r'turn (?P(?: |\w)+) (?P\w+)') + + +def setup(hass, config): + """ Registers the process service. """ + logger = logging.getLogger(__name__) + + def process(service): + if ATTR_TEXT not in service.data: + logger.error("Received process service call without a text") + return + + text = service.data[ATTR_TEXT].lower() + + match = REGEX_TURN_COMMAND.match(text) + + if not match: + logger.error("Unable to process: %s", text) + return + + name, command = match.groups() + + entity_ids = [ + state.entity_id for state in hass.states.all() + if state.attributes.get(ATTR_FRIENDLY_NAME, "").lower() == name] + + if not entity_ids: + logger.error( + "Could not find entity id %s from text %s", name, text) + return + + if command == 'on': + hass.services.call( + homeassistant.DOMAIN, SERVICE_TURN_ON, { + ATTR_ENTITY_ID: entity_ids, + }, blocking=True) + + elif command == 'off': + hass.services.call( + homeassistant.DOMAIN, SERVICE_TURN_OFF, { + ATTR_ENTITY_ID: entity_ids, + }, blocking=True) + + else: + logger.error( + 'Got unsupported command %s from text %s', command, text) + + hass.services.register(DOMAIN, SERVICE_PROCESS, process) + + return True From 90eb8aa82af79cb8323716041f993925df739cc6 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 10 Mar 2015 00:09:08 -0700 Subject: [PATCH 2/3] Move icon imports to generic file --- .../frontend/www_static/polymer/components/domain-icon.html | 5 ----- .../www_static/polymer/resources/home-assistant-icons.html | 4 ++++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/frontend/www_static/polymer/components/domain-icon.html b/homeassistant/components/frontend/www_static/polymer/components/domain-icon.html index 50c5157eb2f..78d583426e8 100644 --- a/homeassistant/components/frontend/www_static/polymer/components/domain-icon.html +++ b/homeassistant/components/frontend/www_static/polymer/components/domain-icon.html @@ -1,10 +1,5 @@ - - - - - + + + + From eaded9b67cf02b6ce35cf1a92e4b1707c57d22c5 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 10 Mar 2015 00:09:27 -0700 Subject: [PATCH 3/3] Add support for voice commands --- homeassistant/components/conversation.py | 1 + homeassistant/components/frontend/version.py | 2 +- .../frontend/www_static/frontend.html | 17 ++-- .../www_static/polymer/home-assistant-js | 2 +- .../polymer/layouts/partial-states.html | 79 ++++++++++++++++++- .../resources/home-assistant-icons.html | 2 + 6 files changed, 93 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/conversation.py b/homeassistant/components/conversation.py index 7ea35d34d7a..bf78e13a094 100644 --- a/homeassistant/components/conversation.py +++ b/homeassistant/components/conversation.py @@ -27,6 +27,7 @@ def setup(hass, config): logger = logging.getLogger(__name__) def process(service): + """ Parses text into commands for Home Assistant. """ if ATTR_TEXT not in service.data: logger.error("Received process service call without a text") return diff --git a/homeassistant/components/frontend/version.py b/homeassistant/components/frontend/version.py index 3886b2c2581..fc76773d501 100644 --- a/homeassistant/components/frontend/version.py +++ b/homeassistant/components/frontend/version.py @@ -1,2 +1,2 @@ """ DO NOT MODIFY. Auto-generated by build_frontend script """ -VERSION = "1c265f0f07e6038c2cbb9b277e58b994" +VERSION = "832b49fd1e3ff3bc33e55812743c3a7d" diff --git a/homeassistant/components/frontend/www_static/frontend.html b/homeassistant/components/frontend/www_static/frontend.html index d9a004de623..49e1e28f993 100644 --- a/homeassistant/components/frontend/www_static/frontend.html +++ b/homeassistant/components/frontend/www_static/frontend.html @@ -122,9 +122,9 @@ b.events&&Object.keys(a).length>0&&console.log("[%s] addHostListeners:",this.loc background-color: #039be5; } - + - +