Open andrewdolphin opened 5 years ago
Firstly, thanks for all the cards you have created!
For my project I wanted to change the more-info dialog for all entities in a domain so I hacked the lovelace-popup-card.js
Usage example (can be global or per view, the same as the original)
popup_cards_domain: climate: title: "###ENTITYNAME###" card: type: vertical-stack cards: - type: history-graph entities: - "###ENTITY###" - type: entities entities: - "###ENTITY###"
Where ###ENTITY### is a sort-of template for the actual entity id and ###ENTITYNAME### is the friendly_name.
Code below
(function (){ const thisScript = document.currentScript; customElements.whenDefined('card-tools').then(() => { let cardTools = customElements.get('card-tools'); let moreInfo = null; document.querySelector("home-assistant").addEventListener("hass-more-info", (e) => { if(moreInfo && !moreInfo.getAttribute('aria-hidden')) return; if(!cardTools.lovelace) return; const data = Object.assign({}, cardTools.lovelace.config.popup_cards_domain, cardTools.lovelace.config.views[cardTools.lovelace.current_view].popup_cards_domain ); if(e.detail) { cardTools.logger(`Opening more-info dialog for ${e.detail.entityId}`, thisScript); cardTools.logger(`AD extra info ${JSON.stringify(e)}`, thisScript); cardTools.logger(`Overridden dialogs:`, thisScript); cardTools.logger(Object.keys(data), thisScript); cardTools.logger(`Settings: ${JSON.stringify(data[e.detail.entityId])}`, thisScript); } if(e.detail && e.detail.entityId && data[e.detail.entityId.split(".")[0]]) { let settings = data[e.detail.entityId.split(".")[0]]; while(settings && typeof settings === "string") settings = data[settings]; if(!settings) return; if(cardTools.hass) myhass = cardTools.hass; friendlyname = myhass.states[e.detail.entityId].attributes.friendly_name; settings = JSON.parse(JSON.stringify(settings).replace(/###ENTITY###/g, e.detail.entityId)); settings = JSON.parse(JSON.stringify(settings).replace(/###ENTITYNAME###/g,friendlyname)); cardTools.logger(`Settings: ${JSON.stringify(settings)}`, thisScript); const card = cardTools.createCard(settings.card); if(cardTools.hass) card.hass = cardTools.hass; moreInfo = cardTools.popUp(settings.title, card, settings.large || false); if(settings.style) { let oldStyle = {}; for(var k in settings.style) { oldStyle[k] = moreInfo.style[k]; moreInfo.style.setProperty(k, settings.style[k]); } setTimeout(() =>{ let interval = setInterval(() => { if(moreInfo.getAttribute('aria-hidden')) { for(var k in oldStyle) moreInfo.style.setProperty(k, oldStyle[k]); clearInterval(interval); } }, 100) }, 1000); } } }); }); })();
As I said...hacky!
Firstly, thanks for all the cards you have created!
For my project I wanted to change the more-info dialog for all entities in a domain so I hacked the lovelace-popup-card.js
Usage example (can be global or per view, the same as the original)
Where ###ENTITY### is a sort-of template for the actual entity id and ###ENTITYNAME### is the friendly_name.
Code below
As I said...hacky!