diff --git a/info.md b/info.md index cdcb316..59e1558 100644 --- a/info.md +++ b/info.md @@ -1,6 +1,12 @@ {% if installed %} ### Features +{% if version_installed.replace("v", "").replace(".","") | int < 10700 %} +- Added `Support for templating for styles` +- Added `Support for templating for title` +- Added `Support for templating for name` +{% endif %} + {% if version_installed.replace("v", "").replace(".","") | int < 10640 %} - Added `content_alignment (left, center or right) for rows` {% endif %} diff --git a/package.json b/package.json index 4c7c79f..7400fc6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "room-card", - "version": "1.06.41", + "version": "1.07.00", "description": "Show entities in Home Assistant's Lovelace UI", "keywords": [ "home-assistant", diff --git a/room-card.js b/room-card.js index bbff98a..16fb760 100644 --- a/room-card.js +++ b/room-card.js @@ -1,7 +1,7 @@ /*! For license information please see room-card.js.LICENSE.txt */ -(()=>{"use strict";var t={197:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_DOMAIN_ICON:()=>Z,DEFAULT_PANEL:()=>Q,DEFAULT_VIEW_ENTITY_ID:()=>st,DOMAINS_HIDE_MORE_INFO:()=>et,DOMAINS_MORE_INFO_NO_HISTORY:()=>it,DOMAINS_TOGGLE:()=>rt,DOMAINS_WITH_CARD:()=>X,DOMAINS_WITH_MORE_INFO:()=>tt,NumberFormat:()=>n,STATES_OFF:()=>nt,TimeFormat:()=>r,UNIT_C:()=>ot,UNIT_F:()=>at,applyThemesOnElement:()=>F,computeCardSize:()=>R,computeDomain:()=>H,computeEntity:()=>L,computeRTL:()=>V,computeRTLDirection:()=>z,computeStateDisplay:()=>J,computeStateDomain:()=>q,createThing:()=>dt,debounce:()=>mt,domainIcon:()=>ft,evaluateFilter:()=>pt,fireEvent:()=>lt,fixedIcons:()=>ht,formatDate:()=>c,formatDateMonth:()=>g,formatDateMonthYear:()=>v,formatDateNumeric:()=>m,formatDateShort:()=>f,formatDateTime:()=>A,formatDateTimeNumeric:()=>T,formatDateTimeWithSeconds:()=>E,formatDateWeekday:()=>l,formatDateYear:()=>b,formatNumber:()=>Y,formatTime:()=>N,formatTimeWeekday:()=>x,formatTimeWithSeconds:()=>D,forwardHaptic:()=>vt,getLovelace:()=>Tt,handleAction:()=>wt,handleActionConfig:()=>bt,handleClick:()=>$t,hasAction:()=>At,hasConfigOrEntityChanged:()=>St,hasDoubleClick:()=>Et,isNumericState:()=>W,navigate:()=>yt,numberFormatToLocale:()=>B,relativeTime:()=>M,round:()=>K,stateIcon:()=>Ct,timerTimeRemaining:()=>P,toggleEntity:()=>_t,turnOnOffEntities:()=>Ot,turnOnOffEntity:()=>gt});var n,r,o,a=function(){return a=Object.assign||function(t){for(var e,i=1,n=arguments.length;i0)return{value:Math.round(m),unit:"year"};var h=12*m+c.getMonth()-d.getMonth();if(Math.round(Math.abs(h))>0)return{value:Math.round(h),unit:"month"};var f=r/604800;return{value:Math.round(f),unit:"week"}}(t,i);return n?function(t){return new Intl.RelativeTimeFormat(t.language,{numeric:"auto"})}(e).format(r.value,r.unit):Intl.NumberFormat(e.language,{style:"unit",unit:r.unit,unitDisplay:"long"}).format(Math.abs(r.value))};function P(t){var e,i=3600*(e=t.attributes.remaining.split(":").map(Number))[0]+60*e[1]+e[2];if("active"===t.state){var n=(new Date).getTime(),r=new Date(t.last_changed).getTime();i=Math.max(i-(n-r)/1e3,0)}return i}function U(){return(U=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},J=function(t,e,i,n){var r=void 0!==n?n:e.state;if("unknown"===r||"unavailable"===r)return t("state.default."+r);if(W(e)){if("monetary"===e.attributes.device_class)try{return Y(r,i,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return Y(r,i)+(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var o=q(e);if("input_datetime"===o){var a;if(void 0===n)return e.attributes.has_date&&e.attributes.has_time?(a=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),A(a,i)):e.attributes.has_date?(a=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),c(a,i)):e.attributes.has_time?((a=new Date).setHours(e.attributes.hour,e.attributes.minute),N(a,i)):e.state;try{var s=n.split(" ");if(2===s.length)return A(new Date(s.join("T")),i);if(1===s.length){if(n.includes("-"))return c(new Date(n+"T00:00"),i);if(n.includes(":")){var l=new Date;return N(new Date(l.toISOString().split("T")[0]+"T"+n),i)}}return n}catch(t){return n}}return"humidifier"===o&&"on"===r&&e.attributes.humidity?e.attributes.humidity+" %":"counter"===o||"number"===o||"input_number"===o?Y(r,i):e.attributes.device_class&&t("component."+o+".state."+e.attributes.device_class+"."+r)||t("component."+o+".state._."+r)||r},Z="mdi:bookmark",Q="lovelace",X=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],tt=["alarm_control_panel","automation","camera","climate","configurator","cover","fan","group","history_graph","input_datetime","light","lock","media_player","script","sun","updater","vacuum","water_heater","weather"],et=["input_number","input_select","input_text","scene","weblink"],it=["camera","configurator","history_graph","scene"],nt=["closed","locked","off"],rt=new Set(["fan","input_boolean","light","switch","group","automation"]),ot="°C",at="°F",st="group.default_view",lt=function(t,e,i,n){n=n||{},i=null==i?{}:i;var r=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return r.detail=i,t.dispatchEvent(r),r},ut=new Set(["call-service","divider","section","weblink","cast","select"]),ct={alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"},dt=function(t,e){void 0===e&&(e=!1);var i=function(t,e){return n("hui-error-card",{type:"error",error:t,config:e})},n=function(t,e){var n=window.document.createElement(t);try{if(!n.setConfig)return;n.setConfig(e)}catch(n){return console.error(t,n),i(n.message,e)}return n};if(!t||"object"!=typeof t||!e&&!t.type)return i("No type defined",t);var r=t.type;if(r&&r.startsWith("custom:"))r=r.substr("custom:".length);else if(e)if(ut.has(r))r="hui-"+r+"-row";else{if(!t.entity)return i("Invalid config given.",t);var o=t.entity.split(".",1)[0];r="hui-"+(ct[o]||"text")+"-entity-row"}else r="hui-"+r+"-card";if(customElements.get(r))return n(r,t);var a=i("Custom element doesn't exist: "+t.type+".",t);a.style.display="None";var s=setTimeout((function(){a.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(s),lt(a,"ll-rebuild",{},a)})),a},mt=function(t,e,i){var n;return void 0===i&&(i=!1),function(){var r=[].slice.call(arguments),o=this,a=function(){n=null,i||t.apply(o,r)},s=i&&!n;clearTimeout(n),n=setTimeout(a,e),s&&t.apply(o,r)}},ht={alert:"mdi:alert",automation:"mdi:playlist-play",calendar:"mdi:calendar",camera:"mdi:video",climate:"mdi:thermostat",configurator:"mdi:settings",conversation:"mdi:text-to-speech",device_tracker:"mdi:account",fan:"mdi:fan",group:"mdi:google-circles-communities",history_graph:"mdi:chart-line",homeassistant:"mdi:home-assistant",homekit:"mdi:home-automation",image_processing:"mdi:image-filter-frames",input_boolean:"mdi:drawing",input_datetime:"mdi:calendar-clock",input_number:"mdi:ray-vertex",input_select:"mdi:format-list-bulleted",input_text:"mdi:textbox",light:"mdi:lightbulb",mailbox:"mdi:mailbox",notify:"mdi:comment-alert",person:"mdi:account",plant:"mdi:flower",proximity:"mdi:apple-safari",remote:"mdi:remote",scene:"mdi:google-pages",script:"mdi:file-document",sensor:"mdi:eye",simple_alarm:"mdi:bell",sun:"mdi:white-balance-sunny",switch:"mdi:flash",timer:"mdi:timer",updater:"mdi:cloud-upload",vacuum:"mdi:robot-vacuum",water_heater:"mdi:thermometer",weblink:"mdi:open-in-new"};function ft(t,e){if(t in ht)return ht[t];switch(t){case"alarm_control_panel":switch(e){case"armed_home":return"mdi:bell-plus";case"armed_night":return"mdi:bell-sleep";case"disarmed":return"mdi:bell-outline";case"triggered":return"mdi:bell-ring";default:return"mdi:bell"}case"binary_sensor":return e&&"off"===e?"mdi:radiobox-blank":"mdi:checkbox-marked-circle";case"cover":return"closed"===e?"mdi:window-closed":"mdi:window-open";case"lock":return e&&"unlocked"===e?"mdi:lock-open":"mdi:lock";case"media_player":return e&&"off"!==e&&"idle"!==e?"mdi:cast-connected":"mdi:cast";case"zwave":switch(e){case"dead":return"mdi:emoticon-dead";case"sleeping":return"mdi:sleep";case"initializing":return"mdi:timer-sand";default:return"mdi:z-wave"}default:return console.warn("Unable to find icon for domain "+t+" ("+e+")"),"mdi:bookmark"}}var pt=function(t,e){var i=e.value||e,n=e.attribute?t.attributes[e.attribute]:t.state;switch(e.operator||"=="){case"==":return n===i;case"<=":return n<=i;case"<":return n=":return n>=i;case">":return n>i;case"!=":return n!==i;case"regex":return n.match(i);default:return!1}},vt=function(t){lt(window,"haptic",t)},yt=function(t,e,i){void 0===i&&(i=!1),i?history.replaceState(null,"",e):history.pushState(null,"",e),lt(window,"location-changed",{replace:i})},gt=function(t,e,i){void 0===i&&(i=!0);var n,r=H(e),o="group"===r?"homeassistant":r;switch(r){case"lock":n=i?"unlock":"lock";break;case"cover":n=i?"open_cover":"close_cover";break;default:n=i?"turn_on":"turn_off"}return t.callService(o,n,{entity_id:e})},_t=function(t,e){var i=nt.includes(t.states[e].state);return gt(t,e,i)},bt=function(t,e,i,n){if(n||(n={action:"more-info"}),!n.confirmation||n.confirmation.exemptions&&n.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||(vt("warning"),confirm(n.confirmation.text||"Are you sure you want to "+n.action+"?")))switch(n.action){case"more-info":(i.entity||i.camera_image)&<(t,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":n.navigation_path&&yt(0,n.navigation_path);break;case"url":n.url_path&&window.open(n.url_path);break;case"toggle":i.entity&&(_t(e,i.entity),vt("success"));break;case"call-service":if(!n.service)return void vt("failure");var r=n.service.split(".",2);e.callService(r[0],r[1],n.service_data,n.target),vt("success");break;case"fire-dom-event":lt(t,"ll-custom",n)}},wt=function(t,e,i,n){var r;"double_tap"===n&&i.double_tap_action?r=i.double_tap_action:"hold"===n&&i.hold_action?r=i.hold_action:"tap"===n&&i.tap_action&&(r=i.tap_action),bt(t,e,i,r)},$t=function(t,e,i,n,r){var o;if(r&&i.double_tap_action?o=i.double_tap_action:n&&i.hold_action?o=i.hold_action:!n&&i.tap_action&&(o=i.tap_action),o||(o={action:"more-info"}),!o.confirmation||o.confirmation.exemptions&&o.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?"))switch(o.action){case"more-info":(o.entity||i.entity||i.camera_image)&&(lt(t,"hass-more-info",{entityId:o.entity?o.entity:i.entity?i.entity:i.camera_image}),o.haptic&&vt(o.haptic));break;case"navigate":o.navigation_path&&(yt(0,o.navigation_path),o.haptic&&vt(o.haptic));break;case"url":o.url_path&&window.open(o.url_path),o.haptic&&vt(o.haptic);break;case"toggle":i.entity&&(_t(e,i.entity),o.haptic&&vt(o.haptic));break;case"call-service":if(!o.service)return;var a=o.service.split(".",2),s=a[0],l=a[1],u=U({},o.service_data);"entity"===u.entity_id&&(u.entity_id=i.entity),e.callService(s,l,u,o.target),o.haptic&&vt(o.haptic);break;case"fire-dom-event":lt(t,"ll-custom",o),o.haptic&&vt(o.haptic)}};function At(t){return void 0!==t&&"none"!==t.action}function St(t,e,i){if(e.has("config")||i)return!0;if(t.config.entity){var n=e.get("hass");return!n||n.states[t.config.entity]!==t.hass.states[t.config.entity]}return!1}function Et(t){return void 0!==t&&"none"!==t.action}var Ot=function(t,e,i){void 0===i&&(i=!0);var n={};e.forEach((function(e){if(nt.includes(t.states[e].state)===i){var r=H(e),o=["cover","lock"].includes(r)?r:"homeassistant";o in n||(n[o]=[]),n[o].push(e)}})),Object.keys(n).forEach((function(e){var r;switch(e){case"lock":r=i?"unlock":"lock";break;case"cover":r=i?"open_cover":"close_cover";break;default:r=i?"turn_on":"turn_off"}t.callService(e,r,{entity_id:n[e]})}))},Tt=function(){var t=document.querySelector("home-assistant");if(t=(t=(t=(t=(t=(t=(t=(t=t&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root")){var e=t.lovelace;return e.current_view=t.___curView,e}return null},kt={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Nt={binary_sensor:function(t,e){var i="off"===t;switch(null==e?void 0:e.attributes.device_class){case"battery":return i?"mdi:battery":"mdi:battery-outline";case"battery_charging":return i?"mdi:battery":"mdi:battery-charging";case"cold":return i?"mdi:thermometer":"mdi:snowflake";case"connectivity":return i?"mdi:server-network-off":"mdi:server-network";case"door":return i?"mdi:door-closed":"mdi:door-open";case"garage_door":return i?"mdi:garage":"mdi:garage-open";case"power":case"plug":return i?"mdi:power-plug-off":"mdi:power-plug";case"gas":case"problem":case"safety":case"tamper":return i?"mdi:check-circle":"mdi:alert-circle";case"smoke":return i?"mdi:check-circle":"mdi:smoke";case"heat":return i?"mdi:thermometer":"mdi:fire";case"light":return i?"mdi:brightness-5":"mdi:brightness-7";case"lock":return i?"mdi:lock":"mdi:lock-open";case"moisture":return i?"mdi:water-off":"mdi:water";case"motion":return i?"mdi:walk":"mdi:run";case"occupancy":case"presence":return i?"mdi:home-outline":"mdi:home";case"opening":return i?"mdi:square":"mdi:square-outline";case"running":return i?"mdi:stop":"mdi:play";case"sound":return i?"mdi:music-note-off":"mdi:music-note";case"update":return i?"mdi:package":"mdi:package-up";case"vibration":return i?"mdi:crop-portrait":"mdi:vibrate";case"window":return i?"mdi:window-closed":"mdi:window-open";default:return i?"mdi:radiobox-blank":"mdi:checkbox-marked-circle"}},cover:function(t){var e="closed"!==t.state;switch(t.attributes.device_class){case"garage":return e?"mdi:garage-open":"mdi:garage";case"door":return e?"mdi:door-open":"mdi:door-closed";case"shutter":return e?"mdi:window-shutter-open":"mdi:window-shutter";case"blind":return e?"mdi:blinds-open":"mdi:blinds";case"window":return e?"mdi:window-open":"mdi:window-closed";default:return ft("cover",t.state)}},sensor:function(t){var e=t.attributes.device_class;if(e&&e in kt)return kt[e];if("battery"===e){var i=Number(t.state);if(isNaN(i))return"mdi:battery-unknown";var n=10*Math.round(i/10);return n>=100?"mdi:battery":n<=0?"mdi:battery-alert":"hass:battery-"+n}var r=t.attributes.unit_of_measurement;return"°C"===r||"°F"===r?"mdi:thermometer":ft("sensor")},input_datetime:function(t){return t.attributes.has_date?t.attributes.has_time?ft("input_datetime"):"mdi:calendar":"mdi:clock"}},Ct=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=H(t.entity_id);return e in Nt?Nt[e](t):ft(e,t.state)}},461:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.holdHandler=e.dblClickHandler=e.clickHandler=e.renderInfoEntity=e.renderTitle=e.renderMainEntity=e.renderValue=e.renderIcon=e.renderEntity=e.renderEntitiesRow=e.renderRows=e.entityStyles=e.entityStateDisplay=e.renderCustomStateIcon=e.renderConditionIcons=e.entityIcon=e.entityName=e.computeEntity=e.checkConfig=void 0;const n=i(230),r=i(759),o=i(578),a=i(882),s=i(197),l=i(897),u=i(623),c=i(704),d=i(846);e.checkConfig=t=>{if(null==t.entities&&null==t.entity&&void 0===t.info_entities&&void 0===t.rows&&void 0===t.cards)throw new Error("Please define entities.")},e.computeEntity=t=>t.substr(t.indexOf(".")+1),e.entityName=t=>t.name||(t.entity?t.stateObj.attributes.friendly_name||(0,e.computeEntity)(t.stateObj.entity_id):null)||null,e.entityIcon=(t,i,n)=>{var r;if("icon"in i&&(void 0===i.show_icon||!1===i.show_icon))throw new Error(`Entity: ${i.entity} => Icon defined but show_icon is set to false or not defined. Please set show_icon to true`);return"icon"in i?"string"==typeof i.icon?i.icon:i.icon.state_on?(0,e.renderCustomStateIcon)(t,i.icon):i.icon.conditions?(0,e.renderConditionIcons)(t,i,n):(null===(r=i.icon.template)||void 0===r?void 0:r.icon)?(0,a.evalTemplate)(n,t,i.icon.template.icon):void 0:t.attributes.icon||null},e.renderConditionIcons=(t,e,i)=>{const n=t.state;return e.icon.conditions.filter((e=>{let r=n;if(e.entity){const t=i.states[e.entity];r=e.attribute?t.attributes[e.attribute]:t.state}return e.attribute&&!e.entity&&(r=t.attributes[e.attribute]),(0,a.checkConditionalValue)(e,r)})).pop()},e.renderCustomStateIcon=(t,e)=>{switch((0,o.computeStateDomain)(t)){case"light":case"switch":case"binary_sensor":case"input_boolean":return"on"===t.state?e.state_on:e.state_off}},e.entityStateDisplay=(t,e)=>{if((0,a.isUnavailable)(e.stateObj))return t.localize(`state.default.${e.stateObj.state}`);let i=(0,a.getValue)(e),s=void 0!==e.attribute?e.unit:e.unit||e.stateObj.attributes.unit_of_measurement;if(e.format){if(e.format.startsWith("precision")){const n=parseInt(e.format.slice(-1),10);i=(0,r.formatNumber)(i,t.locale,{minimumFractionDigits:n,maximumFractionDigits:n})}else isNaN(parseFloat(i))||!isFinite(i)||("brightness"===e.format?(i=Math.round(i/255*100),s="%"):e.format.startsWith("duration")?(i=(0,n.secondsToDuration)("duration-m"===e.format?i/1e3:i),s=void 0):"kilo"===e.format?i=(0,r.formatNumber)(i/1e3,t.locale,{maximumFractionDigits:2}):"invert"===e.format?i=(0,r.formatNumber)(i-2*i,t.locale):"position"===e.format&&(i=(0,r.formatNumber)(100-i,t.locale)));return`${i}${s?` ${s}`:""}`}if(e.attribute)return`${isNaN(i)?i:(0,r.formatNumber)(i,t.locale)}${s?` ${s}`:""}`;const l=Object.assign(Object.assign({},e.stateObj),{attributes:Object.assign(Object.assign({},e.stateObj.attributes),{unit_of_measurement:s})});return(0,o.computeStateDisplay)(t.localize,l,t.locale)},e.entityStyles=t=>(0,a.isObject)(t)?Object.keys(t).map((e=>`${e}: ${t[e]};`)).join(""):"",e.renderRows=(t,i,n,r)=>{const o=i.filter((t=>!(0,d.hideIfRow)(t,n)));return l.html`${o.map((t=>(0,e.renderEntitiesRow)(t,t.entities,n,r)))}`},e.renderEntitiesRow=(t,i,n,r,o)=>void 0===i?null:l.html`
${i.map((t=>(0,e.renderEntity)(t,n,r)))}
`,e.renderEntity=(t,i,n)=>{if(null==t.stateObj||(0,d.hideIfEntity)(t,i))return null;const r=(0,e.clickHandler)(t.stateObj.entity_id,t.tap_action,i,n),o=(0,e.dblClickHandler)(t.stateObj.entity_id,t.double_tap_action,i,n),a=(0,e.holdHandler)(t.stateObj.entity_id,t.hold_action,i,n);let s,u,c;const m=()=>{s=!1,u=window.setTimeout((()=>{s=!0}),500)},h=e=>{e.preventDefault(),["touchend","touchcancel"].includes(e.type)&&void 0===u||(window.clearTimeout(u),u=void 0,s?a():void 0!==t.double_tap_action?"click"===e.type&&e.detail<2||!c?c=window.setTimeout((()=>{c=void 0,r()}),250):(window.clearTimeout(c),c=void 0,o()):r())};return l.html`
{"use strict";var t={197:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_DOMAIN_ICON:()=>Z,DEFAULT_PANEL:()=>Q,DEFAULT_VIEW_ENTITY_ID:()=>st,DOMAINS_HIDE_MORE_INFO:()=>et,DOMAINS_MORE_INFO_NO_HISTORY:()=>it,DOMAINS_TOGGLE:()=>rt,DOMAINS_WITH_CARD:()=>X,DOMAINS_WITH_MORE_INFO:()=>tt,NumberFormat:()=>n,STATES_OFF:()=>nt,TimeFormat:()=>r,UNIT_C:()=>ot,UNIT_F:()=>at,applyThemesOnElement:()=>F,computeCardSize:()=>R,computeDomain:()=>H,computeEntity:()=>L,computeRTL:()=>V,computeRTLDirection:()=>z,computeStateDisplay:()=>J,computeStateDomain:()=>q,createThing:()=>dt,debounce:()=>mt,domainIcon:()=>pt,evaluateFilter:()=>ft,fireEvent:()=>lt,fixedIcons:()=>ht,formatDate:()=>c,formatDateMonth:()=>g,formatDateMonthYear:()=>v,formatDateNumeric:()=>m,formatDateShort:()=>p,formatDateTime:()=>A,formatDateTimeNumeric:()=>T,formatDateTimeWithSeconds:()=>E,formatDateWeekday:()=>l,formatDateYear:()=>b,formatNumber:()=>Y,formatTime:()=>N,formatTimeWeekday:()=>x,formatTimeWithSeconds:()=>D,forwardHaptic:()=>vt,getLovelace:()=>Tt,handleAction:()=>wt,handleActionConfig:()=>bt,handleClick:()=>$t,hasAction:()=>At,hasConfigOrEntityChanged:()=>St,hasDoubleClick:()=>Et,isNumericState:()=>W,navigate:()=>yt,numberFormatToLocale:()=>B,relativeTime:()=>M,round:()=>K,stateIcon:()=>Ct,timerTimeRemaining:()=>P,toggleEntity:()=>_t,turnOnOffEntities:()=>Ot,turnOnOffEntity:()=>gt});var n,r,o,a=function(){return a=Object.assign||function(t){for(var e,i=1,n=arguments.length;i0)return{value:Math.round(m),unit:"year"};var h=12*m+c.getMonth()-d.getMonth();if(Math.round(Math.abs(h))>0)return{value:Math.round(h),unit:"month"};var p=r/604800;return{value:Math.round(p),unit:"week"}}(t,i);return n?function(t){return new Intl.RelativeTimeFormat(t.language,{numeric:"auto"})}(e).format(r.value,r.unit):Intl.NumberFormat(e.language,{style:"unit",unit:r.unit,unitDisplay:"long"}).format(Math.abs(r.value))};function P(t){var e,i=3600*(e=t.attributes.remaining.split(":").map(Number))[0]+60*e[1]+e[2];if("active"===t.state){var n=(new Date).getTime(),r=new Date(t.last_changed).getTime();i=Math.max(i-(n-r)/1e3,0)}return i}function U(){return(U=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},J=function(t,e,i,n){var r=void 0!==n?n:e.state;if("unknown"===r||"unavailable"===r)return t("state.default."+r);if(W(e)){if("monetary"===e.attributes.device_class)try{return Y(r,i,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return Y(r,i)+(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var o=q(e);if("input_datetime"===o){var a;if(void 0===n)return e.attributes.has_date&&e.attributes.has_time?(a=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),A(a,i)):e.attributes.has_date?(a=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),c(a,i)):e.attributes.has_time?((a=new Date).setHours(e.attributes.hour,e.attributes.minute),N(a,i)):e.state;try{var s=n.split(" ");if(2===s.length)return A(new Date(s.join("T")),i);if(1===s.length){if(n.includes("-"))return c(new Date(n+"T00:00"),i);if(n.includes(":")){var l=new Date;return N(new Date(l.toISOString().split("T")[0]+"T"+n),i)}}return n}catch(t){return n}}return"humidifier"===o&&"on"===r&&e.attributes.humidity?e.attributes.humidity+" %":"counter"===o||"number"===o||"input_number"===o?Y(r,i):e.attributes.device_class&&t("component."+o+".state."+e.attributes.device_class+"."+r)||t("component."+o+".state._."+r)||r},Z="mdi:bookmark",Q="lovelace",X=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],tt=["alarm_control_panel","automation","camera","climate","configurator","cover","fan","group","history_graph","input_datetime","light","lock","media_player","script","sun","updater","vacuum","water_heater","weather"],et=["input_number","input_select","input_text","scene","weblink"],it=["camera","configurator","history_graph","scene"],nt=["closed","locked","off"],rt=new Set(["fan","input_boolean","light","switch","group","automation"]),ot="°C",at="°F",st="group.default_view",lt=function(t,e,i,n){n=n||{},i=null==i?{}:i;var r=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return r.detail=i,t.dispatchEvent(r),r},ut=new Set(["call-service","divider","section","weblink","cast","select"]),ct={alert:"toggle",automation:"toggle",climate:"climate",cover:"cover",fan:"toggle",group:"group",input_boolean:"toggle",input_number:"input-number",input_select:"input-select",input_text:"input-text",light:"toggle",lock:"lock",media_player:"media-player",remote:"toggle",scene:"scene",script:"script",sensor:"sensor",timer:"timer",switch:"toggle",vacuum:"toggle",water_heater:"climate",input_datetime:"input-datetime"},dt=function(t,e){void 0===e&&(e=!1);var i=function(t,e){return n("hui-error-card",{type:"error",error:t,config:e})},n=function(t,e){var n=window.document.createElement(t);try{if(!n.setConfig)return;n.setConfig(e)}catch(n){return console.error(t,n),i(n.message,e)}return n};if(!t||"object"!=typeof t||!e&&!t.type)return i("No type defined",t);var r=t.type;if(r&&r.startsWith("custom:"))r=r.substr("custom:".length);else if(e)if(ut.has(r))r="hui-"+r+"-row";else{if(!t.entity)return i("Invalid config given.",t);var o=t.entity.split(".",1)[0];r="hui-"+(ct[o]||"text")+"-entity-row"}else r="hui-"+r+"-card";if(customElements.get(r))return n(r,t);var a=i("Custom element doesn't exist: "+t.type+".",t);a.style.display="None";var s=setTimeout((function(){a.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(s),lt(a,"ll-rebuild",{},a)})),a},mt=function(t,e,i){var n;return void 0===i&&(i=!1),function(){var r=[].slice.call(arguments),o=this,a=function(){n=null,i||t.apply(o,r)},s=i&&!n;clearTimeout(n),n=setTimeout(a,e),s&&t.apply(o,r)}},ht={alert:"mdi:alert",automation:"mdi:playlist-play",calendar:"mdi:calendar",camera:"mdi:video",climate:"mdi:thermostat",configurator:"mdi:settings",conversation:"mdi:text-to-speech",device_tracker:"mdi:account",fan:"mdi:fan",group:"mdi:google-circles-communities",history_graph:"mdi:chart-line",homeassistant:"mdi:home-assistant",homekit:"mdi:home-automation",image_processing:"mdi:image-filter-frames",input_boolean:"mdi:drawing",input_datetime:"mdi:calendar-clock",input_number:"mdi:ray-vertex",input_select:"mdi:format-list-bulleted",input_text:"mdi:textbox",light:"mdi:lightbulb",mailbox:"mdi:mailbox",notify:"mdi:comment-alert",person:"mdi:account",plant:"mdi:flower",proximity:"mdi:apple-safari",remote:"mdi:remote",scene:"mdi:google-pages",script:"mdi:file-document",sensor:"mdi:eye",simple_alarm:"mdi:bell",sun:"mdi:white-balance-sunny",switch:"mdi:flash",timer:"mdi:timer",updater:"mdi:cloud-upload",vacuum:"mdi:robot-vacuum",water_heater:"mdi:thermometer",weblink:"mdi:open-in-new"};function pt(t,e){if(t in ht)return ht[t];switch(t){case"alarm_control_panel":switch(e){case"armed_home":return"mdi:bell-plus";case"armed_night":return"mdi:bell-sleep";case"disarmed":return"mdi:bell-outline";case"triggered":return"mdi:bell-ring";default:return"mdi:bell"}case"binary_sensor":return e&&"off"===e?"mdi:radiobox-blank":"mdi:checkbox-marked-circle";case"cover":return"closed"===e?"mdi:window-closed":"mdi:window-open";case"lock":return e&&"unlocked"===e?"mdi:lock-open":"mdi:lock";case"media_player":return e&&"off"!==e&&"idle"!==e?"mdi:cast-connected":"mdi:cast";case"zwave":switch(e){case"dead":return"mdi:emoticon-dead";case"sleeping":return"mdi:sleep";case"initializing":return"mdi:timer-sand";default:return"mdi:z-wave"}default:return console.warn("Unable to find icon for domain "+t+" ("+e+")"),"mdi:bookmark"}}var ft=function(t,e){var i=e.value||e,n=e.attribute?t.attributes[e.attribute]:t.state;switch(e.operator||"=="){case"==":return n===i;case"<=":return n<=i;case"<":return n=":return n>=i;case">":return n>i;case"!=":return n!==i;case"regex":return n.match(i);default:return!1}},vt=function(t){lt(window,"haptic",t)},yt=function(t,e,i){void 0===i&&(i=!1),i?history.replaceState(null,"",e):history.pushState(null,"",e),lt(window,"location-changed",{replace:i})},gt=function(t,e,i){void 0===i&&(i=!0);var n,r=H(e),o="group"===r?"homeassistant":r;switch(r){case"lock":n=i?"unlock":"lock";break;case"cover":n=i?"open_cover":"close_cover";break;default:n=i?"turn_on":"turn_off"}return t.callService(o,n,{entity_id:e})},_t=function(t,e){var i=nt.includes(t.states[e].state);return gt(t,e,i)},bt=function(t,e,i,n){if(n||(n={action:"more-info"}),!n.confirmation||n.confirmation.exemptions&&n.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||(vt("warning"),confirm(n.confirmation.text||"Are you sure you want to "+n.action+"?")))switch(n.action){case"more-info":(i.entity||i.camera_image)&<(t,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":n.navigation_path&&yt(0,n.navigation_path);break;case"url":n.url_path&&window.open(n.url_path);break;case"toggle":i.entity&&(_t(e,i.entity),vt("success"));break;case"call-service":if(!n.service)return void vt("failure");var r=n.service.split(".",2);e.callService(r[0],r[1],n.service_data,n.target),vt("success");break;case"fire-dom-event":lt(t,"ll-custom",n)}},wt=function(t,e,i,n){var r;"double_tap"===n&&i.double_tap_action?r=i.double_tap_action:"hold"===n&&i.hold_action?r=i.hold_action:"tap"===n&&i.tap_action&&(r=i.tap_action),bt(t,e,i,r)},$t=function(t,e,i,n,r){var o;if(r&&i.double_tap_action?o=i.double_tap_action:n&&i.hold_action?o=i.hold_action:!n&&i.tap_action&&(o=i.tap_action),o||(o={action:"more-info"}),!o.confirmation||o.confirmation.exemptions&&o.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||confirm(o.confirmation.text||"Are you sure you want to "+o.action+"?"))switch(o.action){case"more-info":(o.entity||i.entity||i.camera_image)&&(lt(t,"hass-more-info",{entityId:o.entity?o.entity:i.entity?i.entity:i.camera_image}),o.haptic&&vt(o.haptic));break;case"navigate":o.navigation_path&&(yt(0,o.navigation_path),o.haptic&&vt(o.haptic));break;case"url":o.url_path&&window.open(o.url_path),o.haptic&&vt(o.haptic);break;case"toggle":i.entity&&(_t(e,i.entity),o.haptic&&vt(o.haptic));break;case"call-service":if(!o.service)return;var a=o.service.split(".",2),s=a[0],l=a[1],u=U({},o.service_data);"entity"===u.entity_id&&(u.entity_id=i.entity),e.callService(s,l,u,o.target),o.haptic&&vt(o.haptic);break;case"fire-dom-event":lt(t,"ll-custom",o),o.haptic&&vt(o.haptic)}};function At(t){return void 0!==t&&"none"!==t.action}function St(t,e,i){if(e.has("config")||i)return!0;if(t.config.entity){var n=e.get("hass");return!n||n.states[t.config.entity]!==t.hass.states[t.config.entity]}return!1}function Et(t){return void 0!==t&&"none"!==t.action}var Ot=function(t,e,i){void 0===i&&(i=!0);var n={};e.forEach((function(e){if(nt.includes(t.states[e].state)===i){var r=H(e),o=["cover","lock"].includes(r)?r:"homeassistant";o in n||(n[o]=[]),n[o].push(e)}})),Object.keys(n).forEach((function(e){var r;switch(e){case"lock":r=i?"unlock":"lock";break;case"cover":r=i?"open_cover":"close_cover";break;default:r=i?"turn_on":"turn_off"}t.callService(e,r,{entity_id:n[e]})}))},Tt=function(){var t=document.querySelector("home-assistant");if(t=(t=(t=(t=(t=(t=(t=(t=t&&t.shadowRoot)&&t.querySelector("home-assistant-main"))&&t.shadowRoot)&&t.querySelector("app-drawer-layout partial-panel-resolver"))&&t.shadowRoot||t)&&t.querySelector("ha-panel-lovelace"))&&t.shadowRoot)&&t.querySelector("hui-root")){var e=t.lovelace;return e.current_view=t.___curView,e}return null},kt={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Nt={binary_sensor:function(t,e){var i="off"===t;switch(null==e?void 0:e.attributes.device_class){case"battery":return i?"mdi:battery":"mdi:battery-outline";case"battery_charging":return i?"mdi:battery":"mdi:battery-charging";case"cold":return i?"mdi:thermometer":"mdi:snowflake";case"connectivity":return i?"mdi:server-network-off":"mdi:server-network";case"door":return i?"mdi:door-closed":"mdi:door-open";case"garage_door":return i?"mdi:garage":"mdi:garage-open";case"power":case"plug":return i?"mdi:power-plug-off":"mdi:power-plug";case"gas":case"problem":case"safety":case"tamper":return i?"mdi:check-circle":"mdi:alert-circle";case"smoke":return i?"mdi:check-circle":"mdi:smoke";case"heat":return i?"mdi:thermometer":"mdi:fire";case"light":return i?"mdi:brightness-5":"mdi:brightness-7";case"lock":return i?"mdi:lock":"mdi:lock-open";case"moisture":return i?"mdi:water-off":"mdi:water";case"motion":return i?"mdi:walk":"mdi:run";case"occupancy":case"presence":return i?"mdi:home-outline":"mdi:home";case"opening":return i?"mdi:square":"mdi:square-outline";case"running":return i?"mdi:stop":"mdi:play";case"sound":return i?"mdi:music-note-off":"mdi:music-note";case"update":return i?"mdi:package":"mdi:package-up";case"vibration":return i?"mdi:crop-portrait":"mdi:vibrate";case"window":return i?"mdi:window-closed":"mdi:window-open";default:return i?"mdi:radiobox-blank":"mdi:checkbox-marked-circle"}},cover:function(t){var e="closed"!==t.state;switch(t.attributes.device_class){case"garage":return e?"mdi:garage-open":"mdi:garage";case"door":return e?"mdi:door-open":"mdi:door-closed";case"shutter":return e?"mdi:window-shutter-open":"mdi:window-shutter";case"blind":return e?"mdi:blinds-open":"mdi:blinds";case"window":return e?"mdi:window-open":"mdi:window-closed";default:return pt("cover",t.state)}},sensor:function(t){var e=t.attributes.device_class;if(e&&e in kt)return kt[e];if("battery"===e){var i=Number(t.state);if(isNaN(i))return"mdi:battery-unknown";var n=10*Math.round(i/10);return n>=100?"mdi:battery":n<=0?"mdi:battery-alert":"hass:battery-"+n}var r=t.attributes.unit_of_measurement;return"°C"===r||"°F"===r?"mdi:thermometer":pt("sensor")},input_datetime:function(t){return t.attributes.has_date?t.attributes.has_time?pt("input_datetime"):"mdi:calendar":"mdi:clock"}},Ct=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=H(t.entity_id);return e in Nt?Nt[e](t):pt(e,t.state)}},461:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.holdHandler=e.dblClickHandler=e.clickHandler=e.renderInfoEntity=e.renderTitle=e.renderMainEntity=e.renderValue=e.renderIcon=e.renderEntity=e.renderEntitiesRow=e.renderRows=e.entityStyles=e.entityStateDisplay=e.renderCustomStateIcon=e.renderConditionIcons=e.entityIcon=e.entityName=e.computeEntity=e.checkConfig=void 0;const n=i(230),r=i(759),o=i(578),a=i(882),s=i(197),l=i(897),u=i(623),c=i(704),d=i(846);e.checkConfig=t=>{if(null==t.entities&&null==t.entity&&void 0===t.info_entities&&void 0===t.rows&&void 0===t.cards)throw new Error("Please define entities.")},e.computeEntity=t=>t.substr(t.indexOf(".")+1),e.entityName=(t,i)=>(0,c.getTemplateOrAttribute)(t.name,i,t.stateObj)||(t.entity?t.stateObj.attributes.friendly_name||(0,e.computeEntity)(t.stateObj.entity_id):null)||null,e.entityIcon=(t,i,n)=>{var r;if("icon"in i&&(void 0===i.show_icon||!1===i.show_icon))throw new Error(`Entity: ${i.entity} => Icon defined but show_icon is set to false or not defined. Please set show_icon to true`);return"icon"in i?"string"==typeof i.icon?i.icon:i.icon.state_on?(0,e.renderCustomStateIcon)(t,i.icon):i.icon.conditions?(0,e.renderConditionIcons)(t,i,n):(null===(r=i.icon.template)||void 0===r?void 0:r.icon)?(0,a.evalTemplate)(n,t,i.icon.template.icon):void 0:t.attributes.icon||null},e.renderConditionIcons=(t,e,i)=>{const n=t.state;return e.icon.conditions.filter((e=>{let r=n;if(e.entity){const t=i.states[e.entity];r=e.attribute?t.attributes[e.attribute]:t.state}return e.attribute&&!e.entity&&(r=t.attributes[e.attribute]),(0,a.checkConditionalValue)(e,r)})).pop()},e.renderCustomStateIcon=(t,e)=>{switch((0,o.computeStateDomain)(t)){case"light":case"switch":case"binary_sensor":case"input_boolean":return"on"===t.state?e.state_on:e.state_off}},e.entityStateDisplay=(t,e)=>{if((0,a.isUnavailable)(e.stateObj))return t.localize(`state.default.${e.stateObj.state}`);let i=(0,a.getValue)(e),s=void 0!==e.attribute?e.unit:e.unit||e.stateObj.attributes.unit_of_measurement;if(e.format){if(e.format.startsWith("precision")){const n=parseInt(e.format.slice(-1),10);i=(0,r.formatNumber)(i,t.locale,{minimumFractionDigits:n,maximumFractionDigits:n})}else isNaN(parseFloat(i))||!isFinite(i)||("brightness"===e.format?(i=Math.round(i/255*100),s="%"):e.format.startsWith("duration")?(i=(0,n.secondsToDuration)("duration-m"===e.format?i/1e3:i),s=void 0):"kilo"===e.format?i=(0,r.formatNumber)(i/1e3,t.locale,{maximumFractionDigits:2}):"invert"===e.format?i=(0,r.formatNumber)(i-2*i,t.locale):"position"===e.format&&(i=(0,r.formatNumber)(100-i,t.locale)));return`${i}${s?` ${s}`:""}`}if(e.attribute)return`${isNaN(i)?i:(0,r.formatNumber)(i,t.locale)}${s?` ${s}`:""}`;const l=Object.assign(Object.assign({},e.stateObj),{attributes:Object.assign(Object.assign({},e.stateObj.attributes),{unit_of_measurement:s})});return(0,o.computeStateDisplay)(t.localize,l,t.locale)},e.entityStyles=(t,e,i)=>{if(!t)return"";if("template"in t){const n=t;return(0,a.evalTemplate)(i,e,n.template)}const n=t;return Object.keys(n).map((t=>`${t}: ${n[t]};`)).join("")},e.renderRows=(t,i,n)=>{const r=t.filter((t=>!(0,d.hideIfRow)(t,i)));return l.html`${r.map((t=>(0,e.renderEntitiesRow)(t,t.entities,i,n)))}`},e.renderEntitiesRow=(t,i,n,r,o)=>void 0===i?null:l.html`
${i.map((t=>(0,e.renderEntity)(t,n,r)))}
`,e.renderEntity=(t,i,n)=>{if(null==t.stateObj||(0,d.hideIfEntity)(t,i))return null;const r=(0,e.clickHandler)(t.stateObj.entity_id,t.tap_action,i,n),o=(0,e.dblClickHandler)(t.stateObj.entity_id,t.double_tap_action,i,n),a=(0,e.holdHandler)(t.stateObj.entity_id,t.hold_action,i,n);let s,u,c;const m=()=>{s=!1,u=window.setTimeout((()=>{s=!0}),500)},h=e=>{e.preventDefault(),["touchend","touchcancel"].includes(e.type)&&void 0===u||(window.clearTimeout(u),u=void 0,s?a():void 0!==t.double_tap_action?"click"===e.type&&e.detail<2||!c?c=window.setTimeout((()=>{c=void 0,r()}),250):(window.clearTimeout(c),c=void 0,o()):r())};return l.html`
- ${void 0===t.show_name||t.show_name?l.html`${(0,e.entityName)(t)}`:""} + ${void 0===t.show_name||t.show_name?l.html`${(0,e.entityName)(t,i)}`:""}
${(0,e.renderIcon)(t.stateObj,t,i)}
${t.show_state?l.html`${(0,e.entityStateDisplay)(i,t)}`:""}
`},e.renderIcon=(t,i,n,r)=>{if(void 0!==i.show_icon&&!1===i.show_icon)return null;const o=(0,e.entityIcon)(t,i,n),s=(0,c.templateStyling)(t,i,n);return l.html``},e.renderValue=(t,i)=>{if(!0===t.toggle)return l.html``;if(!0===t.show_icon)return(0,e.renderIcon)(t.stateObj,t,i);if(t.attribute&&[u.LAST_CHANGED,u.LAST_UPDATED].includes(t.attribute))return l.html``:e}return(0,e.entityStateDisplay)(i,t)},e.renderMainEntity=(t,i,n)=>{var r;return void 0===t?null:l.html`
`:e}return(0,e.entityStateDisplay)(i,t)},e.renderMainEntity=(t,i,n)=>{var r;if(void 0===t)return null;const o=n.states[t.entity];return l.html`
+ style="${(0,e.entityStyles)(t.styles,o,n)}"> ${0===(null===(r=i.entities)||void 0===r?void 0:r.length)||i.icon?(0,e.renderIcon)(t.stateObj,i,n,"main-icon"):void 0!==t.show_state&&!1===t.show_state?"":(0,e.renderValue)(t,n)} -
`},e.renderTitle=(t,i,n,r)=>{var o,a;if(!0===i.hide_title)return null;const s=(0,e.clickHandler)(null===(o=null==t?void 0:t.stateObj)||void 0===o?void 0:o.entity_id,i.tap_action,n,r),u=(0,e.dblClickHandler)(null===(a=null==t?void 0:t.stateObj)||void 0===a?void 0:a.entity_id,i.double_tap_action,n,r),c=void 0!==i.tap_action||void 0!==i.double_tap_action;return l.html`
${(0,e.renderMainEntity)(t,i,n)} ${i.title}
`},e.renderInfoEntity=(t,i,n)=>{if(void 0===t||!t.stateObj||(0,d.hideIfEntity)(t,i))return null;const r=(0,e.clickHandler)(t.stateObj.entity_id,t.tap_action,i,n);return l.html`
${(0,e.renderValue)(t,i)}
`},e.clickHandler=(t,e,i,n)=>()=>(0,s.handleClick)(n,i,{entity:t,tap_action:e},!1,!1),e.dblClickHandler=(t,e,i,n)=>()=>(0,s.handleClick)(n,i,{entity:t,double_tap_action:e},!1,!0),e.holdHandler=(t,e,i,n)=>()=>(0,s.handleClick)(n,i,{entity:t,hold_action:e},!0,!1)},846:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.hideIfEntity=e.hideIfRow=e.hideIfCard=e.hideUnavailable=void 0;const n=i(882);e.hideUnavailable=t=>t.hide_unavailable&&(0,n.isUnavailable)(t.stateObj),e.hideIfCard=(t,e)=>{var i,r;if(void 0===t.hide_if)return!1;if(t.hide_if){const o=null===(i=e.states[t.entity])||void 0===i?void 0:i.state,a=null===(r=t.hide_if.conditions)||void 0===r?void 0:r.filter((i=>{let r=o;if(i.entity){const t=e.states[i.entity];r=i.attribute?t.attributes[i.attribute]:t.state}return i.attribute&&!i.entity&&(r=e.states[t.entity].attributes[i.attribute]),(0,n.checkConditionalValue)(i,r)}));return(null==a?void 0:a.length)>0}},e.hideIfRow=(t,e)=>{var i;if(void 0===t.hide_if)return!1;if(t.hide_if){const r=null===(i=t.hide_if.conditions)||void 0===i?void 0:i.filter((t=>{if(t.entity){const i=e.states[t.entity];return(0,n.checkConditionalValue)(t,t.attribute?i.attributes[t.attribute]:i.state)}}));return(null==r?void 0:r.length)>0}},e.hideIfEntity=(t,i)=>{var r;if((0,e.hideUnavailable)(t))return!0;if(void 0===t.hide_if)return!1;if(t.hide_if){const e=t.stateObj.state,o=null===(r=t.hide_if.conditions)||void 0===r?void 0:r.filter((r=>{let o=e;if(r.entity){const t=i.states[r.entity];o=r.attribute?t.attributes[r.attribute]:t.state}return r.attribute&&!r.entity&&(o=t.stateObj.attributes[r.attribute]),(0,n.checkConditionalValue)(r,o)}));return(null==o?void 0:o.length)>0}}},607:function(t,e,i){var n=this&&this.__decorate||function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a};Object.defineProperty(e,"__esModule",{value:!0});const r=i(897),o=i(595),a=i(461),s=i(882),l=i(299),u=i(147);console.info(`%c ROOM-CARD %c ${u.version}`,"color: cyan; background: black; font-weight: bold;","color: darkblue; background: white; font-weight: bold;"),window.customCards=window.customCards||[],window.customCards.push({type:"room-card",name:"Room card",preview:!1,description:"Show multiple entity states, attributes and icons in a single card in Home Assistant's Lovelace UI"});let c=class extends r.LitElement{constructor(){super(...arguments),this.info_entities=[],this.entities=[],this.rows=[],this._refCards=[]}setConfig(t){(0,a.checkConfig)(t),this.config=Object.assign(Object.assign({},t),{entityIds:(0,s.getEntityIds)(t)})}shouldUpdate(t){return(0,s.hasConfigOrEntitiesChanged)(this.config,t)}set hass(t){var e,i,n,r,o,a,l;this._hass=t,t&&this.config&&(this.stateObj=void 0!==this.config.entity?t.states[this.config.entity]:void 0,this.entity=void 0!==this.config.entity?Object.assign(Object.assign({},this.config),{stateObj:this.stateObj}):void 0,this.info_entities=null!==(i=null===(e=this.config.info_entities)||void 0===e?void 0:e.map((e=>(0,s.mapStateObject)(e,t,this.config))))&&void 0!==i?i:[],this.entities=null!==(r=null===(n=this.config.entities)||void 0===n?void 0:n.map((e=>(0,s.mapStateObject)(e,t,this.config))))&&void 0!==r?r:[],this.rows=null!==(a=null===(o=this.config.rows)||void 0===o?void 0:o.map((e=>{var i;return{entities:null===(i=e.entities)||void 0===i?void 0:i.map((e=>(0,s.mapStateObject)(e,t,this.config))),hide_if:e.hide_if,content_alignment:e.content_alignment}})))&&void 0!==a?a:[],this._refCards=null===(l=this.config.cards)||void 0===l?void 0:l.map((e=>(0,s.createCardElement)(e,t))),this.config.hass=t)}static get styles(){return l.style}render(){var t;if(!this._hass||!this.config)return r.html``;try{return r.html` - +
`},e.renderTitle=(t,i,n,r)=>{var o,a;if(!0===i.hide_title)return null;const s=(0,e.clickHandler)(null===(o=null==t?void 0:t.stateObj)||void 0===o?void 0:o.entity_id,i.tap_action,n,r),u=(0,e.dblClickHandler)(null===(a=null==t?void 0:t.stateObj)||void 0===a?void 0:a.entity_id,i.double_tap_action,n,r),d=void 0!==i.tap_action||void 0!==i.double_tap_action,m=(0,c.getTemplateOrAttribute)(i.title,n,null==t?void 0:t.stateObj);return l.html`
${(0,e.renderMainEntity)(t,i,n)} ${m}
`},e.renderInfoEntity=(t,i,n)=>{if(void 0===t||!t.stateObj||(0,d.hideIfEntity)(t,i))return null;const r=(0,e.clickHandler)(t.stateObj.entity_id,t.tap_action,i,n);return l.html`
${(0,e.renderValue)(t,i)}
`},e.clickHandler=(t,e,i,n)=>()=>(0,s.handleClick)(n,i,{entity:t,tap_action:e},!1,!1),e.dblClickHandler=(t,e,i,n)=>()=>(0,s.handleClick)(n,i,{entity:t,double_tap_action:e},!1,!0),e.holdHandler=(t,e,i,n)=>()=>(0,s.handleClick)(n,i,{entity:t,hold_action:e},!0,!1)},846:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.hideIfEntity=e.hideIfRow=e.hideIfCard=e.hideUnavailable=void 0;const n=i(882);e.hideUnavailable=t=>t.hide_unavailable&&(0,n.isUnavailable)(t.stateObj),e.hideIfCard=(t,e)=>{var i,r;if(void 0===t.hide_if)return!1;if(t.hide_if){const o=null===(i=e.states[t.entity])||void 0===i?void 0:i.state,a=null===(r=t.hide_if.conditions)||void 0===r?void 0:r.filter((i=>{let r=o;if(i.entity){const t=e.states[i.entity];r=i.attribute?t.attributes[i.attribute]:t.state}return i.attribute&&!i.entity&&(r=e.states[t.entity].attributes[i.attribute]),(0,n.checkConditionalValue)(i,r)}));return(null==a?void 0:a.length)>0}},e.hideIfRow=(t,e)=>{var i;if(void 0===t.hide_if)return!1;if(t.hide_if){const r=null===(i=t.hide_if.conditions)||void 0===i?void 0:i.filter((t=>{if(t.entity){const i=e.states[t.entity];return(0,n.checkConditionalValue)(t,t.attribute?i.attributes[t.attribute]:i.state)}}));return(null==r?void 0:r.length)>0}},e.hideIfEntity=(t,i)=>{var r;if((0,e.hideUnavailable)(t))return!0;if(void 0===t.hide_if)return!1;if(t.hide_if){const e=t.stateObj.state,o=null===(r=t.hide_if.conditions)||void 0===r?void 0:r.filter((r=>{let o=e;if(r.entity){const t=i.states[r.entity];o=r.attribute?t.attributes[r.attribute]:t.state}return r.attribute&&!r.entity&&(o=t.stateObj.attributes[r.attribute]),(0,n.checkConditionalValue)(r,o)}));return(null==o?void 0:o.length)>0}}},607:function(t,e,i){var n=this&&this.__decorate||function(t,e,i,n){var r,o=arguments.length,a=o<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(t,e,i,n);else for(var s=t.length-1;s>=0;s--)(r=t[s])&&(a=(o<3?r(a):o>3?r(e,i,a):r(e,i))||a);return o>3&&a&&Object.defineProperty(e,i,a),a};Object.defineProperty(e,"__esModule",{value:!0});const r=i(897),o=i(595),a=i(461),s=i(882),l=i(299),u=i(147);console.info(`%c ROOM-CARD %c ${u.version}`,"color: cyan; background: black; font-weight: bold;","color: darkblue; background: white; font-weight: bold;"),window.customCards=window.customCards||[],window.customCards.push({type:"room-card",name:"Room card",preview:!1,description:"Show multiple entity states, attributes and icons in a single card in Home Assistant's Lovelace UI"});let c=class extends r.LitElement{constructor(){super(...arguments),this.info_entities=[],this.entities=[],this.rows=[],this._refCards=[]}setConfig(t){(0,a.checkConfig)(t),this.config=Object.assign(Object.assign({},t),{entityIds:(0,s.getEntityIds)(t)})}shouldUpdate(t){return(0,s.hasConfigOrEntitiesChanged)(this.config,t)}set hass(t){var e,i,n,r,o,a,l;this._hass=t,t&&this.config&&(this.stateObj=void 0!==this.config.entity?t.states[this.config.entity]:void 0,this.entity=void 0!==this.config.entity?Object.assign(Object.assign({},this.config),{stateObj:this.stateObj}):void 0,this.info_entities=null!==(i=null===(e=this.config.info_entities)||void 0===e?void 0:e.map((e=>(0,s.mapStateObject)(e,t,this.config))))&&void 0!==i?i:[],this.entities=null!==(r=null===(n=this.config.entities)||void 0===n?void 0:n.map((e=>(0,s.mapStateObject)(e,t,this.config))))&&void 0!==r?r:[],this.rows=null!==(a=null===(o=this.config.rows)||void 0===o?void 0:o.map((e=>{var i;return{entities:null===(i=e.entities)||void 0===i?void 0:i.map((e=>(0,s.mapStateObject)(e,t,this.config))),hide_if:e.hide_if,content_alignment:e.content_alignment}})))&&void 0!==a?a:[],this._refCards=null===(l=this.config.cards)||void 0===l?void 0:l.map((e=>(0,s.createCardElement)(e,t))),this.config.hass=t)}static get styles(){return l.style}render(){var t;if(!this._hass||!this.config)return r.html``;try{return r.html` +
${(0,a.renderTitle)(this.entity,this.config,this._hass,this)}
${this.info_entities.map((t=>(0,a.renderInfoEntity)(t,this._hass,this)))}
- ${void 0!==this.rows&&this.rows.length>0?(0,a.renderRows)(this.config,this.rows,this._hass,this):(0,a.renderEntitiesRow)(this.config,this.entities,this._hass,this)} + ${void 0!==this.rows&&this.rows.length>0?(0,a.renderRows)(this.rows,this._hass,this):(0,a.renderEntitiesRow)(this.config,this.entities,this._hass,this)} ${this._refCards}
`}catch(t){return r.html`${t.toString()}`}}};n([(0,o.property)()],c.prototype,"_hass",void 0),n([(0,o.property)()],c.prototype,"config",void 0),c=n([(0,o.customElement)("room-card")],c),e.default=c},578:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.computeStateDisplay=e.computeStateDomain=void 0;const n=i(623),r=i(247),o=i(347),a=i(319),s=i(759);e.computeStateDomain=t=>t.entity_id.substr(0,t.entity_id.indexOf(".")),e.computeStateDisplay=(t,i,l,u)=>{const c=void 0!==u?u:i.state;if(c===n.UNKNOWN||c===n.UNAVAILABLE)return t(`state.default.${c}`);if((0,s.isNumericState)(i)){if("monetary"===i.attributes.device_class)try{return(0,s.formatNumber)(c,l,{style:"currency",currency:i.attributes.unit_of_measurement})}catch(t){}return`${(0,s.formatNumber)(c,l)}${i.attributes.unit_of_measurement?" "+i.attributes.unit_of_measurement:""}`}const d=(0,e.computeStateDomain)(i);if("input_datetime"===d){if(void 0===u){let t;return i.attributes.has_date&&i.attributes.has_time?(t=new Date(i.attributes.year,i.attributes.month-1,i.attributes.day,i.attributes.hour,i.attributes.minute),(0,o.formatDateTime)(t,l)):i.attributes.has_date?(t=new Date(i.attributes.year,i.attributes.month-1,i.attributes.day),(0,r.formatDate)(t,l)):i.attributes.has_time?(t=new Date,t.setHours(i.attributes.hour,i.attributes.minute),(0,a.formatTime)(t,l)):i.state}try{const t=u.split(" ");if(2===t.length)return(0,o.formatDateTime)(new Date(t.join("T")),l);if(1===t.length){if(u.includes("-"))return(0,r.formatDate)(new Date(`${u}T00:00`),l);if(u.includes(":")){const t=new Date;return(0,a.formatTime)(new Date(`${t.toISOString().split("T")[0]}T${u}`),l)}}return u}catch(t){return u}}return"humidifier"===d&&"on"===c&&i.attributes.humidity?`${i.attributes.humidity} %`:"counter"===d||"number"===d||"input_number"===d?(0,s.formatNumber)(c,l):"button"===d||"sensor"===d&&"timestamp"===i.attributes.device_class?(0,o.formatDateTime)(new Date(c),l):i.attributes.device_class&&t(`component.${d}.state.${i.attributes.device_class}.${c}`)||t(`component.${d}.state._.${c}`)||c}},623:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.TimeFormat=e.NumberFormat=e.SECONDARY_INFO_VALUES=e.TIMESTAMP_FORMATS=e.LAST_UPDATED=e.LAST_CHANGED=e.UNAVAILABLE_STATES=e.UNKNOWN=e.UNAVAILABLE=void 0,e.UNAVAILABLE="unavailable",e.UNKNOWN="unknown",e.UNAVAILABLE_STATES=[e.UNAVAILABLE,e.UNKNOWN],e.LAST_CHANGED="last-changed",e.LAST_UPDATED="last-updated",e.TIMESTAMP_FORMATS=["relative","total","date","time","datetime"],e.SECONDARY_INFO_VALUES=["entity-id","last-changed","last-updated","last-triggered","position","tilt-position","brightness"],e.NumberFormat={language:"language",system:"system",comma_decimal:"comma_decimal",decimal_comma:"decimal_comma",space_comma:"space_comma",none:"none"},e.TimeFormat={language:"language",system:"system",am_pm:"12",twenty_four:"24"}},247:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatDate=void 0,e.formatDate=(t,e)=>new Intl.DateTimeFormat(e.language,{year:"numeric",month:"long",day:"numeric"}).format(t)},347:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatDateTime=void 0;const n=i(269);e.formatDateTime=(t,e)=>new Intl.DateTimeFormat(e.language,{year:"numeric",month:"long",day:"numeric",hour:(0,n.useAmPm)(e)?"numeric":"2-digit",minute:"2-digit",hour12:(0,n.useAmPm)(e)}).format(t)},759:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatNumber=e.numberFormatToLocale=e.isNumericState=e.round=void 0;const n=i(623);e.round=(t,e=2)=>Math.round(t*Math.pow(10,e))/Math.pow(10,e),e.isNumericState=t=>!!t.attributes.unit_of_measurement||!!t.attributes.state_class,e.numberFormatToLocale=t=>{switch(t.number_format){case n.NumberFormat.comma_decimal:return["en-US","en"];case n.NumberFormat.decimal_comma:return["de","es","it"];case n.NumberFormat.space_comma:return["fr","sv","cs"];case n.NumberFormat.system:return;default:return t.language}},e.formatNumber=(t,i,o)=>{const a=i?(0,e.numberFormatToLocale)(i):void 0;if((null==i?void 0:i.number_format)!==n.NumberFormat.none&&!Number.isNaN(Number(t))&&Intl)try{return new Intl.NumberFormat(a,r(t,o)).format(Number(t))}catch(e){return console.error(e),new Intl.NumberFormat(void 0,r(t,o)).format(Number(t))}return"string"==typeof t?t:`${(0,e.round)(t,null==o?void 0:o.maximumFractionDigits).toString()}${"currency"===(null==o?void 0:o.style)?` ${o.currency}`:""}`};const r=(t,e)=>Object.assign({maximumFractionDigits:2},e)},319:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.formatTime=void 0;const n=i(269);e.formatTime=(t,e)=>new Intl.DateTimeFormat(e.language,{hour:"numeric",minute:"2-digit",hour12:(0,n.useAmPm)(e)}).format(t)},230:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.secondsToDuration=void 0;const i=t=>t<10?`0${t}`:t;e.secondsToDuration=function(t){const e=Math.floor(t/3600),n=Math.floor(t%3600/60),r=Math.floor(t%3600%60);return e>0?`${e}:${i(n)}:${i(r)}`:n>0?`${n}:${i(r)}`:r>0?""+r:null}},269:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.useAmPm=void 0;const n=i(623);e.useAmPm=t=>{if(t.time_format===n.TimeFormat.language||t.time_format===n.TimeFormat.system){const e=t.time_format===n.TimeFormat.language?t.language:void 0,i=(new Date).toLocaleString(e);return i.includes("AM")||i.includes("PM")}return t.time_format===n.TimeFormat.am_pm}},299:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.style=void 0;const n=i(897);e.style=n.css` @@ -121,4 +121,4 @@ .content-right { justify-content: right; } -`},704:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.mapTemplate=e.templateStyling=void 0;const n=i(882);e.templateStyling=(t,e,i)=>{var r;const o=e.icon;return void 0!==(null===(r=null==o?void 0:o.template)||void 0===r?void 0:r.styles)?(0,n.evalTemplate)(i,t,o.template.styles):null},e.mapTemplate=(t,e)=>{if(void 0!==t&&t.template){const i=e.templates.filter((e=>e.name===t.template));if(i.length>0){const e=i[0];return Object.assign(Object.assign({stateObj:t.stateObj},t),e.template)}}return t}},882:function(t,e,i){Object.defineProperty(e,"__esModule",{value:!0}),e.renderClasses=e.evalTemplate=e.createCardElement=e.mapStateObject=e.checkConditionalValue=e.hasConfigOrEntitiesChanged=e.getEntity=e.getEntityIds=e.getValue=e.isUnavailable=e.isObject=void 0;const n=i(197),r=i(897),o=i(623),a=i(704),s=i(846);e.isObject=t=>"object"==typeof t&&!Array.isArray(t)&&!!t,e.isUnavailable=t=>!t||o.UNAVAILABLE_STATES.includes(t.state),e.getValue=t=>{if(t.attribute&&void 0===t.stateObj.attributes[t.attribute])throw new Error(`Entity: '${t.entity}' has no attribute named '${t.attribute}'`);return t.attribute?t.stateObj.attributes[t.attribute]:t.stateObj.state},e.getEntityIds=t=>{var i,n,r,o;return[t.entity].concat(null===(i=t.entities)||void 0===i?void 0:i.map((t=>(0,e.getEntity)(t)))).concat(null===(n=t.info_entities)||void 0===n?void 0:n.map((t=>(0,e.getEntity)(t)))).concat(null===(r=t.rows)||void 0===r?void 0:r.flatMap((t=>t.entities)).map((t=>(0,e.getEntity)(t)))).concat(null===(o=t.cards)||void 0===o?void 0:o.map((t=>(0,e.getEntity)(t.entity)))).filter((t=>t))},e.getEntity=t=>void 0===t?null:"string"==typeof t?t:t.entity,e.hasConfigOrEntitiesChanged=(t,e)=>{if(e.has("config"))return!0;const i=e.get("_hass");return!!i&&t.entityIds.some((e=>i.states[e]!==t.hass.states[e]))},e.checkConditionalValue=(t,e)=>{const i="boolean"==typeof t.value?String(t.value):t.value;return"equals"==t.condition&&e==i||"not_equals"==t.condition&&e!=i||"above"==t.condition&&e>i||"below"==t.condition&&e{let n="string"==typeof t?{entity:t}:t;return n=(0,a.mapTemplate)(n,i),Object.assign(Object.assign({},n),{stateObj:e.states[n.entity]})},e.createCardElement=(t,e)=>{if((0,s.hideIfCard)(t,e)||t.show_states&&!t.show_states.includes(e.states[t.entity].state))return;let i=t.type;i=i.startsWith("divider")?"hui-divider-row":i.startsWith("custom:")?i.substr("custom:".length):`hui-${i}-card`;const r=(0,n.createThing)(t);return r.hass=e,r.style.boxShadow="none",r.style.borderRadius="0",r},e.evalTemplate=(t,e,i)=>{try{return new Function("states","entity","user","hass","html",`'use strict'; ${i}`).call(this,null==t?void 0:t.states,e,null==t?void 0:t.user,t,r.html)}catch(t){const e=i.length<=100?i.trim():`${i.trim().substring(0,98)}...`;throw t.message=`${t.name}: ${t.message} in '${e}'`,t.name="RoomCardJSTemplateError",t}},e.renderClasses=(t,e)=>`entities-row ${t.content_alignment?`content-${t.content_alignment}`:"content-left"}${void 0!==e?` ${e}`:""}`},595:(t,e,i)=>{i.r(e),i.d(e,{customElement:()=>n,eventOptions:()=>l,property:()=>o,query:()=>u,queryAll:()=>c,queryAssignedElements:()=>f,queryAssignedNodes:()=>p,queryAsync:()=>d,state:()=>a});const n=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){customElements.define(t,e)}}})(t,e),r=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}};function o(t){return(e,i)=>void 0!==i?((t,e,i)=>{e.constructor.createProperty(i,t)})(t,e,i):r(t,e)}function a(t){return o({...t,state:!0})}const s=({finisher:t,descriptor:e})=>(i,n)=>{var r;if(void 0===n){const n=null!==(r=i.originalKey)&&void 0!==r?r:i.key,o=null!=e?{kind:"method",placement:"prototype",key:n,descriptor:e(i.key)}:{...i,key:n};return null!=t&&(o.finisher=function(e){t(e,n)}),o}{const r=i.constructor;void 0!==e&&Object.defineProperty(i,n,e(n)),null==t||t(r,n)}};function l(t){return s({finisher:(e,i)=>{Object.assign(e.prototype[i],t)}})}function u(t,e){return s({descriptor:i=>{const n={get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof i?Symbol():"__"+i;n.get=function(){var i,n;return void 0===this[e]&&(this[e]=null!==(n=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(t))&&void 0!==n?n:null),this[e]}}return n}})}function c(t){return s({descriptor:e=>({get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelectorAll(t))&&void 0!==i?i:[]},enumerable:!0,configurable:!0})})}function d(t){return s({descriptor:e=>({async get(){var e;return await this.updateComplete,null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t)},enumerable:!0,configurable:!0})})}var m;const h=null!=(null===(m=window.HTMLSlotElement)||void 0===m?void 0:m.prototype.assignedElements)?(t,e)=>t.assignedElements(e):(t,e)=>t.assignedNodes(e).filter((t=>t.nodeType===Node.ELEMENT_NODE));function f(t){const{slot:e,selector:i}=null!=t?t:{};return s({descriptor:n=>({get(){var n;const r="slot"+(e?`[name=${e}]`:":not([name])"),o=null===(n=this.renderRoot)||void 0===n?void 0:n.querySelector(r),a=null!=o?h(o,t):[];return i?a.filter((t=>t.matches(i))):a},enumerable:!0,configurable:!0})})}function p(t,e,i){let n,r=t;return"object"==typeof t?(r=t.slot,n=t):n={flatten:e},i?f({slot:r,flatten:e,selector:i}):s({descriptor:t=>({get(){var t,e;const i="slot"+(r?`[name=${r}]`:":not([name])"),o=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(i);return null!==(e=null==o?void 0:o.assignedNodes(n))&&void 0!==e?e:[]},enumerable:!0,configurable:!0})})}},897:(t,e,i)=>{i.r(e),i.d(e,{CSSResult:()=>s,LitElement:()=>ct,ReactiveElement:()=>b,UpdatingElement:()=>ut,_$LE:()=>mt,_$LH:()=>ot,adoptStyles:()=>c,css:()=>u,defaultConverter:()=>y,getCompatibleStyle:()=>d,html:()=>L,noChange:()=>z,notEqual:()=>g,nothing:()=>q,render:()=>B,supportsAdoptingStyleSheets:()=>r,svg:()=>V,unsafeCSS:()=>l});const n=window,r=n.ShadowRoot&&(void 0===n.ShadyCSS||n.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,o=Symbol(),a=new WeakMap;class s{constructor(t,e,i){if(this._$cssResult$=!0,i!==o)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(r&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=a.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&a.set(e,t))}return t}toString(){return this.cssText}}const l=t=>new s("string"==typeof t?t:t+"",void 0,o),u=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,n)=>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.")})(i)+t[n+1]),t[0]);return new s(i,t,o)},c=(t,e)=>{r?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),r=n.litNonce;void 0!==r&&i.setAttribute("nonce",r),i.textContent=e.cssText,t.appendChild(i)}))},d=r?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return l(e)})(t):t;var m;const h=window,f=h.trustedTypes,p=f?f.emptyScript:"",v=h.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?p:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},g=(t,e)=>e!==t&&(e==e||t==t),_={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:g};class b extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(t){var e;null!==(e=this.h)&&void 0!==e||(this.h=[]),this.h.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const n=this._$Ep(i,e);void 0!==n&&(this._$Ev.set(n,i),t.push(n))})),t}static createProperty(t,e=_){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,n=this.getPropertyDescriptor(t,i,e);void 0!==n&&Object.defineProperty(this.prototype,t,n)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(n){const r=this[t];this[e]=n,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||_}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._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(d(t))}else void 0!==t&&e.push(d(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return c(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||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._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=_){var n;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const o=(void 0!==(null===(n=i.converter)||void 0===n?void 0:n.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==o?this.removeAttribute(r):this.setAttribute(r,o),this._$El=null}}_$AK(t,e){var i;const n=this.constructor,r=n._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=n.getPropertyOptions(r),o="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=r,this[r]=o.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let n=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||g)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):n=!1),!this.isUpdatePending&&n&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}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._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||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)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}var w;b.finalized=!0,b.elementProperties=new Map,b.elementStyles=[],b.shadowRootOptions={mode:"open"},null==v||v({ReactiveElement:b}),(null!==(m=h.reactiveElementVersions)&&void 0!==m?m:h.reactiveElementVersions=[]).push("1.4.1");const $=window,A=$.trustedTypes,S=A?A.createPolicy("lit-html",{createHTML:t=>t}):void 0,E=`lit$${(Math.random()+"").slice(9)}$`,O="?"+E,T=`<${O}>`,k=document,N=(t="")=>k.createComment(t),C=t=>null===t||"object"!=typeof t&&"function"!=typeof t,D=Array.isArray,j=t=>D(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),x=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,I=/-->/g,M=/>/g,P=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),U=/'/g,F=/"/g,R=/^(?:script|style|textarea|title)$/i,H=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),L=H(1),V=H(2),z=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),W=new WeakMap,B=(t,e,i)=>{var n,r;const o=null!==(n=null==i?void 0:i.renderBefore)&&void 0!==n?n:e;let a=o._$litPart$;if(void 0===a){const t=null!==(r=null==i?void 0:i.renderBefore)&&void 0!==r?r:null;o._$litPart$=a=new Q(e.insertBefore(N(),t),t,void 0,null!=i?i:{})}return a._$AI(t),a},K=k.createTreeWalker(k,129,null,!1),Y=(t,e)=>{const i=t.length-1,n=[];let r,o=2===e?"":"",a=x;for(let e=0;e"===l[0]?(a=null!=r?r:x,u=-1):void 0===l[1]?u=-2:(u=a.lastIndex-l[2].length,s=l[1],a=void 0===l[3]?P:'"'===l[3]?F:U):a===F||a===U?a=P:a===I||a===M?a=x:(a=P,r=void 0);const d=a===P&&t[e+1].startsWith("/>")?" ":"";o+=a===x?i+T:u>=0?(n.push(s),i.slice(0,u)+"$lit$"+i.slice(u)+E+d):i+E+(-2===u?(n.push(void 0),e):d)}const s=o+(t[i]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==S?S.createHTML(s):s,n]};class G{constructor({strings:t,_$litType$:e},i){let n;this.parts=[];let r=0,o=0;const a=t.length-1,s=this.parts,[l,u]=Y(t,e);if(this.el=G.createElement(l,i),K.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(n=K.nextNode())&&s.length0){n.textContent=A?A.emptyScript:"";for(let i=0;i2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,n){const r=this.strings;let o=!1;if(void 0===r)t=J(this,t,e,0),o=!C(t)||t!==this._$AH&&t!==z,o&&(this._$AH=t);else{const n=t;let a,s;for(t=r[0],a=0;a{t._$AK(e,i)},_$AL:t=>t._$AL};(null!==(lt=globalThis.litElementVersions)&&void 0!==lt?lt:globalThis.litElementVersions=[]).push("3.2.2")},147:t=>{t.exports=JSON.parse('{"name":"room-card","version":"1.06.40","description":"Show entities in Home Assistant\'s Lovelace UI","keywords":["home-assistant","homeassistant","lovelace","custom-cards","multiple","entity","row"],"module":"room-card.js","license":"MIT","dependencies":{"babel-jest":"^29.0.3","custom-card-helpers":"^1.8.0","jest-environment-jsdom":"^29.0.3","jest-ts-auto-mock":"^2.1.0","lit":"^2.0.2","ts-auto-mock":"^3.6.2","ttypescript":"^1.5.13","yarn":"^1.22.18"},"devDependencies":{"@babel/core":"^7.19.1","@babel/plugin-transform-runtime":"^7.19.1","@babel/preset-env":"^7.19.1","@types/jest":"^29.0.3","@typescript-eslint/eslint-plugin":"^5.38.0","@typescript-eslint/parser":"^5.38.0","babel-loader":"^8.2.3","compression-webpack-plugin":"^10.0.0","eslint":"^8.24.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^4.0.0","jest":"^29.0.3","prettier":"^2.5.1","ts-jest":"^29.0.2","ts-loader":"^9.4.1","typescript":"^4.8.3","webpack":"^5.65.0","webpack-cli":"^4.9.1"},"scripts":{"lint":"eslint src/**/*.ts","dev":"webpack -c webpack.config.js","build":"yarn lint && webpack -c webpack.config.js","test":"jest","coverage":"jest --coverage","workflow":"jest --coverage --json --outputFile=/home/runner/work/room-card/room-card/jest.results.json"}}')}},e={};function i(n){var r=e[n];if(void 0!==r)return r.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(607)})(); \ No newline at end of file +`},704:(t,e,i)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.getTemplateOrAttribute=e.mapTemplate=e.templateStyling=void 0;const n=i(882);e.templateStyling=(t,e,i)=>{var r;const o=e.icon;return void 0!==(null===(r=null==o?void 0:o.template)||void 0===r?void 0:r.styles)?(0,n.evalTemplate)(i,t,o.template.styles):null},e.mapTemplate=(t,e)=>{if(void 0!==t&&t.template){const i=e.templates.filter((e=>e.name===t.template));if(i.length>0){const e=i[0];return Object.assign(Object.assign({stateObj:t.stateObj},t),e.template)}}return t},e.getTemplateOrAttribute=(t,e,i)=>t&&"object"==typeof t&&"template"in t?(0,n.evalTemplate)(e,i,t.template):t},882:function(t,e,i){Object.defineProperty(e,"__esModule",{value:!0}),e.renderClasses=e.evalTemplate=e.createCardElement=e.mapStateObject=e.checkConditionalValue=e.hasConfigOrEntitiesChanged=e.getEntity=e.getEntityIds=e.getValue=e.isUnavailable=e.isObject=void 0;const n=i(197),r=i(897),o=i(623),a=i(704),s=i(846);e.isObject=t=>"object"==typeof t&&!Array.isArray(t)&&!!t,e.isUnavailable=t=>!t||o.UNAVAILABLE_STATES.includes(t.state),e.getValue=t=>{if(t.attribute&&void 0===t.stateObj.attributes[t.attribute])throw new Error(`Entity: '${t.entity}' has no attribute named '${t.attribute}'`);return t.attribute?t.stateObj.attributes[t.attribute]:t.stateObj.state},e.getEntityIds=t=>{var i,n,r,o;return[t.entity].concat(null===(i=t.entities)||void 0===i?void 0:i.map((t=>(0,e.getEntity)(t)))).concat(null===(n=t.info_entities)||void 0===n?void 0:n.map((t=>(0,e.getEntity)(t)))).concat(null===(r=t.rows)||void 0===r?void 0:r.flatMap((t=>t.entities)).map((t=>(0,e.getEntity)(t)))).concat(null===(o=t.cards)||void 0===o?void 0:o.map((t=>(0,e.getEntity)(t.entity)))).filter((t=>t))},e.getEntity=t=>void 0===t?null:"string"==typeof t?t:t.entity,e.hasConfigOrEntitiesChanged=(t,e)=>{if(e.has("config"))return!0;const i=e.get("_hass");return!!i&&t.entityIds.some((e=>i.states[e]!==t.hass.states[e]))},e.checkConditionalValue=(t,e)=>{const i="boolean"==typeof t.value?String(t.value):t.value;return"equals"==t.condition&&e==i||"not_equals"==t.condition&&e!=i||"above"==t.condition&&e>i||"below"==t.condition&&e{let n="string"==typeof t?{entity:t}:t;return n=(0,a.mapTemplate)(n,i),Object.assign(Object.assign({},n),{stateObj:e.states[n.entity]})},e.createCardElement=(t,e)=>{if((0,s.hideIfCard)(t,e)||t.show_states&&!t.show_states.includes(e.states[t.entity].state))return;let i=t.type;i=i.startsWith("divider")?"hui-divider-row":i.startsWith("custom:")?i.substr("custom:".length):`hui-${i}-card`;const r=(0,n.createThing)(t);return r.hass=e,r.style.boxShadow="none",r.style.borderRadius="0",r},e.evalTemplate=(t,e,i)=>{try{return new Function("states","entity","user","hass","html",`'use strict'; ${i}`).call(this,null==t?void 0:t.states,e,null==t?void 0:t.user,t,r.html)}catch(t){const e=i.length<=100?i.trim():`${i.trim().substring(0,98)}...`;throw t.message=`${t.name}: ${t.message} in '${e}'`,t.name="RoomCardJSTemplateError",t}},e.renderClasses=(t,e)=>`entities-row ${t.content_alignment?`content-${t.content_alignment}`:"content-left"}${void 0!==e?` ${e}`:""}`},595:(t,e,i)=>{i.r(e),i.d(e,{customElement:()=>n,eventOptions:()=>l,property:()=>o,query:()=>u,queryAll:()=>c,queryAssignedElements:()=>p,queryAssignedNodes:()=>f,queryAsync:()=>d,state:()=>a});const n=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:i,elements:n}=e;return{kind:i,elements:n,finisher(e){customElements.define(t,e)}}})(t,e),r=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(i){i.createProperty(e.key,t)}}:{kind:"field",key:Symbol(),placement:"own",descriptor:{},originalKey:e.key,initializer(){"function"==typeof e.initializer&&(this[e.key]=e.initializer.call(this))},finisher(i){i.createProperty(e.key,t)}};function o(t){return(e,i)=>void 0!==i?((t,e,i)=>{e.constructor.createProperty(i,t)})(t,e,i):r(t,e)}function a(t){return o({...t,state:!0})}const s=({finisher:t,descriptor:e})=>(i,n)=>{var r;if(void 0===n){const n=null!==(r=i.originalKey)&&void 0!==r?r:i.key,o=null!=e?{kind:"method",placement:"prototype",key:n,descriptor:e(i.key)}:{...i,key:n};return null!=t&&(o.finisher=function(e){t(e,n)}),o}{const r=i.constructor;void 0!==e&&Object.defineProperty(i,n,e(n)),null==t||t(r,n)}};function l(t){return s({finisher:(e,i)=>{Object.assign(e.prototype[i],t)}})}function u(t,e){return s({descriptor:i=>{const n={get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==i?i:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof i?Symbol():"__"+i;n.get=function(){var i,n;return void 0===this[e]&&(this[e]=null!==(n=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(t))&&void 0!==n?n:null),this[e]}}return n}})}function c(t){return s({descriptor:e=>({get(){var e,i;return null!==(i=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelectorAll(t))&&void 0!==i?i:[]},enumerable:!0,configurable:!0})})}function d(t){return s({descriptor:e=>({async get(){var e;return await this.updateComplete,null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t)},enumerable:!0,configurable:!0})})}var m;const h=null!=(null===(m=window.HTMLSlotElement)||void 0===m?void 0:m.prototype.assignedElements)?(t,e)=>t.assignedElements(e):(t,e)=>t.assignedNodes(e).filter((t=>t.nodeType===Node.ELEMENT_NODE));function p(t){const{slot:e,selector:i}=null!=t?t:{};return s({descriptor:n=>({get(){var n;const r="slot"+(e?`[name=${e}]`:":not([name])"),o=null===(n=this.renderRoot)||void 0===n?void 0:n.querySelector(r),a=null!=o?h(o,t):[];return i?a.filter((t=>t.matches(i))):a},enumerable:!0,configurable:!0})})}function f(t,e,i){let n,r=t;return"object"==typeof t?(r=t.slot,n=t):n={flatten:e},i?p({slot:r,flatten:e,selector:i}):s({descriptor:t=>({get(){var t,e;const i="slot"+(r?`[name=${r}]`:":not([name])"),o=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(i);return null!==(e=null==o?void 0:o.assignedNodes(n))&&void 0!==e?e:[]},enumerable:!0,configurable:!0})})}},897:(t,e,i)=>{i.r(e),i.d(e,{CSSResult:()=>s,LitElement:()=>ct,ReactiveElement:()=>b,UpdatingElement:()=>ut,_$LE:()=>mt,_$LH:()=>ot,adoptStyles:()=>c,css:()=>u,defaultConverter:()=>y,getCompatibleStyle:()=>d,html:()=>L,noChange:()=>z,notEqual:()=>g,nothing:()=>q,render:()=>B,supportsAdoptingStyleSheets:()=>r,svg:()=>V,unsafeCSS:()=>l});const n=window,r=n.ShadowRoot&&(void 0===n.ShadyCSS||n.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,o=Symbol(),a=new WeakMap;class s{constructor(t,e,i){if(this._$cssResult$=!0,i!==o)throw Error("CSSResult is not constructable. Use `unsafeCSS` or `css` instead.");this.cssText=t,this.t=e}get styleSheet(){let t=this.o;const e=this.t;if(r&&void 0===t){const i=void 0!==e&&1===e.length;i&&(t=a.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),i&&a.set(e,t))}return t}toString(){return this.cssText}}const l=t=>new s("string"==typeof t?t:t+"",void 0,o),u=(t,...e)=>{const i=1===t.length?t[0]:e.reduce(((e,i,n)=>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.")})(i)+t[n+1]),t[0]);return new s(i,t,o)},c=(t,e)=>{r?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const i=document.createElement("style"),r=n.litNonce;void 0!==r&&i.setAttribute("nonce",r),i.textContent=e.cssText,t.appendChild(i)}))},d=r?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const i of t.cssRules)e+=i.cssText;return l(e)})(t):t;var m;const h=window,p=h.trustedTypes,f=p?p.emptyScript:"",v=h.reactiveElementPolyfillSupport,y={toAttribute(t,e){switch(e){case Boolean:t=t?f:null;break;case Object:case Array:t=null==t?t:JSON.stringify(t)}return t},fromAttribute(t,e){let i=t;switch(e){case Boolean:i=null!==t;break;case Number:i=null===t?null:Number(t);break;case Object:case Array:try{i=JSON.parse(t)}catch(t){i=null}}return i}},g=(t,e)=>e!==t&&(e==e||t==t),_={attribute:!0,type:String,converter:y,reflect:!1,hasChanged:g};class b extends HTMLElement{constructor(){super(),this._$Ei=new Map,this.isUpdatePending=!1,this.hasUpdated=!1,this._$El=null,this.u()}static addInitializer(t){var e;null!==(e=this.h)&&void 0!==e||(this.h=[]),this.h.push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,i)=>{const n=this._$Ep(i,e);void 0!==n&&(this._$Ev.set(n,i),t.push(n))})),t}static createProperty(t,e=_){if(e.state&&(e.attribute=!1),this.finalize(),this.elementProperties.set(t,e),!e.noAccessor&&!this.prototype.hasOwnProperty(t)){const i="symbol"==typeof t?Symbol():"__"+t,n=this.getPropertyDescriptor(t,i,e);void 0!==n&&Object.defineProperty(this.prototype,t,n)}}static getPropertyDescriptor(t,e,i){return{get(){return this[e]},set(n){const r=this[t];this[e]=n,this.requestUpdate(t,r,i)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||_}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._$Ev=new Map,this.hasOwnProperty("properties")){const t=this.properties,e=[...Object.getOwnPropertyNames(t),...Object.getOwnPropertySymbols(t)];for(const i of e)this.createProperty(i,t[i])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const i=new Set(t.flat(1/0).reverse());for(const t of i)e.unshift(d(t))}else void 0!==t&&e.push(d(t));return e}static _$Ep(t,e){const i=e.attribute;return!1===i?void 0:"string"==typeof i?i:"string"==typeof t?t.toLowerCase():void 0}u(){var t;this._$E_=new Promise((t=>this.enableUpdating=t)),this._$AL=new Map,this._$Eg(),this.requestUpdate(),null===(t=this.constructor.h)||void 0===t||t.forEach((t=>t(this)))}addController(t){var e,i;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(i=t.hostConnected)||void 0===i||i.call(t))}removeController(t){var e;null===(e=this._$ES)||void 0===e||e.splice(this._$ES.indexOf(t)>>>0,1)}_$Eg(){this.constructor.elementProperties.forEach(((t,e)=>{this.hasOwnProperty(e)&&(this._$Ei.set(e,this[e]),delete this[e])}))}createRenderRoot(){var t;const e=null!==(t=this.shadowRoot)&&void 0!==t?t:this.attachShadow(this.constructor.shadowRootOptions);return c(e,this.constructor.elementStyles),e}connectedCallback(){var t;void 0===this.renderRoot&&(this.renderRoot=this.createRenderRoot()),this.enableUpdating(!0),null===(t=this._$ES)||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._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostDisconnected)||void 0===e?void 0:e.call(t)}))}attributeChangedCallback(t,e,i){this._$AK(t,i)}_$EO(t,e,i=_){var n;const r=this.constructor._$Ep(t,i);if(void 0!==r&&!0===i.reflect){const o=(void 0!==(null===(n=i.converter)||void 0===n?void 0:n.toAttribute)?i.converter:y).toAttribute(e,i.type);this._$El=t,null==o?this.removeAttribute(r):this.setAttribute(r,o),this._$El=null}}_$AK(t,e){var i;const n=this.constructor,r=n._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=n.getPropertyOptions(r),o="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(i=t.converter)||void 0===i?void 0:i.fromAttribute)?t.converter:y;this._$El=r,this[r]=o.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,i){let n=!0;void 0!==t&&(((i=i||this.constructor.getPropertyOptions(t)).hasChanged||g)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===i.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,i))):n=!1),!this.isUpdatePending&&n&&(this._$E_=this._$Ej())}async _$Ej(){this.isUpdatePending=!0;try{await this._$E_}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._$Ei&&(this._$Ei.forEach(((t,e)=>this[e]=t)),this._$Ei=void 0);let e=!1;const i=this._$AL;try{e=this.shouldUpdate(i),e?(this.willUpdate(i),null===(t=this._$ES)||void 0===t||t.forEach((t=>{var e;return null===(e=t.hostUpdate)||void 0===e?void 0:e.call(t)})),this.update(i)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(i)}willUpdate(t){}_$AE(t){var e;null===(e=this._$ES)||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)}_$Ek(){this._$AL=new Map,this.isUpdatePending=!1}get updateComplete(){return this.getUpdateComplete()}getUpdateComplete(){return this._$E_}shouldUpdate(t){return!0}update(t){void 0!==this._$EC&&(this._$EC.forEach(((t,e)=>this._$EO(e,this[e],t))),this._$EC=void 0),this._$Ek()}updated(t){}firstUpdated(t){}}var w;b.finalized=!0,b.elementProperties=new Map,b.elementStyles=[],b.shadowRootOptions={mode:"open"},null==v||v({ReactiveElement:b}),(null!==(m=h.reactiveElementVersions)&&void 0!==m?m:h.reactiveElementVersions=[]).push("1.4.1");const $=window,A=$.trustedTypes,S=A?A.createPolicy("lit-html",{createHTML:t=>t}):void 0,E=`lit$${(Math.random()+"").slice(9)}$`,O="?"+E,T=`<${O}>`,k=document,N=(t="")=>k.createComment(t),C=t=>null===t||"object"!=typeof t&&"function"!=typeof t,D=Array.isArray,j=t=>D(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),x=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,I=/-->/g,M=/>/g,P=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),U=/'/g,F=/"/g,R=/^(?:script|style|textarea|title)$/i,H=t=>(e,...i)=>({_$litType$:t,strings:e,values:i}),L=H(1),V=H(2),z=Symbol.for("lit-noChange"),q=Symbol.for("lit-nothing"),W=new WeakMap,B=(t,e,i)=>{var n,r;const o=null!==(n=null==i?void 0:i.renderBefore)&&void 0!==n?n:e;let a=o._$litPart$;if(void 0===a){const t=null!==(r=null==i?void 0:i.renderBefore)&&void 0!==r?r:null;o._$litPart$=a=new Q(e.insertBefore(N(),t),t,void 0,null!=i?i:{})}return a._$AI(t),a},K=k.createTreeWalker(k,129,null,!1),Y=(t,e)=>{const i=t.length-1,n=[];let r,o=2===e?"":"",a=x;for(let e=0;e"===l[0]?(a=null!=r?r:x,u=-1):void 0===l[1]?u=-2:(u=a.lastIndex-l[2].length,s=l[1],a=void 0===l[3]?P:'"'===l[3]?F:U):a===F||a===U?a=P:a===I||a===M?a=x:(a=P,r=void 0);const d=a===P&&t[e+1].startsWith("/>")?" ":"";o+=a===x?i+T:u>=0?(n.push(s),i.slice(0,u)+"$lit$"+i.slice(u)+E+d):i+E+(-2===u?(n.push(void 0),e):d)}const s=o+(t[i]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==S?S.createHTML(s):s,n]};class G{constructor({strings:t,_$litType$:e},i){let n;this.parts=[];let r=0,o=0;const a=t.length-1,s=this.parts,[l,u]=Y(t,e);if(this.el=G.createElement(l,i),K.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(n=K.nextNode())&&s.length0){n.textContent=A?A.emptyScript:"";for(let i=0;i2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=q}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,i,n){const r=this.strings;let o=!1;if(void 0===r)t=J(this,t,e,0),o=!C(t)||t!==this._$AH&&t!==z,o&&(this._$AH=t);else{const n=t;let a,s;for(t=r[0],a=0;a{t._$AK(e,i)},_$AL:t=>t._$AL};(null!==(lt=globalThis.litElementVersions)&&void 0!==lt?lt:globalThis.litElementVersions=[]).push("3.2.2")},147:t=>{t.exports=JSON.parse('{"name":"room-card","version":"1.07.00","description":"Show entities in Home Assistant\'s Lovelace UI","keywords":["home-assistant","homeassistant","lovelace","custom-cards","multiple","entity","row"],"module":"room-card.js","license":"MIT","dependencies":{"babel-jest":"^29.0.3","custom-card-helpers":"^1.8.0","jest-environment-jsdom":"^29.0.3","jest-ts-auto-mock":"^2.1.0","lit":"^2.0.2","ts-auto-mock":"^3.6.2","ttypescript":"^1.5.13","yarn":"^1.22.18"},"devDependencies":{"@babel/core":"^7.19.1","@babel/plugin-transform-runtime":"^7.19.1","@babel/preset-env":"^7.19.1","@types/jest":"^29.0.3","@typescript-eslint/eslint-plugin":"^5.38.0","@typescript-eslint/parser":"^5.38.0","babel-loader":"^8.2.3","compression-webpack-plugin":"^10.0.0","eslint":"^8.24.0","eslint-config-prettier":"^8.3.0","eslint-plugin-prettier":"^4.0.0","jest":"^29.0.3","prettier":"^2.5.1","ts-jest":"^29.0.2","ts-loader":"^9.4.1","typescript":"^4.8.3","webpack":"^5.65.0","webpack-cli":"^4.9.1"},"scripts":{"lint":"eslint src/**/*.ts","dev":"webpack -c webpack.config.js","build":"yarn lint && webpack -c webpack.config.js","test":"jest","coverage":"jest --coverage","workflow":"jest --coverage --json --outputFile=/home/runner/work/room-card/room-card/jest.results.json"}}')}},e={};function i(n){var r=e[n];if(void 0!==r)return r.exports;var o=e[n]={exports:{}};return t[n].call(o.exports,o,o.exports,i),o.exports}i.d=(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i(607)})(); \ No newline at end of file diff --git a/room-card.js.gz b/room-card.js.gz index 5f09a97..db7e400 100644 Binary files a/room-card.js.gz and b/room-card.js.gz differ diff --git a/src/entity.ts b/src/entity.ts index a147666..eb08724 100644 --- a/src/entity.ts +++ b/src/entity.ts @@ -3,10 +3,10 @@ import { formatNumber } from './lib/format_number'; import { computeStateDisplay, computeStateDomain } from './lib/compute_state_display'; import { checkConditionalValue, evalTemplate, getValue, isObject, isUnavailable, renderClasses } from './util'; import { ActionConfig, handleClick, HomeAssistant } from 'custom-card-helpers'; -import { HomeAssistantEntity, EntityCondition, RoomCardEntity, RoomCardIcon, RoomCardConfig, EntityStyles, RoomCardRow } from './types/room-card-types'; +import { HomeAssistantEntity, EntityCondition, RoomCardEntity, RoomCardIcon, RoomCardConfig, EntityStyles, RoomCardRow, RoomCardAttributeTemplate } from './types/room-card-types'; import { html, HTMLTemplateResult, LitElement } from 'lit'; import { LAST_CHANGED, LAST_UPDATED, TIMESTAMP_FORMATS } from './lib/constants'; -import { templateStyling } from './template'; +import { getTemplateOrAttribute, templateStyling } from './template'; import { hideIfEntity, hideIfRow } from './hide'; export const checkConfig = (config: RoomCardConfig) => { @@ -17,9 +17,11 @@ export const checkConfig = (config: RoomCardConfig) => { export const computeEntity = (entityId: string) => entityId.substr(entityId.indexOf('.') + 1); -export const entityName = (entity: RoomCardEntity) => { +export const entityName = (entity: RoomCardEntity, hass: HomeAssistant) => { + const name = getTemplateOrAttribute(entity.name, hass, entity.stateObj) + return ( - entity.name || + name || (entity.entity ? entity.stateObj.attributes.friendly_name || computeEntity(entity.stateObj.entity_id) : null) || null ); @@ -116,14 +118,23 @@ export const entityStateDisplay = (hass: HomeAssistant, entity: RoomCardEntity) return computeStateDisplay(hass.localize, modifiedStateObj, hass.locale); }; -export const entityStyles = (styles: EntityStyles) => - isObject(styles) - ? Object.keys(styles) - .map((key) => `${key}: ${styles[key]};`) - .join('') - : ''; +export const entityStyles = (styles: EntityStyles | RoomCardAttributeTemplate, stateObj: HomeAssistantEntity, hass: HomeAssistant) => { + if(!styles) { + return ''; + } + + if ('template' in styles) { + const templateDefinition = styles as RoomCardAttributeTemplate; + return evalTemplate(hass, stateObj, templateDefinition.template); + } + + const entityStyles = styles as EntityStyles; + return Object.keys(entityStyles) + .map((key) => `${key}: ${entityStyles[key]};`) + .join(''); +} -export const renderRows = (config: RoomCardConfig, rows: RoomCardRow[], hass: HomeAssistant, element: LitElement) : HTMLTemplateResult => { +export const renderRows = (rows: RoomCardRow[], hass: HomeAssistant, element: LitElement) : HTMLTemplateResult => { const filteredRows = rows.filter(row => { return !hideIfRow(row, hass); }); return html`${filteredRows.map((row) => { @@ -183,9 +194,9 @@ export const renderEntity = (entity: RoomCardEntity, hass: HomeAssistant, elemen } }; - return html`
- ${entity.show_name === undefined || entity.show_name ? html`${entityName(entity)}` : ''} + ${entity.show_name === undefined || entity.show_name ? html`${entityName(entity, hass)}` : ''}
${renderIcon(entity.stateObj, entity, hass)}
${entity.show_state ? html`${entityStateDisplay(hass, entity)}` : ''}
`; @@ -204,7 +215,7 @@ export const renderIcon = (stateObj: HomeAssistantEntity, config: RoomCardEntity .stateObj="${stateObj}" .overrideIcon="${isObject(customIcon) ? (customIcon as EntityCondition).icon : customIcon as string}" .stateColor="${config.state_color}" - style="${customStyling ?? entityStyles(isObject(customIcon) ? (customIcon as EntityCondition).styles : null)}" + style="${customStyling ?? entityStyles(isObject(customIcon) ? (customIcon as EntityCondition).styles : null, hass.states[config.entity], hass)}" >`; } @@ -245,9 +256,12 @@ export const renderMainEntity = (entity: RoomCardEntity | undefined, config: Roo if (entity === undefined) { return null; } + + const stateObj = hass.states[entity.entity]; + return html`
+ style="${entityStyles(entity.styles, stateObj, hass)}"> ${config.entities?.length === 0 || config.icon ? renderIcon(entity.stateObj, config, hass, "main-icon") : entity.show_state !== undefined && entity.show_state === false ? '' : renderValue(entity, hass)} @@ -261,8 +275,9 @@ export const renderTitle = (entity: RoomCardEntity, config: RoomCardConfig, hass const onClick = clickHandler(entity?.stateObj?.entity_id, config.tap_action, hass, element); const onDblClick = dblClickHandler(entity?.stateObj?.entity_id, config.double_tap_action, hass, element); const hasAction = config.tap_action !== undefined || config.double_tap_action !== undefined; + const title = getTemplateOrAttribute(config.title, hass, entity?.stateObj); - return html`
${renderMainEntity(entity, config, hass)} ${config.title}
`; + return html`
${renderMainEntity(entity, config, hass)} ${title}
`; } export const renderInfoEntity = (entity: RoomCardEntity, hass: HomeAssistant, element: LitElement) : HTMLTemplateResult => { @@ -271,7 +286,7 @@ export const renderInfoEntity = (entity: RoomCardEntity, hass: HomeAssistant, el } const onClick = clickHandler(entity.stateObj.entity_id, entity.tap_action, hass, element); - return html`
${renderValue(entity, hass)}
`; + return html`
${renderValue(entity, hass)}
`; } export const clickHandler = (entity: string, actionConfig: ActionConfig, hass: HomeAssistant, element: LitElement) => { diff --git a/src/index.ts b/src/index.ts index 5d8de1f..b40daaa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -78,7 +78,7 @@ export default class RoomCard extends LitElement { try { return html` - +
${renderTitle(this.entity, this.config, this._hass, this)}
@@ -86,7 +86,7 @@ export default class RoomCard extends LitElement {
${this.rows !== undefined && this.rows.length > 0 ? - renderRows(this.config, this.rows, this._hass, this) : + renderRows(this.rows, this._hass, this) : renderEntitiesRow(this.config, this.entities, this._hass, this)} ${this._refCards}
diff --git a/src/lib/format_number.ts b/src/lib/format_number.ts index 40907a2..7b67ca7 100644 --- a/src/lib/format_number.ts +++ b/src/lib/format_number.ts @@ -4,7 +4,7 @@ import { FrontendLocaleData } from 'custom-card-helpers'; import { FormattingOptions, HomeAssistantEntity } from '../types/room-card-types'; import { NumberFormat } from './constants'; -export const round = (value: number, precision = 2) => Math.round(value * 10 ** precision) / 10 ** precision; +export const round = (value?: number, precision = 2) => Math.round(value * 10 ** precision) / 10 ** precision; export const isNumericState = (stateObj: HomeAssistantEntity) => !!stateObj.attributes.unit_of_measurement || !!stateObj.attributes.state_class; diff --git a/src/template.ts b/src/template.ts index 1e29b54..33a654d 100644 --- a/src/template.ts +++ b/src/template.ts @@ -1,8 +1,8 @@ +/* eslint-disable @typescript-eslint/ban-types */ import { HomeAssistant } from "custom-card-helpers"; -import { HomeAssistantEntity, RoomCardConfig, RoomCardEntity, RoomCardIcon } from "./types/room-card-types"; +import { HomeAssistantEntity, RoomCardAttributeTemplate, RoomCardConfig, RoomCardEntity, RoomCardIcon } from "./types/room-card-types"; import { evalTemplate } from "./util"; -// eslint-disable-next-line @typescript-eslint/ban-types export const templateStyling = (stateObj: HomeAssistantEntity, config: RoomCardEntity | RoomCardConfig, hass: HomeAssistant) : Function => { const icon = (config.icon as RoomCardIcon); @@ -20,4 +20,18 @@ export const mapTemplate = (entity: RoomCardEntity, config: RoomCardConfig) => { } return entity; +} + +export const getTemplateOrAttribute = (attribute: string | number | RoomCardAttributeTemplate | boolean, hass: HomeAssistant, stateObj: HomeAssistantEntity) => { + if(!attribute) { + return attribute; + } + + if(typeof attribute == "object") { + if('template' in attribute) { + return evalTemplate(hass, stateObj, (attribute as RoomCardAttributeTemplate).template); + } + } + + return attribute; } \ No newline at end of file diff --git a/src/types/room-card-types.ts b/src/types/room-card-types.ts index 55d4e3a..b53d023 100644 --- a/src/types/room-card-types.ts +++ b/src/types/room-card-types.ts @@ -2,7 +2,7 @@ import { ActionConfig, HomeAssistant, LovelaceCardConfig } from 'custom-card-hel import { HassEntity } from 'home-assistant-js-websocket'; export interface RoomCardEntity { - name?: string; + name?: string | RoomCardAttributeTemplate; entity?: string; tap_action?: ActionConfig; hold_action?: ActionConfig; @@ -18,7 +18,7 @@ export interface RoomCardEntity { stateObj: HomeAssistantEntity; attribute?: string; show_state?: boolean; - styles?: EntityStyles; + styles?: EntityStyles | RoomCardAttributeTemplate; icon?: string | RoomCardIcon; template?: string; } @@ -39,9 +39,8 @@ export interface RoomCardConfig extends LovelaceCardConfig { icon?: string | RoomCardIcon; rows?: RoomCardRow[]; show_icon?: boolean; - title?: string; - name?: string; - styles?: EntityStyles; + title?: string | RoomCardAttributeTemplate; + styles?: EntityStyles | RoomCardAttributeTemplate; templates?: RoomCardTemplateContainer[]; content_alignment?: RoomCardAlignment; } @@ -107,4 +106,8 @@ export interface RoomCardTemplateDefinition { export interface RoomCardLovelaceCardConfig extends LovelaceCardConfig { hide_if?: HideIfConfig; +} + +export interface RoomCardAttributeTemplate { + template: string; } \ No newline at end of file diff --git a/tests/entity/entityIcon.test.ts b/tests/entity/entityIcon.test.ts index b95bd3f..3272ac9 100644 --- a/tests/entity/entityIcon.test.ts +++ b/tests/entity/entityIcon.test.ts @@ -82,27 +82,29 @@ describe('Testing entity file function entityIcon', () => { expect(entityIcon(stateObj, config, hass)).toBe('mdi:on-icon'); }), - test.each` - entity_id - ${'light.test_entity'} - ${'switch.test_entity'} - ${'binary_sensor.test_entity'} - ${'input_boolean.test_entity'} - `('Passing config with icon state_on/state_off should return state_off icon', ({entity_id}) => { - - stateObj.entity_id = entity_id;// 'input_boolean.test_entity'; - stateObj.state = 'off'; - const config: RoomCardConfig = { - entityIds: [], - type: '', - show_icon: true, - icon: { - state_on: 'mdi:on-icon', - state_off: 'mdi:off-icon', - } - }; + + + [ + ['light.test_entity'], + ['switch.test_entity'], + ['binary_sensor.test_entity'], + ['input_boolean.test_entity'] + ].forEach(([entity_id]) => { + test(`Passing config with icon and entity_id ${entity_id} state_on/state_off should return state_off icon`, () => { + stateObj.entity_id = entity_id;// 'input_boolean.test_entity'; + stateObj.state = 'off'; + const config: RoomCardConfig = { + entityIds: [], + type: '', + show_icon: true, + icon: { + state_on: 'mdi:on-icon', + state_off: 'mdi:off-icon', + } + }; - expect(entityIcon(stateObj, config, hass)).toBe('mdi:off-icon'); + expect(entityIcon(stateObj, config, hass)).toBe('mdi:off-icon'); + }) }), test('Passing config with icon iconditions equals should return condition', () => { diff --git a/tests/entity/entityName.test.ts b/tests/entity/entityName.test.ts index 40379af..52f3511 100644 --- a/tests/entity/entityName.test.ts +++ b/tests/entity/entityName.test.ts @@ -3,14 +3,16 @@ import { HassEntity } from 'home-assistant-js-websocket'; import { entityName } from '../../src/entity'; import { RoomCardEntity } from '../../src/types/room-card-types'; import { StubHassEntity } from '../testdata'; +import { HomeAssistant } from 'custom-card-helpers'; describe('Testing entity file function computeEntity', () => { + const hass = createMock(); test('Passing RoomCardEntity with name should return entity name', () => { const entity : RoomCardEntity = { name: 'Test entity', stateObj: StubHassEntity }; - expect(entityName(entity)).toBe(entity.name); + expect(entityName(entity, hass)).toBe(entity.name); }), test('Passing RoomCardEntity with entity should return friendly name', () => { StubHassEntity.attributes.friendly_name = 'Test Entity Friendly' @@ -18,7 +20,7 @@ describe('Testing entity file function computeEntity', () => { entity: 'sensor.test_entity', stateObj: StubHassEntity }; - expect(entityName(entity)).toBe(StubHassEntity.attributes.friendly_name); + expect(entityName(entity, hass)).toBe(StubHassEntity.attributes.friendly_name); }), test('Passing RoomCardEntity with entity should return entity_id', () => { const hassEntity = createMock(); @@ -27,14 +29,34 @@ describe('Testing entity file function computeEntity', () => { entity: 'sensor.test_entity', stateObj: hassEntity }; - expect(entityName(entity)).toBe('test_entity_id'); + expect(entityName(entity, hass)).toBe('test_entity_id'); }), test('Passing RoomCardEntity with no config should return null', () => { const hassEntity = createMock(); const entity : RoomCardEntity = { stateObj: hassEntity }; - expect(entityName(entity)).toBe(null); + expect(entityName(entity, hass)).toBe(null); + }), + + [ + ['off', 'Name off'], + ['on', 'Name on'] + ].forEach(([state, expected]) => { + test(`Passing RoomCardEntity with entity state ${state} and name template should return ${expected}`, ()=>{ + const hassEntity = createMock(); + hassEntity.entity_id = 'sensor.test_entity_id'; + hassEntity.state = state; + const entity : RoomCardEntity = { + entity: 'sensor.test_entity', + stateObj: hassEntity, + name: { + template: "if (entity.state == 'on') return 'Name on'; else return 'Name off'; " + } + }; + + expect(entityName(entity, hass)).toBe(expected); + }) }) }) diff --git a/tests/entity/entityStyles.test.ts b/tests/entity/entityStyles.test.ts index 96d7803..26d76f2 100644 --- a/tests/entity/entityStyles.test.ts +++ b/tests/entity/entityStyles.test.ts @@ -1,12 +1,28 @@ +import { HomeAssistant } from 'custom-card-helpers'; +import { createMock } from 'ts-auto-mock'; import { entityStyles } from '../../src/entity'; -import { EntityStyles } from '../../src/types/room-card-types'; +import { EntityStyles, HomeAssistantEntity, RoomCardAttributeTemplate } from '../../src/types/room-card-types'; describe('Testing entity file function computeEntity', () => { - test('Passing entity_id should return entity name', () => { + const stateObj = createMock(); + const hass = createMock(); + + test('Passing styles object should return style string', () => { const styles: EntityStyles = { color: 'red', height: '100' } - expect(entityStyles(styles)).toBe('color: red;height: 100;'); + expect(entityStyles(styles, stateObj, hass)).toBe('color: red;height: 100;'); + }), + test.each` + state | expected + ${'off'} ${'color: red'} + ${'on'} ${'color: blue'} + `('Passing RoomCardAttributeTemplate should return style string', ({ state, expected }) => { + stateObj.state = state; + const template: RoomCardAttributeTemplate = { + template: "if (entity.state == 'off') return 'color: red'; else return 'color: blue';" + } + expect(entityStyles(template, stateObj, hass)).toBe(expected); }) }) \ No newline at end of file diff --git a/tests/entity/renderTitle.test.ts b/tests/entity/renderTitle.test.ts index b60f98e..cf80ff9 100644 --- a/tests/entity/renderTitle.test.ts +++ b/tests/entity/renderTitle.test.ts @@ -3,6 +3,7 @@ import { LitElement } from "lit"; import { createMock } from "ts-auto-mock"; import { renderTitle } from "../../src/entity"; import { HomeAssistantEntity, RoomCardConfig, RoomCardEntity } from "../../src/types/room-card-types"; +import { mapStateObject } from '../../src/util'; import { getRenderString } from "../utils"; describe('Testing entity file function renderValue', () => { @@ -63,5 +64,33 @@ describe('Testing entity file function renderValue', () => { const htmlResult = getRenderString(result); expect(htmlResult).toMatch('
'); + }), + test.each` + state | expected + ${'off'} ${'Off'} + ${'on'} ${'Test title'} + `('Passing RoomCardEntity, RoomcardConfig, HomeAssistant and LitElement should return expected html', ({ state, expected }) => { + stateObj.attributes['title'] = "Test title"; + stateObj.state = state; + const entity: RoomCardEntity = { + stateObj: stateObj, + show_icon: true, + icon: 'mdi:table' + }; + + const config: RoomCardConfig = { + entity: 'light.test_entity', + entityIds: ['light.test_entity'], + type: '', + tap_action: 'more-info', + title: { + template: "if (entity.state == 'on') return entity.attributes.title; else return 'Off'; " + } + }; + + const result = renderTitle(entity, config, hass, element); + const htmlResult = getRenderString(result); + + expect(htmlResult).toMatch(`
${expected}
`);; }) }); \ No newline at end of file diff --git a/tests/lib/compute_state_display.test.ts b/tests/lib/compute_state_display.test.ts index 791aa09..008c435 100644 --- a/tests/lib/compute_state_display.test.ts +++ b/tests/lib/compute_state_display.test.ts @@ -5,6 +5,9 @@ import { UNAVAILABLE, UNKNOWN } from '../../src/lib/constants'; import { HomeAssistantEntity } from '../../src/types/room-card-types'; describe('Testing compute_state_display file', () => { + beforeEach(() => { + jest.spyOn(console, 'error').mockImplementation(jest.fn()); + }); const hass = createMock(); hass.localize = jest.fn(); diff --git a/tests/lib/format_number.test.ts b/tests/lib/format_number.test.ts index 116bd88..3a6bb72 100644 --- a/tests/lib/format_number.test.ts +++ b/tests/lib/format_number.test.ts @@ -4,14 +4,18 @@ import { formatNumber, isNumericState, numberFormatToLocale, round } from "../.. import { FormattingOptions, HomeAssistantEntity } from "../../src/types/room-card-types"; describe('Testing format_number file', () => { - test.each` - number | precision| expected - ${7200.12345} ${2} ${7200.12} - ${7200.12345} ${3} ${7200.123} - ${7200.12345} ${undefined} ${7200.12} - `('Passing number and precision should return expected', ({ number, precision, expected }) => { - - expect(round(number, precision)).toBe(expected); + beforeEach(() => { + jest.spyOn(console, 'error').mockImplementation(jest.fn()); + }); + + [ + [7200.12345, 2, 7200.12], + [7200.12345, 3, 7200.123], + [7200.12345, undefined, 7200.12], + ].forEach(([number, precision, expected]) => { + test(`Passing number ${number} and precision ${precision} should return expected`, () => { + expect(round(number, precision)).toBe(expected); + }) }), test.each` unit_of_measurement | state_class| expected diff --git a/tests/template/getTemplateOrAttribute.test.ts b/tests/template/getTemplateOrAttribute.test.ts new file mode 100644 index 0000000..f9c5898 --- /dev/null +++ b/tests/template/getTemplateOrAttribute.test.ts @@ -0,0 +1,20 @@ +import { HomeAssistant } from 'custom-card-helpers'; +import { createMock } from 'ts-auto-mock'; +import { getTemplateOrAttribute } from '../../src/template'; +import { HomeAssistantEntity, RoomCardAttributeTemplate } from '../../src/types/room-card-types';; + +describe('Testing template file function getTemplateOrAttribute', () => { + const hass = createMock(); + const stateObj = createMock(); + + [ + [{ template : "if(true) return true;" } as RoomCardAttributeTemplate, true], + ['test title', 'test title'], + [33, 33] + ].forEach(([attribute, expected]) => { + test(`Passing ${attribute} as attribute, HomeAssistant and HomeAssistantEntity be ${expected}`, ()=>{ + expect(getTemplateOrAttribute(attribute, hass, stateObj)).toBe(expected); + }) + }) +}) +