diff --git a/src/cards/ha-camera-card.html b/src/cards/ha-camera-card.html new file mode 100644 index 0000000000..76576cb069 --- /dev/null +++ b/src/cards/ha-camera-card.html @@ -0,0 +1,37 @@ + + + + + + + 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/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 @@ - +