From 70b04333f1146412596bf1bea48b3801671e3523 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 16 Feb 2016 20:46:21 -0800 Subject: [PATCH 1/4] More info dialog cleanup --- src/dialogs/more-info-dialog.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dialogs/more-info-dialog.js b/src/dialogs/more-info-dialog.js index af172b6043..4d246db935 100644 --- a/src/dialogs/more-info-dialog.js +++ b/src/dialogs/more-info-dialog.js @@ -15,7 +15,6 @@ const { moreInfoActions, } = hass; -// if you don't want the history component to show add the domain to this array const DOMAINS_WITH_NO_HISTORY = ['camera', 'configurator', 'scene']; export default new Polymer({ @@ -63,6 +62,7 @@ export default new Polymer({ showHistoryComponent: { type: Boolean, value: false, + computed: 'computeShowHistoryComponent(hasHistoryComponent, stateObj)', }, dialogOpen: { @@ -87,6 +87,11 @@ export default new Polymer({ return !_delayedDialogOpen || _isLoadingHistoryData; }, + computeShowHistoryComponent(hasHistoryComponent, stateObj) { + return this.hasHistoryComponent && stateObj && + DOMAINS_WITH_NO_HISTORY.indexOf(stateObj.domain) === -1; + }, + fetchHistoryData() { if (this.stateObj && this.hasHistoryComponent && this.shouldFetchHistory) { @@ -100,11 +105,6 @@ export default new Polymer({ return; } - this.showHistoryComponent = ( - this.hasHistoryComponent && - DOMAINS_WITH_NO_HISTORY.indexOf(this.stateObj.domain) === -1 - ); - this.async(() => { // Firing action while other action is happening confuses nuclear this.fetchHistoryData(); From 1fb3f2bbf4d9b8e6663b647deffa46a73a541f59 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Tue, 16 Feb 2016 21:24:09 -0800 Subject: [PATCH 2/4] Rename domain-card -> entities-card --- .../{ha-domain-card.html => ha-entities-card.html} | 4 ++-- src/cards/{ha-domain-card.js => ha-entities-card.js} | 12 +++++------- src/components/ha-cards.html | 6 +++--- src/components/ha-cards.js | 2 +- 4 files changed, 11 insertions(+), 13 deletions(-) rename src/cards/{ha-domain-card.html => ha-entities-card.html} (91%) rename src/cards/{ha-domain-card.js => ha-entities-card.js} (84%) diff --git a/src/cards/ha-domain-card.html b/src/cards/ha-entities-card.html similarity index 91% rename from src/cards/ha-domain-card.html rename to src/cards/ha-entities-card.html index b5082eb590..16de3e6f6b 100644 --- a/src/cards/ha-domain-card.html +++ b/src/cards/ha-entities-card.html @@ -4,7 +4,7 @@ - + + + diff --git a/src/cards/ha-camera-card.js b/src/cards/ha-camera-card.js new file mode 100644 index 0000000000..2c77bbc40a --- /dev/null +++ b/src/cards/ha-camera-card.js @@ -0,0 +1,52 @@ +import Polymer from '../polymer'; +import hass from '../util/home-assistant-js-instance'; + +const { moreInfoActions } = hass; + +const UPDATE_INTERVAL = 10000; // ms + +export default new Polymer({ + is: 'ha-camera-card', + + properties: { + stateObj: { + type: Object, + observer: 'updateCameraFeedSrc', + }, + + cameraFeedSrc: { + type: String, + }, + + /** + * The z-depth of the card, from 0-5. + */ + elevation: { + type: Number, + value: 1, + reflectToAttribute: true, + }, + }, + + listeners: { + tap: 'cardTapped', + }, + + attached() { + this.timer = setInterval(() => this.updateCameraFeedSrc(this.stateObj), + UPDATE_INTERVAL); + }, + + detached() { + clearInterval(this.timer); + }, + + cardTapped() { + this.async(() => moreInfoActions.selectEntity(this.stateObj.entityId), 1); + }, + + updateCameraFeedSrc(stateObj) { + const time = (new Date()).getTime(); + this.cameraFeedSrc = `${stateObj.attributes.entity_picture}?time=${time}`; + }, +}); diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html new file mode 100644 index 0000000000..d5ab9ad31a --- /dev/null +++ b/src/cards/ha-card-chooser.html @@ -0,0 +1,5 @@ + + + + + diff --git a/src/cards/ha-card-chooser.js b/src/cards/ha-card-chooser.js new file mode 100644 index 0000000000..c6fd37d6f4 --- /dev/null +++ b/src/cards/ha-card-chooser.js @@ -0,0 +1,53 @@ +import Polymer from '../polymer'; + +require('./ha-camera-card'); +require('./ha-entities-card'); +require('./ha-introduction-card'); + +export default new Polymer({ + is: 'ha-card-chooser', + + properties: { + cardData: { + type: Object, + observer: 'cardDataChanged', + }, + }, + + cardDataChanged(newData, oldData) { + const root = Polymer.dom(this); + + if (!newData) { + if (root.lastChild) { + root.removeChild(root.lastChild); + } + return; + } + + const newElement = !oldData || oldData.cardType !== newData.cardType; + let card; + if (newElement) { + if (root.lastChild) { + root.removeChild(root.lastChild); + } + + card = document.createElement(`ha-${newData.cardType}-card`); + } else { + card = root.lastChild; + } + + Object.keys(newData).forEach(key => card[key] = newData[key]); + + if (oldData) { + Object.keys(oldData).forEach(key => { + if (!(key in newData)) { + card[key] = undefined; + } + }); + } + + if (newElement) { + root.appendChild(card); + } + }, +}); diff --git a/src/components/ha-cards.html b/src/components/ha-cards.html index 740a6939e5..85af2af87e 100644 --- a/src/components/ha-cards.html +++ b/src/components/ha-cards.html @@ -2,8 +2,7 @@ - - +