Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/cards/ha-card-chooser.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
});
</script>
2 changes: 1 addition & 1 deletion src/more-infos/more-info-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
},
Expand Down
16 changes: 3 additions & 13 deletions src/state-summary/state-card-content.html
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 19 additions & 6 deletions src/util/hass-util.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
Expand Down Expand Up @@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the return value of this function need to be uppercased anyway, I think it is more readable to use lower-case here.

}
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) {
Expand Down Expand Up @@ -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')) {
Expand Down