From cdb7a6261ec3726be774af71c59d5436cc95508e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 29 Jun 2018 15:35:46 -0400 Subject: [PATCH] Random fixes (#1369) * Random fixes * weather card to use legacy wrapper * Lint --- .../lovelace/cards/hui-camera-preview-card.js | 48 ++--------------- .../lovelace/cards/hui-entities-card.js | 24 +++++---- src/panels/lovelace/cards/hui-glance-card.js | 5 +- .../lovelace/cards/hui-history-graph-card.js | 5 +- .../lovelace/cards/hui-legacy-wrapper-card.js | 49 ++++++++++++++++++ .../lovelace/cards/hui-markdown-card.js | 6 +-- .../lovelace/cards/hui-media-control-card.js | 51 ++----------------- .../lovelace/cards/hui-picture-glance-card.js | 37 +++++++++----- .../lovelace/cards/hui-plant-status-card.js | 51 ++----------------- src/panels/lovelace/cards/hui-row-card.js | 1 + .../cards/hui-weather-forecast-card.js | 49 ++---------------- src/panels/lovelace/hui-view.js | 10 +++- 12 files changed, 124 insertions(+), 212 deletions(-) create mode 100644 src/panels/lovelace/cards/hui-legacy-wrapper-card.js diff --git a/src/panels/lovelace/cards/hui-camera-preview-card.js b/src/panels/lovelace/cards/hui-camera-preview-card.js index eb2262306c..5ecbd62b85 100644 --- a/src/panels/lovelace/cards/hui-camera-preview-card.js +++ b/src/panels/lovelace/cards/hui-camera-preview-card.js @@ -1,55 +1,15 @@ -import { PolymerElement } from '@polymer/polymer/polymer-element.js'; - import '../../../cards/ha-camera-card.js'; -import validateEntityConfig from '../common/validate-entity-config.js'; +import LegacyWrapperCard from './hui-legacy-wrapper-card.js'; -class HuiCameraPreviewCard extends PolymerElement { - static get properties() { - return { - hass: { - type: Object, - observer: '_hassChanged' - }, - }; +class HuiCameraPreviewCard extends LegacyWrapperCard { + constructor() { + super('ha-camera-card', 'camera'); } getCardSize() { return 4; } - - setConfig(config) { - if (!validateEntityConfig(config, 'camera')) { - throw new Error('Error in card configuration.'); - } - - this._config = config; - this._entityId = null; - - if (this.lastChild) { - this.removeChild(this.lastChild); - } - - const entityId = config.entity; - if (!(entityId in this.hass.states)) { - return; - } - - const element = document.createElement('ha-camera-card'); - element.stateObj = this.hass.states[entityId]; - element.hass = this.hass; - this.appendChild(element); - this._entityId = entityId; - } - - _hassChanged(hass) { - const entityId = this._entityId; - if (entityId && entityId in hass.states) { - const element = this.lastChild; - element.stateObj = hass.states[entityId]; - element.hass = hass; - } - } } customElements.define('hui-camera-preview-card', HuiCameraPreviewCard); diff --git a/src/panels/lovelace/cards/hui-entities-card.js b/src/panels/lovelace/cards/hui-entities-card.js index 6edc11993d..f5ab0cc5df 100644 --- a/src/panels/lovelace/cards/hui-entities-card.js +++ b/src/panels/lovelace/cards/hui-entities-card.js @@ -49,12 +49,14 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) { -
-
[[_computeTitle(_config)]]
- -
+
`; @@ -85,12 +87,14 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) { return 1 + (this._config ? this._config.entities.length : 0); } - _computeTitle(config) { - return config.title; + _showHeaderToggle(show) { + // If show is undefined, we treat it as true + return show !== false; } - _showHeaderToggle(show) { - return show !== false; + _showHeader(config) { + // Show header if either title or toggle configured to show in it + return config.title || config.show_header_toggle; } setConfig(config) { diff --git a/src/panels/lovelace/cards/hui-glance-card.js b/src/panels/lovelace/cards/hui-glance-card.js index 3a99384780..4aa221db73 100644 --- a/src/panels/lovelace/cards/hui-glance-card.js +++ b/src/panels/lovelace/cards/hui-glance-card.js @@ -22,6 +22,9 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) { ha-card { padding: 16px; } + ha-card[header] { + padding-top: 0; + } .entities { padding: 4px 0; display: flex; @@ -47,7 +50,7 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) { } - +