* Fix legacy wrapper in browsers without native custom elements

* Better error reporting for picture-elements

* Lint
pull/1378/head
Paulus Schoutsen 2018-07-01 12:25:00 -04:00 committed by GitHub
parent 54fcb21917
commit dc5213a79a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View File

@ -27,10 +27,8 @@ export default class LegacyWrapperCard extends HTMLElement {
if (entityId in hass.states) {
this._ensureElement(this._tag);
this.lastChild.setProperties({
hass,
stateObj: hass.states[entityId],
});
this.lastChild.hass = hass;
this.lastChild.stateObj = hass.states[entityId];
} else {
this._ensureElement('HUI-ERROR-CARD');
this.lastChild.setConfig(createErrorCardConfig(`No state available for ${entityId}`, this._config));

View File

@ -14,6 +14,8 @@ import toggleEntity from '../common/entity/toggle-entity.js';
import EventsMixin from '../../../mixins/events-mixin.js';
import LocalizeMixin from '../../../mixins/localize-mixin.js';
const VALID_TYPES = new Set(['service-button', 'state-badge', 'state-icon', 'state-label']);
/*
* @appliesMixin EventsMixin
* @appliesMixin LocalizeMixin
@ -85,6 +87,10 @@ class HuiPictureElementsCard extends EventsMixin(LocalizeMixin(PolymerElement))
if (!config || !config.image || !Array.isArray(config.elements)) {
throw new Error('Invalid card configuration');
}
const invalidTypes = config.elements.map(el => el.type).filter(el => !VALID_TYPES.has(el));
if (invalidTypes.length) {
throw new Error(`Incorrect element types: ${invalidTypes.join(', ')}`);
}
this._config = config;
if (this.$) this._buildConfig();
@ -106,7 +112,6 @@ class HuiPictureElementsCard extends EventsMixin(LocalizeMixin(PolymerElement))
img.src = config.image;
root.appendChild(img);
config.elements.forEach((element) => {
const entityId = element.entity;
let el;