From a4ef3db5f433b1a6ca8c9a56282f15ea55d1d91e Mon Sep 17 00:00:00 2001 From: Nerwyn Singh Date: Tue, 7 Nov 2023 20:34:28 -0500 Subject: [PATCH] restore empty button logic --- dist/android-tv-card.js | 2 +- src/android-tv-card.ts | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/dist/android-tv-card.js b/dist/android-tv-card.js index 945606f4..43cfd446 100644 --- a/dist/android-tv-card.js +++ b/dist/android-tv-card.js @@ -1,5 +1,5 @@ /*! For license information please see android-tv-card.js.LICENSE.txt */ -(()=>{"use strict";var e={197:(e,t,i)=>{i.r(t),i.d(t,{DEFAULT_DOMAIN_ICON:()=>G,DEFAULT_PANEL:()=>J,DEFAULT_VIEW_ENTITY_ID:()=>ae,DOMAINS_HIDE_MORE_INFO:()=>te,DOMAINS_MORE_INFO_NO_HISTORY:()=>ie,DOMAINS_TOGGLE:()=>oe,DOMAINS_WITH_CARD:()=>Q,DOMAINS_WITH_MORE_INFO:()=>ee,NumberFormat:()=>n,STATES_OFF:()=>ne,TimeFormat:()=>o,UNIT_C:()=>re,UNIT_F:()=>se,applyThemesOnElement:()=>j,computeCardSize:()=>U,computeDomain:()=>Z,computeEntity:()=>F,computeRTL:()=>H,computeRTLDirection:()=>B,computeStateDisplay:()=>X,computeStateDomain:()=>K,createThing:()=>de,debounce:()=>he,domainIcon:()=>pe,evaluateFilter:()=>fe,fireEvent:()=>ce,fixedIcons:()=>me,formatDate:()=>u,formatDateMonth:()=>y,formatDateMonthYear:()=>C,formatDateNumeric:()=>h,formatDateShort:()=>p,formatDateTime:()=>w,formatDateTimeNumeric:()=>A,formatDateTimeWithSeconds:()=>$,formatDateWeekday:()=>c,formatDateYear:()=>b,formatNumber:()=>Y,formatTime:()=>S,formatTimeWeekday:()=>I,formatTimeWithSeconds:()=>O,forwardHaptic:()=>Ce,getLovelace:()=>Ae,handleAction:()=>_e,handleActionConfig:()=>be,handleClick:()=>Le,hasAction:()=>we,hasConfigOrEntityChanged:()=>ke,hasDoubleClick:()=>$e,isNumericState:()=>V,navigate:()=>ve,numberFormatToLocale:()=>z,relativeTime:()=>P,round:()=>q,stateIcon:()=>xe,timerTimeRemaining:()=>R,toggleEntity:()=>ge,turnOnOffEntities:()=>Ee,turnOnOffEntity:()=>ye});var n,o,r,s=function(){return s=Object.assign||function(e){for(var t,i=1,n=arguments.length;i0)return{value:Math.round(h),unit:"year"};var m=12*h+u.getMonth()-d.getMonth();if(Math.round(Math.abs(m))>0)return{value:Math.round(m),unit:"month"};var p=o/604800;return{value:Math.round(p),unit:"week"}}(e,i);return n?function(e){return new Intl.RelativeTimeFormat(e.language,{numeric:"auto"})}(t).format(o.value,o.unit):Intl.NumberFormat(t.language,{style:"unit",unit:o.unit,unitDisplay:"long"}).format(Math.abs(o.value))};function R(e){var t,i=3600*(t=e.attributes.remaining.split(":").map(Number))[0]+60*t[1]+t[2];if("active"===e.state){var n=(new Date).getTime(),o=new Date(e.last_changed).getTime();i=Math.max(i-(n-o)/1e3,0)}return i}function N(){return(N=Object.assign||function(e){for(var t=1;t-1?e.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},X=function(e,t,i,n){var o=void 0!==n?n:t.state;if("unknown"===o||"unavailable"===o)return e("state.default."+o);if(V(t)){if("monetary"===t.attributes.device_class)try{return Y(o,i,{style:"currency",currency:t.attributes.unit_of_measurement})}catch(e){}return Y(o,i)+(t.attributes.unit_of_measurement?" "+t.attributes.unit_of_measurement:"")}var r=K(t);if("input_datetime"===r){var s;if(void 0===n)return t.attributes.has_date&&t.attributes.has_time?(s=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),w(s,i)):t.attributes.has_date?(s=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),u(s,i)):t.attributes.has_time?((s=new Date).setHours(t.attributes.hour,t.attributes.minute),S(s,i)):t.state;try{var a=n.split(" ");if(2===a.length)return w(new Date(a.join("T")),i);if(1===a.length){if(n.includes("-"))return u(new Date(n+"T00:00"),i);if(n.includes(":")){var c=new Date;return S(new Date(c.toISOString().split("T")[0]+"T"+n),i)}}return n}catch(e){return n}}return"humidifier"===r&&"on"===o&&t.attributes.humidity?t.attributes.humidity+" %":"counter"===r||"number"===r||"input_number"===r?Y(o,i):t.attributes.device_class&&e("component."+r+".state."+t.attributes.device_class+"."+o)||e("component."+r+".state._."+o)||o},G="mdi:bookmark",J="lovelace",Q=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],ee=["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"],te=["input_number","input_select","input_text","scene","weblink"],ie=["camera","configurator","history_graph","scene"],ne=["closed","locked","off"],oe=new Set(["fan","input_boolean","light","switch","group","automation"]),re="°C",se="°F",ae="group.default_view",ce=function(e,t,i,n){n=n||{},i=null==i?{}:i;var o=new Event(t,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return o.detail=i,e.dispatchEvent(o),o},le=new Set(["call-service","divider","section","weblink","cast","select"]),ue={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"},de=function(e,t){void 0===t&&(t=!1);var i=function(e,t){return n("hui-error-card",{type:"error",error:e,config:t})},n=function(e,t){var n=window.document.createElement(e);try{if(!n.setConfig)return;n.setConfig(t)}catch(n){return console.error(e,n),i(n.message,t)}return n};if(!e||"object"!=typeof e||!t&&!e.type)return i("No type defined",e);var o=e.type;if(o&&o.startsWith("custom:"))o=o.substr(7);else if(t)if(le.has(o))o="hui-"+o+"-row";else{if(!e.entity)return i("Invalid config given.",e);var r=e.entity.split(".",1)[0];o="hui-"+(ue[r]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return n(o,e);var s=i("Custom element doesn't exist: "+e.type+".",e);s.style.display="None";var a=setTimeout((function(){s.style.display=""}),2e3);return customElements.whenDefined(e.type).then((function(){clearTimeout(a),ce(s,"ll-rebuild",{},s)})),s},he=function(e,t,i){var n;return void 0===i&&(i=!1),function(){var o=[].slice.call(arguments),r=this,s=i&&!n;clearTimeout(n),n=setTimeout((function(){n=null,i||e.apply(r,o)}),t),s&&e.apply(r,o)}},me={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 pe(e,t){if(e in me)return me[e];switch(e){case"alarm_control_panel":switch(t){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 t&&"off"===t?"mdi:radiobox-blank":"mdi:checkbox-marked-circle";case"cover":return"closed"===t?"mdi:window-closed":"mdi:window-open";case"lock":return t&&"unlocked"===t?"mdi:lock-open":"mdi:lock";case"media_player":return t&&"off"!==t&&"idle"!==t?"mdi:cast-connected":"mdi:cast";case"zwave":switch(t){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 "+e+" ("+t+")"),"mdi:bookmark"}}var fe=function(e,t){var i=t.value||t,n=t.attribute?e.attributes[t.attribute]:e.state;switch(t.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}},Ce=function(e){ce(window,"haptic",e)},ve=function(e,t,i){void 0===i&&(i=!1),i?history.replaceState(null,"",t):history.pushState(null,"",t),ce(window,"location-changed",{replace:i})},ye=function(e,t,i){void 0===i&&(i=!0);var n,o=Z(t),r="group"===o?"homeassistant":o;switch(o){case"lock":n=i?"unlock":"lock";break;case"cover":n=i?"open_cover":"close_cover";break;default:n=i?"turn_on":"turn_off"}return e.callService(r,n,{entity_id:t})},ge=function(e,t){var i=ne.includes(e.states[t].state);return ye(e,t,i)},be=function(e,t,i,n){if(n||(n={action:"more-info"}),!n.confirmation||n.confirmation.exemptions&&n.confirmation.exemptions.some((function(e){return e.user===t.user.id}))||(Ce("warning"),confirm(n.confirmation.text||"Are you sure you want to "+n.action+"?")))switch(n.action){case"more-info":(i.entity||i.camera_image)&&ce(e,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":n.navigation_path&&ve(0,n.navigation_path);break;case"url":n.url_path&&window.open(n.url_path);break;case"toggle":i.entity&&(ge(t,i.entity),Ce("success"));break;case"call-service":if(!n.service)return void Ce("failure");var o=n.service.split(".",2);t.callService(o[0],o[1],n.service_data,n.target),Ce("success");break;case"fire-dom-event":ce(e,"ll-custom",n)}},_e=function(e,t,i,n){var o;"double_tap"===n&&i.double_tap_action?o=i.double_tap_action:"hold"===n&&i.hold_action?o=i.hold_action:"tap"===n&&i.tap_action&&(o=i.tap_action),be(e,t,i,o)},Le=function(e,t,i,n,o){var r;if(o&&i.double_tap_action?r=i.double_tap_action:n&&i.hold_action?r=i.hold_action:!n&&i.tap_action&&(r=i.tap_action),r||(r={action:"more-info"}),!r.confirmation||r.confirmation.exemptions&&r.confirmation.exemptions.some((function(e){return e.user===t.user.id}))||confirm(r.confirmation.text||"Are you sure you want to "+r.action+"?"))switch(r.action){case"more-info":(r.entity||i.entity||i.camera_image)&&(ce(e,"hass-more-info",{entityId:r.entity?r.entity:i.entity?i.entity:i.camera_image}),r.haptic&&Ce(r.haptic));break;case"navigate":r.navigation_path&&(ve(0,r.navigation_path),r.haptic&&Ce(r.haptic));break;case"url":r.url_path&&window.open(r.url_path),r.haptic&&Ce(r.haptic);break;case"toggle":i.entity&&(ge(t,i.entity),r.haptic&&Ce(r.haptic));break;case"call-service":if(!r.service)return;var s=r.service.split(".",2),a=s[0],c=s[1],l=N({},r.service_data);"entity"===l.entity_id&&(l.entity_id=i.entity),t.callService(a,c,l,r.target),r.haptic&&Ce(r.haptic);break;case"fire-dom-event":ce(e,"ll-custom",r),r.haptic&&Ce(r.haptic)}};function we(e){return void 0!==e&&"none"!==e.action}function ke(e,t,i){if(t.has("config")||i)return!0;if(e.config.entity){var n=t.get("hass");return!n||n.states[e.config.entity]!==e.hass.states[e.config.entity]}return!1}function $e(e){return void 0!==e&&"none"!==e.action}var Ee=function(e,t,i){void 0===i&&(i=!0);var n={};t.forEach((function(t){if(ne.includes(e.states[t].state)===i){var o=Z(t),r=["cover","lock"].includes(o)?o:"homeassistant";r in n||(n[r]=[]),n[r].push(t)}})),Object.keys(n).forEach((function(t){var o;switch(t){case"lock":o=i?"unlock":"lock";break;case"cover":o=i?"open_cover":"close_cover";break;default:o=i?"turn_on":"turn_off"}e.callService(t,o,{entity_id:n[t]})}))},Ae=function(){var e=document.querySelector("home-assistant");if(e=(e=(e=(e=(e=(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root")){var t=e.lovelace;return t.current_view=e.___curView,t}return null},Me={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Se={binary_sensor:function(e,t){var i="off"===e;switch(null==t?void 0:t.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(e){var t="closed"!==e.state;switch(e.attributes.device_class){case"garage":return t?"mdi:garage-open":"mdi:garage";case"door":return t?"mdi:door-open":"mdi:door-closed";case"shutter":return t?"mdi:window-shutter-open":"mdi:window-shutter";case"blind":return t?"mdi:blinds-open":"mdi:blinds";case"window":return t?"mdi:window-open":"mdi:window-closed";default:return pe("cover",e.state)}},sensor:function(e){var t=e.attributes.device_class;if(t&&t in Me)return Me[t];if("battery"===t){var i=Number(e.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 o=e.attributes.unit_of_measurement;return"°C"===o||"°F"===o?"mdi:thermometer":pe("sensor")},input_datetime:function(e){return e.attributes.has_date?e.attributes.has_time?pe("input_datetime"):"mdi:calendar":"mdi:clock"}},xe=function(e){if(!e)return"mdi:bookmark";if(e.attributes.icon)return e.attributes.icon;var t=Z(e.entity_id);return t in Se?Se[t](e):pe(t,e.state)}},992:function(e,t,i){var n=this&&this.__decorate||function(e,t,i,n){var o,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(r<3?o(s):r>3?o(t,i,s):o(t,i))||s);return r>3&&s&&Object.defineProperty(t,i,s),s},o=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(o,r){function s(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const r=i(147),s=i(677),a=i(595),c=i(197),l=i(554);i(984),i(389),i(448),i(786),i(857),i(116),console.info(`%c ANDROID-TV-CARD v${r.version}`,"color: white; font-weight: bold; background: green");class u extends s.LitElement{constructor(){super(...arguments),this.customKeys={},this.customSources={},this.customIcons={}}static get properties(){return{hass:{},config:{}}}static getStubConfig(){return{type:"custom:android-tv-card",rows:[]}}getCardSize(){let e=this.config.rows.length;return"title"in this.config&&(e+=1),e}setConfig(e){return o(this,void 0,void 0,(function*(){if(!e)throw new Error("Invalid configuration");e=JSON.parse(JSON.stringify(e)),e=Object.assign({theme:"default"},e),e=this.updateDeprecatedKeys(e),e=this.convertToRowsArray(e),e=this.combineServiceFields(e),this.customKeys=e.custom_keys||{},this.customSources=e.custom_sources||{},this.customIcons=e.custom_icons||{},yield window.loadCardHelpers(),this.config=e}))}updateDeprecatedKeys(e){return"adb_id"in e&&!("keyboard_id"in e)&&(e.keyboard_id=e.adb_id),"touchpad_height"in e&&!("touchpad_style"in e)&&(e.touchpad_style={height:e.touchpad_height}),e}convertToRowsArray(e){if(!("rows"in e)||!(e.rows||[]).length){const t=[],i=Object.keys(e).filter((e=>e.includes("_row")));for(const n of i){let i=e[n];"string"==typeof i&&(i=[i]),"volume_row"==n?i=["volume_"+i[0]]:"navigation_row"==n&&(i=["navigation_"+i[0]]),t.push(i)}e.rows=t}return e}combineServiceFields(e){const t=["custom_keys","custom_sources"];for(const i of t)if(i in e){const t=e[i];for(const e in t){const i=t[e];"service"in i&&(i.data=Object.assign(Object.assign(Object.assign({},i.data),i.service_data),i.target))}}return e}getInfo(e){var t,i;const n=l.defaultKeys[e]||l.defaultSources[e]||{},o=this.customKeys[e]||this.customSources[e]||n;return(null==o?void 0:o.icon)||o.svg_path||(o.icon=null!==(t=null==n?void 0:n.icon)&&void 0!==t?t:"",o.svg_path=null!==(i=null==n?void 0:n.svg_path)&&void 0!==i?i:""),o}buildRow(e){return s.html`
${e}
`}buildColumn(e){return s.html`
${e}
`}buildButton(e){var t,i;const n=this.getInfo(e),o=Object.assign(Object.assign({},this.config.button_style),n.style);return s.html`{"use strict";var e={197:(e,t,i)=>{i.r(t),i.d(t,{DEFAULT_DOMAIN_ICON:()=>G,DEFAULT_PANEL:()=>J,DEFAULT_VIEW_ENTITY_ID:()=>ae,DOMAINS_HIDE_MORE_INFO:()=>te,DOMAINS_MORE_INFO_NO_HISTORY:()=>ie,DOMAINS_TOGGLE:()=>oe,DOMAINS_WITH_CARD:()=>Q,DOMAINS_WITH_MORE_INFO:()=>ee,NumberFormat:()=>n,STATES_OFF:()=>ne,TimeFormat:()=>o,UNIT_C:()=>re,UNIT_F:()=>se,applyThemesOnElement:()=>j,computeCardSize:()=>U,computeDomain:()=>Z,computeEntity:()=>F,computeRTL:()=>H,computeRTLDirection:()=>B,computeStateDisplay:()=>X,computeStateDomain:()=>K,createThing:()=>de,debounce:()=>he,domainIcon:()=>pe,evaluateFilter:()=>fe,fireEvent:()=>ce,fixedIcons:()=>me,formatDate:()=>u,formatDateMonth:()=>y,formatDateMonthYear:()=>C,formatDateNumeric:()=>h,formatDateShort:()=>p,formatDateTime:()=>w,formatDateTimeNumeric:()=>A,formatDateTimeWithSeconds:()=>$,formatDateWeekday:()=>c,formatDateYear:()=>b,formatNumber:()=>Y,formatTime:()=>S,formatTimeWeekday:()=>I,formatTimeWithSeconds:()=>O,forwardHaptic:()=>Ce,getLovelace:()=>Ae,handleAction:()=>_e,handleActionConfig:()=>be,handleClick:()=>Le,hasAction:()=>we,hasConfigOrEntityChanged:()=>ke,hasDoubleClick:()=>$e,isNumericState:()=>V,navigate:()=>ve,numberFormatToLocale:()=>z,relativeTime:()=>P,round:()=>q,stateIcon:()=>xe,timerTimeRemaining:()=>R,toggleEntity:()=>ge,turnOnOffEntities:()=>Ee,turnOnOffEntity:()=>ye});var n,o,r,s=function(){return s=Object.assign||function(e){for(var t,i=1,n=arguments.length;i0)return{value:Math.round(h),unit:"year"};var m=12*h+u.getMonth()-d.getMonth();if(Math.round(Math.abs(m))>0)return{value:Math.round(m),unit:"month"};var p=o/604800;return{value:Math.round(p),unit:"week"}}(e,i);return n?function(e){return new Intl.RelativeTimeFormat(e.language,{numeric:"auto"})}(t).format(o.value,o.unit):Intl.NumberFormat(t.language,{style:"unit",unit:o.unit,unitDisplay:"long"}).format(Math.abs(o.value))};function R(e){var t,i=3600*(t=e.attributes.remaining.split(":").map(Number))[0]+60*t[1]+t[2];if("active"===e.state){var n=(new Date).getTime(),o=new Date(e.last_changed).getTime();i=Math.max(i-(n-o)/1e3,0)}return i}function N(){return(N=Object.assign||function(e){for(var t=1;t-1?e.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},X=function(e,t,i,n){var o=void 0!==n?n:t.state;if("unknown"===o||"unavailable"===o)return e("state.default."+o);if(V(t)){if("monetary"===t.attributes.device_class)try{return Y(o,i,{style:"currency",currency:t.attributes.unit_of_measurement})}catch(e){}return Y(o,i)+(t.attributes.unit_of_measurement?" "+t.attributes.unit_of_measurement:"")}var r=K(t);if("input_datetime"===r){var s;if(void 0===n)return t.attributes.has_date&&t.attributes.has_time?(s=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day,t.attributes.hour,t.attributes.minute),w(s,i)):t.attributes.has_date?(s=new Date(t.attributes.year,t.attributes.month-1,t.attributes.day),u(s,i)):t.attributes.has_time?((s=new Date).setHours(t.attributes.hour,t.attributes.minute),S(s,i)):t.state;try{var a=n.split(" ");if(2===a.length)return w(new Date(a.join("T")),i);if(1===a.length){if(n.includes("-"))return u(new Date(n+"T00:00"),i);if(n.includes(":")){var c=new Date;return S(new Date(c.toISOString().split("T")[0]+"T"+n),i)}}return n}catch(e){return n}}return"humidifier"===r&&"on"===o&&t.attributes.humidity?t.attributes.humidity+" %":"counter"===r||"number"===r||"input_number"===r?Y(o,i):t.attributes.device_class&&e("component."+r+".state."+t.attributes.device_class+"."+o)||e("component."+r+".state._."+o)||o},G="mdi:bookmark",J="lovelace",Q=["climate","cover","configurator","input_select","input_number","input_text","lock","media_player","scene","script","timer","vacuum","water_heater","weblink"],ee=["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"],te=["input_number","input_select","input_text","scene","weblink"],ie=["camera","configurator","history_graph","scene"],ne=["closed","locked","off"],oe=new Set(["fan","input_boolean","light","switch","group","automation"]),re="°C",se="°F",ae="group.default_view",ce=function(e,t,i,n){n=n||{},i=null==i?{}:i;var o=new Event(t,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return o.detail=i,e.dispatchEvent(o),o},le=new Set(["call-service","divider","section","weblink","cast","select"]),ue={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"},de=function(e,t){void 0===t&&(t=!1);var i=function(e,t){return n("hui-error-card",{type:"error",error:e,config:t})},n=function(e,t){var n=window.document.createElement(e);try{if(!n.setConfig)return;n.setConfig(t)}catch(n){return console.error(e,n),i(n.message,t)}return n};if(!e||"object"!=typeof e||!t&&!e.type)return i("No type defined",e);var o=e.type;if(o&&o.startsWith("custom:"))o=o.substr(7);else if(t)if(le.has(o))o="hui-"+o+"-row";else{if(!e.entity)return i("Invalid config given.",e);var r=e.entity.split(".",1)[0];o="hui-"+(ue[r]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return n(o,e);var s=i("Custom element doesn't exist: "+e.type+".",e);s.style.display="None";var a=setTimeout((function(){s.style.display=""}),2e3);return customElements.whenDefined(e.type).then((function(){clearTimeout(a),ce(s,"ll-rebuild",{},s)})),s},he=function(e,t,i){var n;return void 0===i&&(i=!1),function(){var o=[].slice.call(arguments),r=this,s=i&&!n;clearTimeout(n),n=setTimeout((function(){n=null,i||e.apply(r,o)}),t),s&&e.apply(r,o)}},me={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 pe(e,t){if(e in me)return me[e];switch(e){case"alarm_control_panel":switch(t){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 t&&"off"===t?"mdi:radiobox-blank":"mdi:checkbox-marked-circle";case"cover":return"closed"===t?"mdi:window-closed":"mdi:window-open";case"lock":return t&&"unlocked"===t?"mdi:lock-open":"mdi:lock";case"media_player":return t&&"off"!==t&&"idle"!==t?"mdi:cast-connected":"mdi:cast";case"zwave":switch(t){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 "+e+" ("+t+")"),"mdi:bookmark"}}var fe=function(e,t){var i=t.value||t,n=t.attribute?e.attributes[t.attribute]:e.state;switch(t.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}},Ce=function(e){ce(window,"haptic",e)},ve=function(e,t,i){void 0===i&&(i=!1),i?history.replaceState(null,"",t):history.pushState(null,"",t),ce(window,"location-changed",{replace:i})},ye=function(e,t,i){void 0===i&&(i=!0);var n,o=Z(t),r="group"===o?"homeassistant":o;switch(o){case"lock":n=i?"unlock":"lock";break;case"cover":n=i?"open_cover":"close_cover";break;default:n=i?"turn_on":"turn_off"}return e.callService(r,n,{entity_id:t})},ge=function(e,t){var i=ne.includes(e.states[t].state);return ye(e,t,i)},be=function(e,t,i,n){if(n||(n={action:"more-info"}),!n.confirmation||n.confirmation.exemptions&&n.confirmation.exemptions.some((function(e){return e.user===t.user.id}))||(Ce("warning"),confirm(n.confirmation.text||"Are you sure you want to "+n.action+"?")))switch(n.action){case"more-info":(i.entity||i.camera_image)&&ce(e,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":n.navigation_path&&ve(0,n.navigation_path);break;case"url":n.url_path&&window.open(n.url_path);break;case"toggle":i.entity&&(ge(t,i.entity),Ce("success"));break;case"call-service":if(!n.service)return void Ce("failure");var o=n.service.split(".",2);t.callService(o[0],o[1],n.service_data,n.target),Ce("success");break;case"fire-dom-event":ce(e,"ll-custom",n)}},_e=function(e,t,i,n){var o;"double_tap"===n&&i.double_tap_action?o=i.double_tap_action:"hold"===n&&i.hold_action?o=i.hold_action:"tap"===n&&i.tap_action&&(o=i.tap_action),be(e,t,i,o)},Le=function(e,t,i,n,o){var r;if(o&&i.double_tap_action?r=i.double_tap_action:n&&i.hold_action?r=i.hold_action:!n&&i.tap_action&&(r=i.tap_action),r||(r={action:"more-info"}),!r.confirmation||r.confirmation.exemptions&&r.confirmation.exemptions.some((function(e){return e.user===t.user.id}))||confirm(r.confirmation.text||"Are you sure you want to "+r.action+"?"))switch(r.action){case"more-info":(r.entity||i.entity||i.camera_image)&&(ce(e,"hass-more-info",{entityId:r.entity?r.entity:i.entity?i.entity:i.camera_image}),r.haptic&&Ce(r.haptic));break;case"navigate":r.navigation_path&&(ve(0,r.navigation_path),r.haptic&&Ce(r.haptic));break;case"url":r.url_path&&window.open(r.url_path),r.haptic&&Ce(r.haptic);break;case"toggle":i.entity&&(ge(t,i.entity),r.haptic&&Ce(r.haptic));break;case"call-service":if(!r.service)return;var s=r.service.split(".",2),a=s[0],c=s[1],l=N({},r.service_data);"entity"===l.entity_id&&(l.entity_id=i.entity),t.callService(a,c,l,r.target),r.haptic&&Ce(r.haptic);break;case"fire-dom-event":ce(e,"ll-custom",r),r.haptic&&Ce(r.haptic)}};function we(e){return void 0!==e&&"none"!==e.action}function ke(e,t,i){if(t.has("config")||i)return!0;if(e.config.entity){var n=t.get("hass");return!n||n.states[e.config.entity]!==e.hass.states[e.config.entity]}return!1}function $e(e){return void 0!==e&&"none"!==e.action}var Ee=function(e,t,i){void 0===i&&(i=!0);var n={};t.forEach((function(t){if(ne.includes(e.states[t].state)===i){var o=Z(t),r=["cover","lock"].includes(o)?o:"homeassistant";r in n||(n[r]=[]),n[r].push(t)}})),Object.keys(n).forEach((function(t){var o;switch(t){case"lock":o=i?"unlock":"lock";break;case"cover":o=i?"open_cover":"close_cover";break;default:o=i?"turn_on":"turn_off"}e.callService(t,o,{entity_id:n[t]})}))},Ae=function(){var e=document.querySelector("home-assistant");if(e=(e=(e=(e=(e=(e=(e=(e=e&&e.shadowRoot)&&e.querySelector("home-assistant-main"))&&e.shadowRoot)&&e.querySelector("app-drawer-layout partial-panel-resolver"))&&e.shadowRoot||e)&&e.querySelector("ha-panel-lovelace"))&&e.shadowRoot)&&e.querySelector("hui-root")){var t=e.lovelace;return t.current_view=e.___curView,t}return null},Me={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Se={binary_sensor:function(e,t){var i="off"===e;switch(null==t?void 0:t.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(e){var t="closed"!==e.state;switch(e.attributes.device_class){case"garage":return t?"mdi:garage-open":"mdi:garage";case"door":return t?"mdi:door-open":"mdi:door-closed";case"shutter":return t?"mdi:window-shutter-open":"mdi:window-shutter";case"blind":return t?"mdi:blinds-open":"mdi:blinds";case"window":return t?"mdi:window-open":"mdi:window-closed";default:return pe("cover",e.state)}},sensor:function(e){var t=e.attributes.device_class;if(t&&t in Me)return Me[t];if("battery"===t){var i=Number(e.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 o=e.attributes.unit_of_measurement;return"°C"===o||"°F"===o?"mdi:thermometer":pe("sensor")},input_datetime:function(e){return e.attributes.has_date?e.attributes.has_time?pe("input_datetime"):"mdi:calendar":"mdi:clock"}},xe=function(e){if(!e)return"mdi:bookmark";if(e.attributes.icon)return e.attributes.icon;var t=Z(e.entity_id);return t in Se?Se[t](e):pe(t,e.state)}},992:function(e,t,i){var n=this&&this.__decorate||function(e,t,i,n){var o,r=arguments.length,s=r<3?t:null===n?n=Object.getOwnPropertyDescriptor(t,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,n);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(s=(r<3?o(s):r>3?o(t,i,s):o(t,i))||s);return r>3&&s&&Object.defineProperty(t,i,s),s},o=this&&this.__awaiter||function(e,t,i,n){return new(i||(i=Promise))((function(o,r){function s(e){try{c(n.next(e))}catch(e){r(e)}}function a(e){try{c(n.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof i?t:new i((function(e){e(t)}))).then(s,a)}c((n=n.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const r=i(147),s=i(677),a=i(595),c=i(197),l=i(554);i(984),i(389),i(448),i(786),i(857),i(116),console.info(`%c ANDROID-TV-CARD v${r.version}`,"color: white; font-weight: bold; background: green");class u extends s.LitElement{constructor(){super(...arguments),this.customKeys={},this.customSources={},this.customIcons={}}static get properties(){return{hass:{},config:{}}}static getStubConfig(){return{type:"custom:android-tv-card",rows:[]}}getCardSize(){let e=this.config.rows.length;return"title"in this.config&&(e+=1),e}setConfig(e){return o(this,void 0,void 0,(function*(){if(!e)throw new Error("Invalid configuration");e=JSON.parse(JSON.stringify(e)),e=Object.assign({theme:"default"},e),e=this.updateDeprecatedKeys(e),e=this.convertToRowsArray(e),e=this.combineServiceFields(e),this.customKeys=e.custom_keys||{},this.customSources=e.custom_sources||{},this.customIcons=e.custom_icons||{},yield window.loadCardHelpers(),this.config=e}))}updateDeprecatedKeys(e){return"adb_id"in e&&!("keyboard_id"in e)&&(e.keyboard_id=e.adb_id),"touchpad_height"in e&&!("touchpad_style"in e)&&(e.touchpad_style={height:e.touchpad_height}),e}convertToRowsArray(e){if(!("rows"in e)||!(e.rows||[]).length){const t=[],i=Object.keys(e).filter((e=>e.includes("_row")));for(const n of i){let i=e[n];"string"==typeof i&&(i=[i]),"volume_row"==n?i=["volume_"+i[0]]:"navigation_row"==n&&(i=["navigation_"+i[0]]),t.push(i)}e.rows=t}return e}combineServiceFields(e){const t=["custom_keys","custom_sources"];for(const i of t)if(i in e){const t=e[i];for(const e in t){const i=t[e];"service"in i&&(i.data=Object.assign(Object.assign(Object.assign({},i.data),i.service_data),i.target))}}return e}getInfo(e){var t,i;const n=l.defaultKeys[e]||l.defaultSources[e]||{},o=this.customKeys[e]||this.customSources[e]||n;return Object.keys(o).length?((null==o?void 0:o.icon)||o.svg_path||(o.icon=null!==(t=null==n?void 0:n.icon)&&void 0!==t?t:void 0,o.svg_path=null!==(i=null==n?void 0:n.svg_path)&&void 0!==i?i:void 0),o):{}}buildRow(e){return s.html`
${e}
`}buildColumn(e){return s.html`
${e}
`}buildButton(e){var t,i;const n=this.getInfo(e);if(!Object.keys(n).length)return s.html`
`;const o=Object.assign(Object.assign({},this.config.button_style),n.style);return s.html``; + } + const style = { ...this.config.button_style, ...info.style, }; - return html`