From eae1e22fa8bd6ed8ac49c3e7ff38c3d00cf1eaff Mon Sep 17 00:00:00 2001 From: Marco Kreeft Date: Wed, 2 Feb 2022 17:19:44 +0100 Subject: [PATCH] Added styles to card element and info.md --- info.md | 11 +++++++++++ room-card.js | 2 +- src/index.js | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 info.md diff --git a/info.md b/info.md new file mode 100644 index 0000000..327dd51 --- /dev/null +++ b/info.md @@ -0,0 +1,11 @@ +{% if installed %} + +### Features + +{% if version_installed.replace("v", "").replace(".","") | int < 2 %} +- Added `styles in root config for card styling. Now custom CSS styles to the card is possible` +- Release notes are shown in HACS depending on your installed version +{% endif %} + +--- +{% endif %} \ No newline at end of file diff --git a/room-card.js b/room-card.js index bcaa51b..2d85109 100644 --- a/room-card.js +++ b/room-card.js @@ -1,2 +1,2 @@ /*! For license information please see room-card.js.LICENSE.txt */ -(()=>{"use strict";const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e=Symbol(),n=new Map;class i{constructor(t,n){if(this._$cssResult$=!0,n!==e)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let e=n.get(this.cssText);return t&&void 0===e&&(n.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const r=(t,...n)=>{const r=1===t.length?t[0]:n.reduce(((e,n,i)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[i+1]),t[0]);return new i(r,e)},o=t?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let n="";for(const e of t.cssRules)n+=e.cssText;return(t=>new i("string"==typeof t?t:t+"",e))(n)})(t):t;var s;const a=window.trustedTypes,c=a?a.emptyScript:"",l=window.reactiveElementPolyfillSupport,u={toAttribute(t,e){switch(e){case Boolean:t=t?c:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},h=(t,e)=>e!==t&&(e==e||t==t),d={attribute:!0,type:String,converter:u,reflect:!1,hasChanged:h};class f extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o()}static addInitializer(t){var e;null!==(e=this.l)&&void 0!==e||(this.l=[]),this.l.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,n)=>{const i=this._$Eh(n,e);void 0!==i&&(this._$Eu.set(i,n),t.push(i))})),t}static createProperty(t,e=d){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const n="symbol"==typeof t?Symbol():"__"+t,i=this.getPropertyDescriptor(t,n,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}}static getPropertyDescriptor(t,e,n){return{get(){return this[e]},set(i){const r=this[t];this[e]=i,this.requestUpdate(t,r,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||d}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const n of e)this.createProperty(n,t[n])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(o(t))}else void 0!==t&&e.push(o(t));return e}static _$Eh(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,n;(null!==(e=this._$Eg)&&void 0!==e?e:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(n=t.hostConnected)||void 0===n||n.call(t))}removeController(t){var e;null===(e=this._$Eg)||void 0===e||e.splice(this._$Eg.indexOf(t)>>>0,1)}_$Em(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Et.set(e,this[e]),delete this[e])}))}createRenderRoot(){var e;const n=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,n)=>{t?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),i=window.litNonce;void 0!==i&&n.setAttribute("nonce",i),n.textContent=t.cssText,e.appendChild(n)}))})(n,this.constructor.elementStyles),n}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,n){this._$AK(t,n)}_$ES(t,e,n=d){var i,r;const o=this.constructor._$Eh(t,n);if(void 0!==o&&!0===n.reflect){const s=(null!==(r=null===(i=n.converter)||void 0===i?void 0:i.toAttribute)&&void 0!==r?r:u.toAttribute)(e,n.type);this._$Ei=t,null==s?this.removeAttribute(o):this.setAttribute(o,s),this._$Ei=null}}_$AK(t,e){var n,i,r;const o=this.constructor,s=o._$Eu.get(t);if(void 0!==s&&this._$Ei!==s){const t=o.getPropertyOptions(s),a=t.converter,c=null!==(r=null!==(i=null===(n=a)||void 0===n?void 0:n.fromAttribute)&&void 0!==i?i:"function"==typeof a?a:null)&&void 0!==r?r:u.fromAttribute;this._$Ei=s,this[s]=c(e,t.type),this._$Ei=null}}requestUpdate(t,e,n){let i=!0;void 0!==t&&(((n=n||this.constructor.getPropertyOptions(t)).hasChanged||h)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===n.reflect&&this._$Ei!==t&&(void 0===this._$E_&&(this._$E_=new Map),this._$E_.set(t,n))):i=!1),!this.isUpdatePending&&i&&(this._$Ep=this._$EC())}async _$EC(){this.isUpdatePending=!0;try{await this._$Ep}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,e)=>this[e]=t)),this._$Et=void 0);let e=!1;const n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(n)):this._$EU()}catch(t){throw e=!1,this._$EU(),t}e&&this._$AE(n)}willUpdate(t){}_$AE(t){var e;null===(e=this._$Eg)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return!0}update(t){void 0!==this._$E_&&(this._$E_.forEach(((t,e)=>this._$ES(e,this[e],t))),this._$E_=void 0),this._$EU()}updated(t){}firstUpdated(t){}}var p;f.finalized=!0,f.elementProperties=new Map,f.elementStyles=[],f.shadowRootOptions={mode:"open"},null==l||l({ReactiveElement:f}),(null!==(s=globalThis.reactiveElementVersions)&&void 0!==s?s:globalThis.reactiveElementVersions=[]).push("1.2.1");const m=globalThis.trustedTypes,y=m?m.createPolicy("lit-html",{createHTML:t=>t}):void 0,v=`lit$${(Math.random()+"").slice(9)}$`,b="?"+v,_=`<${b}>`,g=document,$=(t="")=>g.createComment(t),w=t=>null===t||"object"!=typeof t&&"function"!=typeof t,A=Array.isArray,O=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,E=/-->/g,S=/>/g,j=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,x=/'/g,P=/"/g,k=/^(?:script|style|textarea)$/i,C=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),N=C(1),D=(C(2),Symbol.for("lit-noChange")),U=Symbol.for("lit-nothing"),T=new WeakMap,H=g.createTreeWalker(g,129,null,!1),M=(t,e)=>{const n=t.length-1,i=[];let r,o=2===e?"":"",s=O;for(let e=0;e"===c[0]?(s=null!=r?r:O,l=-1):void 0===c[1]?l=-2:(l=s.lastIndex-c[2].length,a=c[1],s=void 0===c[3]?j:'"'===c[3]?P:x):s===P||s===x?s=j:s===E||s===S?s=O:(s=j,r=void 0);const h=s===j&&t[e+1].startsWith("/>")?" ":"";o+=s===O?n+_:l>=0?(i.push(a),n.slice(0,l)+"$lit$"+n.slice(l)+v+h):n+v+(-2===l?(i.push(void 0),e):h)}const a=o+(t[n]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==y?y.createHTML(a):a,i]};class R{constructor({strings:t,_$litType$:e},n){let i;this.parts=[];let r=0,o=0;const s=t.length-1,a=this.parts,[c,l]=M(t,e);if(this.el=R.createElement(c,n),H.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(i=H.nextNode())&&a.length0){i.textContent=m?m.emptyScript:"";for(let n=0;n{var e;return A(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.A(t):this.$(t)}M(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}S(t){this._$AH!==t&&(this._$AR(),this._$AH=this.M(t))}$(t){this._$AH!==U&&w(this._$AH)?this._$AA.nextSibling.data=t:this.S(g.createTextNode(t)),this._$AH=t}T(t){var e;const{values:n,_$litType$:i}=t,r="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=R.createElement(i.h,this.options)),i);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(n);else{const t=new z(r,this),e=t.p(this.options);t.m(n),this.S(e),this._$AH=t}}_$AC(t){let e=T.get(t.strings);return void 0===e&&T.set(t.strings,e=new R(t)),e}A(t){A(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let n,i=0;for(const r of t)i===e.length?e.push(n=new F(this.M($()),this.M($()),this,this.options)):n=e[i],n._$AI(r),i++;i2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=U}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,n,i){const r=this.strings;let o=!1;if(void 0===r)t=I(this,t,e,0),o=!w(t)||t!==this._$AH&&t!==D,o&&(this._$AH=t);else{const i=t;let s,a;for(t=r[0],s=0;s{var i,r;const o=null!==(i=null==n?void 0:n.renderBefore)&&void 0!==i?i:e;let s=o._$litPart$;if(void 0===s){const t=null!==(r=null==n?void 0:n.renderBefore)&&void 0!==r?r:null;o._$litPart$=s=new F(e.insertBefore($(),t),t,void 0,null!=n?n:{})}return s._$AI(t),s})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return D}}Q.finalized=!0,Q._$litElement$=!0,null===(Z=globalThis.litElementHydrateSupport)||void 0===Z||Z.call(globalThis,{LitElement:Q});const X=globalThis.litElementPolyfillSupport;var Y,tt,et;function nt(){return(nt=Object.assign||function(t){for(var e=1;e1&&void 0!==arguments[1]?arguments[1]:2;return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}(t,null==n?void 0:n.maximumFractionDigits).toString()).concat("currency"===(null==n?void 0:n.style)?" ".concat(n.currency):"")},bt=function(t,e){var n=function(t){for(var e=1;e-1?t.split(".")[1].length:0;n.minimumFractionDigits=i,n.maximumFractionDigits=i}return n},_t=Number.isNaN||function(t){return"number"==typeof t&&t!=t};function gt(t,e){if(t.length!==e.length)return!1;for(var n=0;ne.hide_if.above)return!0;e.hide_if.value&&(i=i.concat(e.hide_if.value))}else i=i.concat(e.hide_if);return i.some((function(t){return"number"==typeof t?t===+n:t===n}))};function Dt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function Ut(t){for(var e=1;e\n
\n
'," ",'
\n
\n ','\n
\n
\n
\n ',"\n
\n ","\n \n "])),this.renderMainEntity(),this.config.title,this.info_entities.map((function(e){return t.renderInfoEntity(e.stateObj,e)})),this.config.column?"entities-column":"entities-row",this.entities.map((function(e){return t.renderEntity(e.stateObj,e)})),this._refCards):N(Mt||(Mt=Gt([""])))}},{key:"renderInfoEntity",value:function(t,e){if(!t||Nt(t,e))return null;var n=this.clickHandler(t.entity_id,e.tap_action);return N(It||(It=Gt(['
',"
"])),n,this.renderValue(t,e))}},{key:"renderEntity",value:function(t,e){if(!t||Nt(t,e))return null;var n=this.clickHandler(t.entity_id,e.tap_action),i=this.dblClickHandler(t.entity_id,e.double_tap_action);return N(zt||(zt=Gt(['
\n ',"\n
","
\n
"])),Kt(e),n,i,function(t,e){return!1===e.name?null:e.name||(e.entity?t.attributes.friendly_name||(n=t.entity_id).substr(n.indexOf(".")+1):null)||null;var n}(t,e),this.renderIcon(t,e))}},{key:"renderMainEntity",value:function(){if(!this.entity)return null;var t=this.clickHandler(this.stateObj.entity_id,this.config.tap_action),e=this.dblClickHandler(this.stateObj.entity_id,this.config.double_tap_action);return N(Ft||(Ft=Gt(['\n ',"\n "])),Kt(this.config),t,e,0===this.entities.length||this.config.icon?this.renderIcon(this.stateObj,this.config):this.renderValue(this.stateObj,this.config))}},{key:"renderValue",value:function(t,e){if(!0===e.toggle)return N(Bt||(Bt=Gt([''])),t,this._hass);if(!0===e.show_icon)return this.renderIcon(t,e);var n;if(e.attribute&&[ut,ht].includes(e.attribute))return N(Lt||(Lt=Gt([""])),this._hass,t[null===(n=e.attribute)||void 0===n?void 0:n.replace("-","_")]);if(e.format&&dt.includes(e.format)){var i=e.attribute?t.attributes[e.attribute]:t.state,r=new Date(i);return r instanceof Date&&!isNaN(r.getTime())?N(Vt||(Vt=Gt([""])),this._hass,r,e.format):i}return function(t,e,n){if(Ct(e))return t.localize("state.default.".concat(e.state));var i=n.attribute?e.attributes[n.attribute]:e.state,r=!1===n.unit?void 0:void 0!==n.attribute?n.unit:n.unit||e.attributes.unit_of_measurement;if(n.format){if(isNaN(parseFloat(i))||!isFinite(i));else if("brightness"===n.format)i=Math.round(i/255*100),r="%";else if(n.format.startsWith("duration"))i=function(t){var e=Math.floor(t/3600),n=Math.floor(t%3600/60),i=Math.floor(t%3600%60);return e>0?"".concat(e,":").concat(pt(n),":").concat(pt(i)):n>0?"".concat(n,":").concat(pt(i)):i>0?""+i:null}("duration-m"===n.format?i/1e3:i),r=void 0;else if(n.format.startsWith("precision")){var o=parseInt(n.format.slice(-1),10);i=vt(parseFloat(i),t.locale,{minimumFractionDigits:o,maximumFractionDigits:o})}else"kilo"===n.format?i=vt(i/1e3,t.locale,{maximumFractionDigits:2}):"invert"===n.format?i=vt(i-2*i,t.locale):"position"===n.format&&(i=vt(100-i,t.locale));return"".concat(i).concat(r?" ".concat(r):"")}if(n.attribute)return"".concat(isNaN(i)?i:vt(i,t.locale)).concat(r?" ".concat(r):"");var s=Ut(Ut({},e),{},{attributes:Ut(Ut({},e.attributes),{},{unit_of_measurement:r})});return function(t,e,n,i){var r=e.state;if(r===ct||r===at)return t("state.default.".concat(r));if(function(t){return!!t.attributes.unit_of_measurement||!!t.attributes.state_class}(e)){if("monetary"===e.attributes.device_class)try{return vt(r,n,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return"".concat(vt(r,n)).concat(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var o,s=function(t){return t.entity_id.substr(0,t.entity_id.indexOf("."))}(e);return"input_datetime"===s?e.attributes.has_date&&e.attributes.has_time?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),Et(o,n)):e.attributes.has_date?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),wt(o,n)):e.attributes.has_time?((o=new Date).setHours(e.attributes.hour,e.attributes.minute),jt(o,n)):e.state:"humidifier"===s&&"on"===r&&e.attributes.humidity?"".concat(e.attributes.humidity," %"):"counter"===s||"number"===s||"input_number"===s?vt(r,n):"button"===s||"sensor"===s&&"timestamp"===e.attributes.device_class?Et(new Date(r),n):e.attributes.device_class&&t("component.".concat(s,".state.").concat(e.attributes.device_class,".").concat(r))||t("component.".concat(s,".state._.").concat(r))||r}(t.localize,s,t.locale)}(this._hass,t,e)}},{key:"renderIcon",value:function(t,e){return N(Wt||(Wt=Gt([''])),t,!0===e.icon?t.attributes.icon||null:e.icon,e.state_color)}},{key:"renderWarning",value:function(){return N(qt||(qt=Gt(["\n ","\n "])),this._hass.localize("ui.panel.lovelace.warning.entity_not_found","entity",this.config.entity))}},{key:"clickHandler",value:function(t,e){var n=this;return function(){return st(n,n._hass,{entity:t,tap_action:e},!1,!1)}}},{key:"dblClickHandler",value:function(t,e){var n=this;return function(){return st(n,n._hass,{entity:t,double_tap_action:e},!0,!1)}}}])&&ee(e.prototype,n),i&&ee(e,i),Object.defineProperty(e,"prototype",{writable:!1}),c}(Q);customElements.define("room-card",oe)})(); \ No newline at end of file +(()=>{"use strict";const t=window.ShadowRoot&&(void 0===window.ShadyCSS||window.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,e=Symbol(),n=new Map;class i{constructor(t,n){if(this._$cssResult$=!0,n!==e)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t}get styleSheet(){let e=n.get(this.cssText);return t&&void 0===e&&(n.set(this.cssText,e=new CSSStyleSheet),e.replaceSync(this.cssText)),e}toString(){return this.cssText}}const r=(t,...n)=>{const r=1===t.length?t[0]:n.reduce(((e,n,i)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[i+1]),t[0]);return new i(r,e)},o=t?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let n="";for(const e of t.cssRules)n+=e.cssText;return(t=>new i("string"==typeof t?t:t+"",e))(n)})(t):t;var s;const a=window.trustedTypes,c=a?a.emptyScript:"",l=window.reactiveElementPolyfillSupport,u={toAttribute(t,e){switch(e){case Boolean:t=t?c:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},h=(t,e)=>e!==t&&(e==e||t==t),d={attribute:!0,type:String,converter:u,reflect:!1,hasChanged:h};class f extends HTMLElement{constructor(){super(),this._$Et=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$Ei=null,this.o()}static addInitializer(t){var e;null!==(e=this.l)&&void 0!==e||(this.l=[]),this.l.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,n)=>{const i=this._$Eh(n,e);void 0!==i&&(this._$Eu.set(i,n),t.push(i))})),t}static createProperty(t,e=d){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const n="symbol"==typeof t?Symbol():"__"+t,i=this.getPropertyDescriptor(t,n,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}}static getPropertyDescriptor(t,e,n){return{get(){return this[e]},set(i){const r=this[t];this[e]=i,this.requestUpdate(t,r,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||d}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),this.elementProperties=new Map(t.elementProperties),this._$Eu=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const n of e)this.createProperty(n,t[n])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(o(t))}else void 0!==t&&e.push(o(t));return e}static _$Eh(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"string"==typeof t?t.toLowerCase():void 0}o(){var t;this._$Ep=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Em(),this.requestUpdate(),null===(t=this.constructor.l)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,n;(null!==(e=this._$Eg)&&void 0!==e?e:this._$Eg=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(n=t.hostConnected)||void 0===n||n.call(t))}removeController(t){var e;null===(e=this._$Eg)||void 0===e||e.splice(this._$Eg.indexOf(t)>>>0,1)}_$Em(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Et.set(e,this[e]),delete this[e])}))}createRenderRoot(){var e;const n=null!==(e=this.shadowRoot)&&void 0!==e?e:this.attachShadow(this.constructor.shadowRootOptions);return((e,n)=>{t?e.adoptedStyleSheets=n.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):n.forEach((t=>{const n=document.createElement("style"),i=window.litNonce;void 0!==i&&n.setAttribute("nonce",i),n.textContent=t.cssText,e.appendChild(n)}))})(n,this.constructor.elementStyles),n}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostConnected)||void 0===e?void 0:e.call(t)}))}enableUpdating(t){}disconnectedCallback(){var t;null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,n){this._$AK(t,n)}_$ES(t,e,n=d){var i,r;const o=this.constructor._$Eh(t,n);if(void 0!==o&&!0===n.reflect){const s=(null!==(r=null===(i=n.converter)||void 0===i?void 0:i.toAttribute)&&void 0!==r?r:u.toAttribute)(e,n.type);this._$Ei=t,null==s?this.removeAttribute(o):this.setAttribute(o,s),this._$Ei=null}}_$AK(t,e){var n,i,r;const o=this.constructor,s=o._$Eu.get(t);if(void 0!==s&&this._$Ei!==s){const t=o.getPropertyOptions(s),a=t.converter,c=null!==(r=null!==(i=null===(n=a)||void 0===n?void 0:n.fromAttribute)&&void 0!==i?i:"function"==typeof a?a:null)&&void 0!==r?r:u.fromAttribute;this._$Ei=s,this[s]=c(e,t.type),this._$Ei=null}}requestUpdate(t,e,n){let i=!0;void 0!==t&&(((n=n||this.constructor.getPropertyOptions(t)).hasChanged||h)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===n.reflect&&this._$Ei!==t&&(void 0===this._$E_&&(this._$E_=new Map),this._$E_.set(t,n))):i=!1),!this.isUpdatePending&&i&&(this._$Ep=this._$EC())}async _$EC(){this.isUpdatePending=!0;try{await this._$Ep}catch(t){Promise.reject(t)}const t=this.scheduleUpdate();return null!=t&&await t,!this.isUpdatePending}scheduleUpdate(){return this.performUpdate()}performUpdate(){var t;if(!this.isUpdatePending)return;this.hasUpdated,this._$Et&&(this._$Et.forEach(((t,e)=>this[e]=t)),this._$Et=void 0);let e=!1;const n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),null===(t=this._$Eg)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(n)):this._$EU()}catch(t){throw e=!1,this._$EU(),t}e&&this._$AE(n)}willUpdate(t){}_$AE(t){var e;null===(e=this._$Eg)||void 0===e||e.forEach((t=>{var e;return null===(e=t.hostUpdated)||void 0===e?void 0:e.call(t)})),this.hasUpdated||(this.hasUpdated=!0,this.firstUpdated(t)),this.updated(t)}_$EU(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$Ep}shouldUpdate(t){return!0}update(t){void 0!==this._$E_&&(this._$E_.forEach(((t,e)=>this._$ES(e,this[e],t))),this._$E_=void 0),this._$EU()}updated(t){}firstUpdated(t){}}var p;f.finalized=!0,f.elementProperties=new Map,f.elementStyles=[],f.shadowRootOptions={mode:"open"},null==l||l({ReactiveElement:f}),(null!==(s=globalThis.reactiveElementVersions)&&void 0!==s?s:globalThis.reactiveElementVersions=[]).push("1.2.1");const m=globalThis.trustedTypes,y=m?m.createPolicy("lit-html",{createHTML:t=>t}):void 0,v=`lit$${(Math.random()+"").slice(9)}$`,b="?"+v,_=`<${b}>`,g=document,$=(t="")=>g.createComment(t),w=t=>null===t||"object"!=typeof t&&"function"!=typeof t,A=Array.isArray,O=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,E=/-->/g,S=/>/g,j=/>|[ \n \r](?:([^\s"'>=/]+)([ \n \r]*=[ \n \r]*(?:[^ \n \r"'`<>=]|("|')|))|$)/g,x=/'/g,P=/"/g,k=/^(?:script|style|textarea)$/i,C=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),N=C(1),D=(C(2),Symbol.for("lit-noChange")),U=Symbol.for("lit-nothing"),T=new WeakMap,H=g.createTreeWalker(g,129,null,!1),M=(t,e)=>{const n=t.length-1,i=[];let r,o=2===e?"":"",s=O;for(let e=0;e"===c[0]?(s=null!=r?r:O,l=-1):void 0===c[1]?l=-2:(l=s.lastIndex-c[2].length,a=c[1],s=void 0===c[3]?j:'"'===c[3]?P:x):s===P||s===x?s=j:s===E||s===S?s=O:(s=j,r=void 0);const h=s===j&&t[e+1].startsWith("/>")?" ":"";o+=s===O?n+_:l>=0?(i.push(a),n.slice(0,l)+"$lit$"+n.slice(l)+v+h):n+v+(-2===l?(i.push(void 0),e):h)}const a=o+(t[n]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==y?y.createHTML(a):a,i]};class R{constructor({strings:t,_$litType$:e},n){let i;this.parts=[];let r=0,o=0;const s=t.length-1,a=this.parts,[c,l]=M(t,e);if(this.el=R.createElement(c,n),H.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(i=H.nextNode())&&a.length0){i.textContent=m?m.emptyScript:"";for(let n=0;n{var e;return A(t)||"function"==typeof(null===(e=t)||void 0===e?void 0:e[Symbol.iterator])})(t)?this.A(t):this.$(t)}M(t,e=this._$AB){return this._$AA.parentNode.insertBefore(t,e)}S(t){this._$AH!==t&&(this._$AR(),this._$AH=this.M(t))}$(t){this._$AH!==U&&w(this._$AH)?this._$AA.nextSibling.data=t:this.S(g.createTextNode(t)),this._$AH=t}T(t){var e;const{values:n,_$litType$:i}=t,r="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=R.createElement(i.h,this.options)),i);if((null===(e=this._$AH)||void 0===e?void 0:e._$AD)===r)this._$AH.m(n);else{const t=new z(r,this),e=t.p(this.options);t.m(n),this.S(e),this._$AH=t}}_$AC(t){let e=T.get(t.strings);return void 0===e&&T.set(t.strings,e=new R(t)),e}A(t){A(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let n,i=0;for(const r of t)i===e.length?e.push(n=new F(this.M($()),this.M($()),this,this.options)):n=e[i],n._$AI(r),i++;i2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=U}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,n,i){const r=this.strings;let o=!1;if(void 0===r)t=I(this,t,e,0),o=!w(t)||t!==this._$AH&&t!==D,o&&(this._$AH=t);else{const i=t;let s,a;for(t=r[0],s=0;s{var i,r;const o=null!==(i=null==n?void 0:n.renderBefore)&&void 0!==i?i:e;let s=o._$litPart$;if(void 0===s){const t=null!==(r=null==n?void 0:n.renderBefore)&&void 0!==r?r:null;o._$litPart$=s=new F(e.insertBefore($(),t),t,void 0,null!=n?n:{})}return s._$AI(t),s})(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Dt)||void 0===t||t.setConnected(!1)}render(){return D}}Q.finalized=!0,Q._$litElement$=!0,null===(Z=globalThis.litElementHydrateSupport)||void 0===Z||Z.call(globalThis,{LitElement:Q});const X=globalThis.litElementPolyfillSupport;var Y,tt,et;function nt(){return(nt=Object.assign||function(t){for(var e=1;e1&&void 0!==arguments[1]?arguments[1]:2;return Math.round(t*Math.pow(10,e))/Math.pow(10,e)}(t,null==n?void 0:n.maximumFractionDigits).toString()).concat("currency"===(null==n?void 0:n.style)?" ".concat(n.currency):"")},bt=function(t,e){var n=function(t){for(var e=1;e-1?t.split(".")[1].length:0;n.minimumFractionDigits=i,n.maximumFractionDigits=i}return n},_t=Number.isNaN||function(t){return"number"==typeof t&&t!=t};function gt(t,e){if(t.length!==e.length)return!1;for(var n=0;ne.hide_if.above)return!0;e.hide_if.value&&(i=i.concat(e.hide_if.value))}else i=i.concat(e.hide_if);return i.some((function(t){return"number"==typeof t?t===+n:t===n}))};function Dt(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,i)}return n}function Ut(t){for(var e=1;e\n
\n
'," ",'
\n
\n ','\n
\n
\n
\n ',"\n
\n ","\n \n "])),Kt(this.config),this.renderMainEntity(),this.config.title,this.info_entities.map((function(e){return t.renderInfoEntity(e.stateObj,e)})),this.config.column?"entities-column":"entities-row",this.entities.map((function(e){return t.renderEntity(e.stateObj,e)})),this._refCards):N(Mt||(Mt=Gt([""])))}},{key:"renderInfoEntity",value:function(t,e){if(!t||Nt(t,e))return null;var n=this.clickHandler(t.entity_id,e.tap_action);return N(It||(It=Gt(['
',"
"])),n,this.renderValue(t,e))}},{key:"renderEntity",value:function(t,e){if(!t||Nt(t,e))return null;var n=this.clickHandler(t.entity_id,e.tap_action),i=this.dblClickHandler(t.entity_id,e.double_tap_action);return N(zt||(zt=Gt(['
\n ',"\n
","
\n
"])),Kt(e),n,i,function(t,e){return!1===e.name?null:e.name||(e.entity?t.attributes.friendly_name||(n=t.entity_id).substr(n.indexOf(".")+1):null)||null;var n}(t,e),this.renderIcon(t,e))}},{key:"renderMainEntity",value:function(){if(!this.entity)return null;var t=this.clickHandler(this.stateObj.entity_id,this.config.tap_action),e=this.dblClickHandler(this.stateObj.entity_id,this.config.double_tap_action);return N(Ft||(Ft=Gt(['\n ',"\n "])),Kt(this.config),t,e,0===this.entities.length||this.config.icon?this.renderIcon(this.stateObj,this.config):this.renderValue(this.stateObj,this.config))}},{key:"renderValue",value:function(t,e){if(!0===e.toggle)return N(Bt||(Bt=Gt([''])),t,this._hass);if(!0===e.show_icon)return this.renderIcon(t,e);var n;if(e.attribute&&[ut,ht].includes(e.attribute))return N(Lt||(Lt=Gt([""])),this._hass,t[null===(n=e.attribute)||void 0===n?void 0:n.replace("-","_")]);if(e.format&&dt.includes(e.format)){var i=e.attribute?t.attributes[e.attribute]:t.state,r=new Date(i);return r instanceof Date&&!isNaN(r.getTime())?N(Vt||(Vt=Gt([""])),this._hass,r,e.format):i}return function(t,e,n){if(Ct(e))return t.localize("state.default.".concat(e.state));var i=n.attribute?e.attributes[n.attribute]:e.state,r=!1===n.unit?void 0:void 0!==n.attribute?n.unit:n.unit||e.attributes.unit_of_measurement;if(n.format){if(isNaN(parseFloat(i))||!isFinite(i));else if("brightness"===n.format)i=Math.round(i/255*100),r="%";else if(n.format.startsWith("duration"))i=function(t){var e=Math.floor(t/3600),n=Math.floor(t%3600/60),i=Math.floor(t%3600%60);return e>0?"".concat(e,":").concat(pt(n),":").concat(pt(i)):n>0?"".concat(n,":").concat(pt(i)):i>0?""+i:null}("duration-m"===n.format?i/1e3:i),r=void 0;else if(n.format.startsWith("precision")){var o=parseInt(n.format.slice(-1),10);i=vt(parseFloat(i),t.locale,{minimumFractionDigits:o,maximumFractionDigits:o})}else"kilo"===n.format?i=vt(i/1e3,t.locale,{maximumFractionDigits:2}):"invert"===n.format?i=vt(i-2*i,t.locale):"position"===n.format&&(i=vt(100-i,t.locale));return"".concat(i).concat(r?" ".concat(r):"")}if(n.attribute)return"".concat(isNaN(i)?i:vt(i,t.locale)).concat(r?" ".concat(r):"");var s=Ut(Ut({},e),{},{attributes:Ut(Ut({},e.attributes),{},{unit_of_measurement:r})});return function(t,e,n,i){var r=e.state;if(r===ct||r===at)return t("state.default.".concat(r));if(function(t){return!!t.attributes.unit_of_measurement||!!t.attributes.state_class}(e)){if("monetary"===e.attributes.device_class)try{return vt(r,n,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return"".concat(vt(r,n)).concat(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var o,s=function(t){return t.entity_id.substr(0,t.entity_id.indexOf("."))}(e);return"input_datetime"===s?e.attributes.has_date&&e.attributes.has_time?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),Et(o,n)):e.attributes.has_date?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),wt(o,n)):e.attributes.has_time?((o=new Date).setHours(e.attributes.hour,e.attributes.minute),jt(o,n)):e.state:"humidifier"===s&&"on"===r&&e.attributes.humidity?"".concat(e.attributes.humidity," %"):"counter"===s||"number"===s||"input_number"===s?vt(r,n):"button"===s||"sensor"===s&&"timestamp"===e.attributes.device_class?Et(new Date(r),n):e.attributes.device_class&&t("component.".concat(s,".state.").concat(e.attributes.device_class,".").concat(r))||t("component.".concat(s,".state._.").concat(r))||r}(t.localize,s,t.locale)}(this._hass,t,e)}},{key:"renderIcon",value:function(t,e){return N(Wt||(Wt=Gt([''])),t,!0===e.icon?t.attributes.icon||null:e.icon,e.state_color)}},{key:"renderWarning",value:function(){return N(qt||(qt=Gt(["\n ","\n "])),this._hass.localize("ui.panel.lovelace.warning.entity_not_found","entity",this.config.entity))}},{key:"clickHandler",value:function(t,e){var n=this;return function(){return st(n,n._hass,{entity:t,tap_action:e},!1,!1)}}},{key:"dblClickHandler",value:function(t,e){var n=this;return function(){return st(n,n._hass,{entity:t,double_tap_action:e},!0,!1)}}}])&&ee(e.prototype,n),i&&ee(e,i),Object.defineProperty(e,"prototype",{writable:!1}),c}(Q);customElements.define("room-card",oe)})(); \ No newline at end of file diff --git a/src/index.js b/src/index.js index d72cce7..4d378a7 100644 --- a/src/index.js +++ b/src/index.js @@ -121,7 +121,7 @@ class RoomCard extends LitElement { if (!this._hass || !this.config) return html``; return html` - +
${this.renderMainEntity()} ${this.config.title}