mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-08 18:06:36 +00:00
Random fixes (#1369)
* Random fixes * weather card to use legacy wrapper * Lint
This commit is contained in:
parent
a8063f3359
commit
cdb7a6261e
@ -1,55 +1,15 @@
|
|||||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
||||||
|
|
||||||
import '../../../cards/ha-camera-card.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 {
|
class HuiCameraPreviewCard extends LegacyWrapperCard {
|
||||||
static get properties() {
|
constructor() {
|
||||||
return {
|
super('ha-camera-card', 'camera');
|
||||||
hass: {
|
|
||||||
type: Object,
|
|
||||||
observer: '_hassChanged'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCardSize() {
|
getCardSize() {
|
||||||
return 4;
|
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);
|
customElements.define('hui-camera-preview-card', HuiCameraPreviewCard);
|
||||||
|
@ -49,12 +49,14 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) {
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<ha-card>
|
<ha-card>
|
||||||
|
<template is='dom-if' if='[[_showHeader(_config)]]'>
|
||||||
<div class='header'>
|
<div class='header'>
|
||||||
<div class="name">[[_computeTitle(_config)]]</div>
|
<div class="name">[[_config.title]]</div>
|
||||||
<template is="dom-if" if="[[_showHeaderToggle(_config.show_header_toggle)]]">
|
<template is="dom-if" if="[[_showHeaderToggle(_config.show_header_toggle)]]">
|
||||||
<hui-entities-toggle hass="[[hass]]" entities="[[_config.entities]]"></hui-entities-toggle>
|
<hui-entities-toggle hass="[[hass]]" entities="[[_config.entities]]"></hui-entities-toggle>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
|
</template>
|
||||||
<div id="states"></div>
|
<div id="states"></div>
|
||||||
</ha-card>
|
</ha-card>
|
||||||
`;
|
`;
|
||||||
@ -85,12 +87,14 @@ class HuiEntitiesCard extends EventsMixin(PolymerElement) {
|
|||||||
return 1 + (this._config ? this._config.entities.length : 0);
|
return 1 + (this._config ? this._config.entities.length : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
_computeTitle(config) {
|
_showHeaderToggle(show) {
|
||||||
return config.title;
|
// If show is undefined, we treat it as true
|
||||||
|
return show !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_showHeaderToggle(show) {
|
_showHeader(config) {
|
||||||
return show !== false;
|
// Show header if either title or toggle configured to show in it
|
||||||
|
return config.title || config.show_header_toggle;
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfig(config) {
|
setConfig(config) {
|
||||||
|
@ -22,6 +22,9 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
ha-card {
|
ha-card {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
|
ha-card[header] {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
.entities {
|
.entities {
|
||||||
padding: 4px 0;
|
padding: 4px 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -47,7 +50,7 @@ class HuiGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<ha-card header="[[_config.title]]">
|
<ha-card header$="[[_config.title]]">
|
||||||
<div class="entities">
|
<div class="entities">
|
||||||
<template is="dom-repeat" items="[[_computeEntities(_config)]]">
|
<template is="dom-repeat" items="[[_computeEntities(_config)]]">
|
||||||
<template is="dom-if" if="[[_showEntity(item, hass.states)]]">
|
<template is="dom-if" if="[[_showEntity(item, hass.states)]]">
|
||||||
|
@ -12,9 +12,12 @@ class HuiHistoryGraphCard extends PolymerElement {
|
|||||||
ha-card {
|
ha-card {
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
}
|
}
|
||||||
|
ha-card[header] {
|
||||||
|
padding-top: 0;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<ha-card header=[[_config.title]]>
|
<ha-card header$='[[_config.title]]'>
|
||||||
<ha-state-history-data
|
<ha-state-history-data
|
||||||
hass="[[hass]]"
|
hass="[[hass]]"
|
||||||
filter-type="recent-entity"
|
filter-type="recent-entity"
|
||||||
|
49
src/panels/lovelace/cards/hui-legacy-wrapper-card.js
Normal file
49
src/panels/lovelace/cards/hui-legacy-wrapper-card.js
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
import createErrorCardConfig from '../common/create-error-card-config.js';
|
||||||
|
import validateEntityConfig from '../common/validate-entity-config.js';
|
||||||
|
|
||||||
|
|
||||||
|
export default class LegacyWrapperCard extends HTMLElement {
|
||||||
|
constructor(tag, domain) {
|
||||||
|
super();
|
||||||
|
this._tag = tag.toUpperCase();
|
||||||
|
this._domain = domain;
|
||||||
|
this._element = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
getCardSize() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
setConfig(config) {
|
||||||
|
if (!validateEntityConfig(config, this._domain)) {
|
||||||
|
throw new Error('Error in card configuration.');
|
||||||
|
}
|
||||||
|
|
||||||
|
this._config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
set hass(hass) {
|
||||||
|
const entityId = this._config.entity;
|
||||||
|
|
||||||
|
if (entityId in hass.states) {
|
||||||
|
this._ensureElement(this._tag);
|
||||||
|
this.lastChild.setProperties({
|
||||||
|
hass,
|
||||||
|
stateObj: hass.states[entityId],
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this._ensureElement('HUI-ERROR-CARD');
|
||||||
|
this.lastChild.setConfig(createErrorCardConfig(`No state available for ${entityId}`, this._config));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_ensureElement(tag) {
|
||||||
|
if (this.lastChild && this.lastChild.tagName === tag) return;
|
||||||
|
|
||||||
|
if (this.lastChild) {
|
||||||
|
this.removeChild(this.lastChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.appendChild(document.createElement(tag));
|
||||||
|
}
|
||||||
|
}
|
@ -21,10 +21,10 @@ class HuiMarkdownCard extends PolymerElement {
|
|||||||
:host([no-title]) ha-markdown {
|
:host([no-title]) ha-markdown {
|
||||||
padding-top: 16px;
|
padding-top: 16px;
|
||||||
}
|
}
|
||||||
ha-markdown p:first-child {
|
ha-markdown > *:first-child {
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
}
|
}
|
||||||
ha-markdown p:last-child {
|
ha-markdown > *:last-child {
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
}
|
}
|
||||||
ha-markdown a {
|
ha-markdown a {
|
||||||
@ -46,7 +46,7 @@ class HuiMarkdownCard extends PolymerElement {
|
|||||||
noTitle: {
|
noTitle: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
reflectToAttribute: true,
|
reflectToAttribute: true,
|
||||||
computed: '_computeNoTitle(config.title)',
|
computed: '_computeNoTitle(_config.title)',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,10 @@
|
|||||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
||||||
|
|
||||||
import '../../../cards/ha-media_player-card.js';
|
import '../../../cards/ha-media_player-card.js';
|
||||||
|
|
||||||
import validateEntityConfig from '../common/validate-entity-config.js';
|
import LegacyWrapperCard from './hui-legacy-wrapper-card.js';
|
||||||
|
|
||||||
class HuiMediaControlCard extends PolymerElement {
|
class HuiMediaControlCard extends LegacyWrapperCard {
|
||||||
static get properties() {
|
constructor() {
|
||||||
return {
|
super('ha-media_player-card', 'media_player');
|
||||||
hass: {
|
|
||||||
type: Object,
|
|
||||||
observer: '_hassChanged'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
getCardSize() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
setConfig(config) {
|
|
||||||
if (!validateEntityConfig(config, 'media_player')) {
|
|
||||||
throw new Error('Error in card configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
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-media_player-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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,8 +97,15 @@ class HuiPictureGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
return {
|
return {
|
||||||
hass: Object,
|
hass: Object,
|
||||||
_config: Object,
|
_config: Object,
|
||||||
_entitiesDialog: Array,
|
_entitiesDialog: {
|
||||||
_entitiesService: Array,
|
type: Array,
|
||||||
|
computed: '_computeEntitiesDialog(hass, _config, _entitiesService)',
|
||||||
|
},
|
||||||
|
_entitiesService: {
|
||||||
|
type: Array,
|
||||||
|
value: [],
|
||||||
|
computed: '_computeEntitiesService(hass, _config)',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,19 +119,23 @@ class HuiPictureGlanceCard extends LocalizeMixin(EventsMixin(PolymerElement)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this._config = config;
|
this._config = config;
|
||||||
let dialog = [];
|
|
||||||
let service = [];
|
|
||||||
if (config.force_dialog) {
|
|
||||||
dialog = config.entities;
|
|
||||||
} else {
|
|
||||||
service = config.entities.filter(entity =>
|
|
||||||
canToggleState(this.hass, this.hass.states[entity]));
|
|
||||||
dialog = config.entities.filter(entity => !service.includes(entity));
|
|
||||||
}
|
}
|
||||||
this.setProperties({
|
|
||||||
_entitiesDialog: dialog,
|
_computeEntitiesDialog(hass, config, entitiesService) {
|
||||||
_entitiesService: service,
|
if (config.force_dialog) {
|
||||||
});
|
return config.entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.entities.filter(entity => !entitiesService.includes(entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
_computeEntitiesService(hass, config) {
|
||||||
|
if (config.force_dialog) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return config.entities.filter(entity =>
|
||||||
|
canToggleState(this.hass, this.hass.states[entity]));
|
||||||
}
|
}
|
||||||
|
|
||||||
_showEntity(entityId, states) {
|
_showEntity(entityId, states) {
|
||||||
|
@ -1,53 +1,10 @@
|
|||||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
|
||||||
|
|
||||||
import '../../../cards/ha-plant-card.js';
|
import '../../../cards/ha-plant-card.js';
|
||||||
|
|
||||||
import validateEntityConfig from '../common/validate-entity-config.js';
|
import LegacyWrapperCard from './hui-legacy-wrapper-card.js';
|
||||||
|
|
||||||
class HuiPlantStatusCard extends PolymerElement {
|
class HuiPlantStatusCard extends LegacyWrapperCard {
|
||||||
static get properties() {
|
constructor() {
|
||||||
return {
|
super('ha-plant-card', 'plant');
|
||||||
hass: {
|
|
||||||
type: Object,
|
|
||||||
observer: '_hassChanged'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
getCardSize() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
setConfig(config) {
|
|
||||||
if (!validateEntityConfig(config, 'plant')) {
|
|
||||||
throw new Error('Error in card configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
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-plant-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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,6 +54,7 @@ class HuiRowCard extends PolymerElement {
|
|||||||
if (!config || !config.cards || !Array.isArray(config.cards)) {
|
if (!config || !config.cards || !Array.isArray(config.cards)) {
|
||||||
throw new Error('Card config incorrect.');
|
throw new Error('Card config incorrect.');
|
||||||
}
|
}
|
||||||
|
this._config = config;
|
||||||
if (this.$) this._buildConfig();
|
if (this.$) this._buildConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,54 +1,15 @@
|
|||||||
import { PolymerElement } from '@polymer/polymer/polymer-element.js';
|
import '../../../cards/ha-camera-card.js';
|
||||||
|
|
||||||
import '../../../cards/ha-weather-card.js';
|
import LegacyWrapperCard from './hui-legacy-wrapper-card.js';
|
||||||
|
|
||||||
import validateEntityConfig from '../common/validate-entity-config.js';
|
class HuiWeatherForecastCard extends LegacyWrapperCard {
|
||||||
|
constructor() {
|
||||||
class HuiWeatherForecastCard extends PolymerElement {
|
super('ha-weather-card', 'weather');
|
||||||
static get properties() {
|
|
||||||
return {
|
|
||||||
hass: {
|
|
||||||
type: Object,
|
|
||||||
observer: '_hassChanged'
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getCardSize() {
|
getCardSize() {
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
setConfig(config) {
|
|
||||||
if (!validateEntityConfig(config, 'weather')) {
|
|
||||||
throw new Error('Error in card configuration.');
|
|
||||||
}
|
|
||||||
|
|
||||||
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-weather-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-weather-forecast-card', HuiWeatherForecastCard);
|
customElements.define('hui-weather-forecast-card', HuiWeatherForecastCard);
|
||||||
|
@ -56,6 +56,7 @@ class HUIView extends PolymerElement {
|
|||||||
<div id='columns' on-rebuild-view='_debouncedConfigChanged'></div>
|
<div id='columns' on-rebuild-view='_debouncedConfigChanged'></div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
return {
|
return {
|
||||||
hass: {
|
hass: {
|
||||||
@ -65,16 +66,21 @@ class HUIView extends PolymerElement {
|
|||||||
|
|
||||||
columns: {
|
columns: {
|
||||||
type: Number,
|
type: Number,
|
||||||
observer: '_configChanged',
|
|
||||||
},
|
},
|
||||||
|
|
||||||
config: {
|
config: {
|
||||||
type: Object,
|
type: Object,
|
||||||
observer: '_configChanged',
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static get observers() {
|
||||||
|
return [
|
||||||
|
// Put all properties in 1 observer so we only call configChanged once
|
||||||
|
'_configChanged(columns, config)'
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this._elements = [];
|
this._elements = [];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user