From b04e28506110869003b7da11c91f78b4a8cca75a Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Wed, 4 Nov 2015 23:52:21 -0800 Subject: [PATCH] Move voice recog to dialog --- package.json | 2 +- src/components/ha-voice-command-progress.html | 32 ------- src/components/ha-voice-command-progress.js | 27 ------ src/dialogs/ha-voice-command-dialog.html | 64 ++++++++++++++ src/dialogs/ha-voice-command-dialog.js | 83 +++++++++++++++++++ src/layouts/home-assistant-main.html | 2 + src/layouts/home-assistant-main.js | 1 + src/layouts/partial-zone.html | 9 +- src/layouts/partial-zone.js | 25 +----- 9 files changed, 153 insertions(+), 92 deletions(-) delete mode 100644 src/components/ha-voice-command-progress.html delete mode 100644 src/components/ha-voice-command-progress.js create mode 100644 src/dialogs/ha-voice-command-dialog.html create mode 100644 src/dialogs/ha-voice-command-dialog.js diff --git a/package.json b/package.json index 83b6879307..e3ed800a0e 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "author": "Paulus Schoutsen (http://paulusschoutsen.nl)", "license": "MIT", "dependencies": { - "home-assistant-js": "git+https://github.com/balloob/home-assistant-js.git#2f69d196e841b4dd77e17a60b5b712938d9ddc0c", + "home-assistant-js": "git+https://github.com/balloob/home-assistant-js.git#9b10d9a7615a6a84762fb418a0b24ba9893c1829", "lodash": "^3.10.1", "moment": "^2.10.6" }, diff --git a/src/components/ha-voice-command-progress.html b/src/components/ha-voice-command-progress.html deleted file mode 100644 index a0f3a01438..0000000000 --- a/src/components/ha-voice-command-progress.html +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - diff --git a/src/components/ha-voice-command-progress.js b/src/components/ha-voice-command-progress.js deleted file mode 100644 index 020530b357..0000000000 --- a/src/components/ha-voice-command-progress.js +++ /dev/null @@ -1,27 +0,0 @@ -import { voiceGetters } from '../util/home-assistant-js-instance'; - -import Polymer from '../polymer'; -import nuclearObserver from '../util/bound-nuclear-behavior'; - -export default new Polymer({ - is: 'ha-voice-command-progress', - - behaviors: [nuclearObserver], - - properties: { - isTransmitting: { - type: Boolean, - bindNuclear: voiceGetters.isTransmitting, - }, - - interimTranscript: { - type: String, - bindNuclear: voiceGetters.extraInterimTranscript, - }, - - finalTranscript: { - type: String, - bindNuclear: voiceGetters.finalTranscript, - }, - }, -}); diff --git a/src/dialogs/ha-voice-command-dialog.html b/src/dialogs/ha-voice-command-dialog.html new file mode 100644 index 0000000000..2977a287f7 --- /dev/null +++ b/src/dialogs/ha-voice-command-dialog.html @@ -0,0 +1,64 @@ + + + + + + + + + + + + + diff --git a/src/dialogs/ha-voice-command-dialog.js b/src/dialogs/ha-voice-command-dialog.js new file mode 100644 index 0000000000..ad1c599c08 --- /dev/null +++ b/src/dialogs/ha-voice-command-dialog.js @@ -0,0 +1,83 @@ +import { + voiceActions, + voiceGetters, +} from '../util/home-assistant-js-instance'; + +import Polymer from '../polymer'; +import nuclearObserver from '../util/bound-nuclear-behavior'; + +export default new Polymer({ + is: 'ha-voice-command-dialog', + + behaviors: [nuclearObserver], + + properties: { + dialogOpen: { + type: Boolean, + value: false, + observer: 'dialogOpenChanged', + }, + + finalTranscript: { + type: String, + bindNuclear: voiceGetters.finalTranscript, + }, + + interimTranscript: { + type: String, + bindNuclear: voiceGetters.extraInterimTranscript, + }, + + isTransmitting: { + type: Boolean, + bindNuclear: voiceGetters.isTransmitting, + }, + + isListening: { + type: Boolean, + bindNuclear: voiceGetters.isListening, + }, + + showListenInterface: { + type: Boolean, + computed: 'computeShowListenInterface(isListening, isTransmitting)', + observer: 'showListenInterfaceChanged', + }, + + _boundOnBackdropTap: { + type: Function, + value: function bindBackdropTap() { + return this._onBackdropTap.bind(this); + }, + }, + }, + + computeShowListenInterface(isListening, isTransmitting) { + return isListening || isTransmitting; + }, + + dialogOpenChanged(newVal) { + if (newVal) { + this.$.dialog.backdropElement.addEventListener('click', + this._boundOnBackdropTap); + } else if (!newVal && this.isListening) { + voiceActions.stop(); + } + }, + + showListenInterfaceChanged(newVal) { + if (!newVal && this.dialogOpen) { + this.dialogOpen = false; + } else if (newVal) { + this.dialogOpen = true; + } + }, + + _onBackdropTap() { + this.$.dialog.backdropElement.removeEventListener('click', + this._boundOnBackdropTap); + if (this.isListening) { + voiceActions.stop(); + } + }, +}); diff --git a/src/layouts/home-assistant-main.html b/src/layouts/home-assistant-main.html index f04b191f70..e22045039e 100644 --- a/src/layouts/home-assistant-main.html +++ b/src/layouts/home-assistant-main.html @@ -10,6 +10,7 @@ + @@ -17,6 +18,7 @@