diff --git a/src/cards/ha-card-chooser.html b/src/cards/ha-card-chooser.html index 782402ee02f4..2c9680081da8 100644 --- a/src/cards/ha-card-chooser.html +++ b/src/cards/ha-card-chooser.html @@ -21,8 +21,16 @@ cardDataChanged: function (newData) { if (!newData) return; - window.hassUtil.dynamicContentUpdater(this, 'HA-' + newData.cardType.toUpperCase() + '-CARD', - newData); + var cardType; + + if (newData.stateObj && newData.stateObj.attributes && 'custom_ui_card' in newData.stateObj.attributes) { + cardType = newData.stateObj.attributes.custom_ui_card; + window.hassUtil.ensureCustomUILoaded(cardType); + cardType = cardType.toUpperCase(); + } else { + cardType = 'HA-' + newData.cardType.toUpperCase() + '-CARD'; + } + window.hassUtil.dynamicContentUpdater(this, cardType, newData); }, }); diff --git a/src/more-infos/more-info-content.html b/src/more-infos/more-info-content.html index 23b3f76c6e70..c6a84391f985 100644 --- a/src/more-infos/more-info-content.html +++ b/src/more-infos/more-info-content.html @@ -46,7 +46,7 @@ } } else { window.hassUtil.dynamicContentUpdater( - this, 'MORE-INFO-' + window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(), + this, window.hassUtil.stateMoreInfoType(stateObj).toUpperCase(), { hass: this.hass, stateObj: stateObj, isVisible: true }); } }, diff --git a/src/state-summary/state-card-content.html b/src/state-summary/state-card-content.html index dd3c86e26c74..443f45f92304 100644 --- a/src/state-summary/state-card-content.html +++ b/src/state-summary/state-card-content.html @@ -35,28 +35,18 @@ 'inputChanged(hass, inDialog, stateObj)', ], - _ensureCustomUILoaded: function (stateType) { - this.importHref( - '/local/custom_ui/state-card-' + stateType + '.html', - function () {}, - /* eslint-disable no-console */ - function () { console.error('Error loading %s from /local/custom_ui/state-card-%s.html', stateType, stateType); }, - /* eslint-enable no-console */ - true); - }, - inputChanged: function (hass, inDialog, stateObj) { var stateCardType; if (!stateObj || !hass) return; if (stateObj.attributes && 'custom_ui_state_card' in stateObj.attributes) { stateCardType = stateObj.attributes.custom_ui_state_card; - this._ensureCustomUILoaded(stateCardType); + window.hassUtil.ensureCustomUILoaded(stateCardType); } else { - stateCardType = window.hassUtil.stateCardType(hass, stateObj); + stateCardType = 'STATE-CARD-' + window.hassUtil.stateCardType(hass, stateObj); } window.hassUtil.dynamicContentUpdater( this, - ('STATE-CARD-' + stateCardType.toUpperCase()), + (stateCardType.toUpperCase()), { hass: hass, stateObj: stateObj, diff --git a/src/util/hass-util.html b/src/util/hass-util.html index f9fe871589ec..5311038cfa96 100644 --- a/src/util/hass-util.html +++ b/src/util/hass-util.html @@ -38,7 +38,7 @@ 'entity_picture', 'friendly_name', 'icon', 'unit_of_measurement', 'emulated_hue', 'emulated_hue_name', 'haaska_hidden', 'haaska_name', 'homebridge_hidden', 'homebridge_name', 'supported_features', 'attribution', - 'custom_ui_state_card', 'device_class', + 'custom_ui_state_card', 'custom_ui_card', 'custom_ui_more_info', 'device_class', ]; window.hassUtil.LANGUAGE = navigator.languages ? @@ -231,16 +231,31 @@ return 'display'; }; +window.hassUtil.ensureCustomUILoaded = function (customUI) { + Polymer.Base.importHref( + '/local/custom_ui/' + customUI + '.html', + function () {}, + /* eslint-disable no-console */ + function () { console.error('Error loading %s from /local/custom_ui/%s.html', customUI, customUI); }, + /* eslint-enable no-console */ + true); +}; + window.hassUtil.stateMoreInfoType = function (stateObj) { + if (stateObj.attributes && 'custom_ui_more_info' in stateObj.attributes) { + var customUI = stateObj.attributes.custom_ui_more_info; + window.hassUtil.ensureCustomUILoaded(customUI); + return customUI; + } var domain = window.hassUtil.computeDomain(stateObj); if (window.hassUtil.DOMAINS_WITH_MORE_INFO.indexOf(domain) !== -1) { - return domain; + return 'MORE-INFO-' + domain; } if (window.hassUtil.HIDE_MORE_INFO.indexOf(domain) !== -1) { - return 'hidden'; + return 'MORE-INFO-HIDDEN'; } - return 'default'; + return 'MORE-INFO-DEFAULT'; }; window.hassUtil.domainIcon = function (domain, state) { @@ -516,9 +531,7 @@ }); } element.updateStyles(styles); - if (!updateMeta) return; - const meta = document.querySelector('meta[name=theme-color]'); if (meta) { if (!meta.hasAttribute('default-content')) {