From 45943cfe19fdb9e4829c126e2e0569191b6d8ada Mon Sep 17 00:00:00 2001 From: Nerwyn Singh Date: Sat, 9 Sep 2023 16:59:19 -0400 Subject: [PATCH] increase number of retries for creating volume slider --- dist/android-tv-card.js | 2 +- src/android-tv-card.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/android-tv-card.js b/dist/android-tv-card.js index 608189ce..46281156 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 t={197:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_DOMAIN_ICON:()=>G,DEFAULT_PANEL:()=>J,DEFAULT_VIEW_ENTITY_ID:()=>at,DOMAINS_HIDE_MORE_INFO:()=>et,DOMAINS_MORE_INFO_NO_HISTORY:()=>it,DOMAINS_TOGGLE:()=>ot,DOMAINS_WITH_CARD:()=>Q,DOMAINS_WITH_MORE_INFO:()=>tt,NumberFormat:()=>n,STATES_OFF:()=>nt,TimeFormat:()=>o,UNIT_C:()=>rt,UNIT_F:()=>st,applyThemesOnElement:()=>U,computeCardSize:()=>Z,computeDomain:()=>j,computeEntity:()=>F,computeRTL:()=>B,computeRTLDirection:()=>H,computeStateDisplay:()=>X,computeStateDomain:()=>V,createThing:()=>dt,debounce:()=>ht,domainIcon:()=>Ct,evaluateFilter:()=>pt,fireEvent:()=>ct,fixedIcons:()=>mt,formatDate:()=>u,formatDateMonth:()=>_,formatDateMonthYear:()=>f,formatDateNumeric:()=>h,formatDateShort:()=>C,formatDateTime:()=>w,formatDateTimeNumeric:()=>M,formatDateTimeWithSeconds:()=>A,formatDateWeekday:()=>c,formatDateYear:()=>y,formatNumber:()=>W,formatTime:()=>E,formatTimeWeekday:()=>D,formatTimeWithSeconds:()=>O,forwardHaptic:()=>ft,getLovelace:()=>Mt,handleAction:()=>Lt,handleActionConfig:()=>yt,handleClick:()=>bt,hasAction:()=>wt,hasConfigOrEntityChanged:()=>kt,hasDoubleClick:()=>At,isNumericState:()=>z,navigate:()=>vt,numberFormatToLocale:()=>K,relativeTime:()=>P,round:()=>q,stateIcon:()=>Tt,timerTimeRemaining:()=>N,toggleEntity:()=>gt,turnOnOffEntities:()=>$t,turnOnOffEntity:()=>_t});var n,o,r,s=function(){return s=Object.assign||function(t){for(var e,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 C=o/604800;return{value:Math.round(C),unit:"week"}}(t,i);return n?function(t){return new Intl.RelativeTimeFormat(t.language,{numeric:"auto"})}(e).format(o.value,o.unit):Intl.NumberFormat(e.language,{style:"unit",unit:o.unit,unitDisplay:"long"}).format(Math.abs(o.value))};function N(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(),o=new Date(t.last_changed).getTime();i=Math.max(i-(n-o)/1e3,0)}return i}function R(){return(R=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},X=function(t,e,i,n){var o=void 0!==n?n:e.state;if("unknown"===o||"unavailable"===o)return t("state.default."+o);if(z(e)){if("monetary"===e.attributes.device_class)try{return W(o,i,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return W(o,i)+(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var r=V(e);if("input_datetime"===r){var s;if(void 0===n)return e.attributes.has_date&&e.attributes.has_time?(s=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),w(s,i)):e.attributes.has_date?(s=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),u(s,i)):e.attributes.has_time?((s=new Date).setHours(e.attributes.hour,e.attributes.minute),E(s,i)):e.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 E(new Date(c.toISOString().split("T")[0]+"T"+n),i)}}return n}catch(t){return n}}return"humidifier"===r&&"on"===o&&e.attributes.humidity?e.attributes.humidity+" %":"counter"===r||"number"===r||"input_number"===r?W(o,i):e.attributes.device_class&&t("component."+r+".state."+e.attributes.device_class+"."+o)||t("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"],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"],ot=new Set(["fan","input_boolean","light","switch","group","automation"]),rt="°C",st="°F",at="group.default_view",ct=function(t,e,i,n){n=n||{},i=null==i?{}:i;var o=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return o.detail=i,t.dispatchEvent(o),o},lt=new Set(["call-service","divider","section","weblink","cast","select"]),ut={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 o=t.type;if(o&&o.startsWith("custom:"))o=o.substr(7);else if(e)if(lt.has(o))o="hui-"+o+"-row";else{if(!t.entity)return i("Invalid config given.",t);var r=t.entity.split(".",1)[0];o="hui-"+(ut[r]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return n(o,t);var s=i("Custom element doesn't exist: "+t.type+".",t);s.style.display="None";var a=setTimeout((function(){s.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(a),ct(s,"ll-rebuild",{},s)})),s},ht=function(t,e,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||t.apply(r,o)}),e),s&&t.apply(r,o)}},mt={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 Ct(t,e){if(t in mt)return mt[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}},ft=function(t){ct(window,"haptic",t)},vt=function(t,e,i){void 0===i&&(i=!1),i?history.replaceState(null,"",e):history.pushState(null,"",e),ct(window,"location-changed",{replace:i})},_t=function(t,e,i){void 0===i&&(i=!0);var n,o=j(e),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 t.callService(r,n,{entity_id:e})},gt=function(t,e){var i=nt.includes(t.states[e].state);return _t(t,e,i)},yt=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}))||(ft("warning"),confirm(n.confirmation.text||"Are you sure you want to "+n.action+"?")))switch(n.action){case"more-info":(i.entity||i.camera_image)&&ct(t,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":n.navigation_path&&vt(0,n.navigation_path);break;case"url":n.url_path&&window.open(n.url_path);break;case"toggle":i.entity&&(gt(e,i.entity),ft("success"));break;case"call-service":if(!n.service)return void ft("failure");var o=n.service.split(".",2);e.callService(o[0],o[1],n.service_data,n.target),ft("success");break;case"fire-dom-event":ct(t,"ll-custom",n)}},Lt=function(t,e,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),yt(t,e,i,o)},bt=function(t,e,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(t){return t.user===e.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)&&(ct(t,"hass-more-info",{entityId:r.entity?r.entity:i.entity?i.entity:i.camera_image}),r.haptic&&ft(r.haptic));break;case"navigate":r.navigation_path&&(vt(0,r.navigation_path),r.haptic&&ft(r.haptic));break;case"url":r.url_path&&window.open(r.url_path),r.haptic&&ft(r.haptic);break;case"toggle":i.entity&&(gt(e,i.entity),r.haptic&&ft(r.haptic));break;case"call-service":if(!r.service)return;var s=r.service.split(".",2),a=s[0],c=s[1],l=R({},r.service_data);"entity"===l.entity_id&&(l.entity_id=i.entity),e.callService(a,c,l,r.target),r.haptic&&ft(r.haptic);break;case"fire-dom-event":ct(t,"ll-custom",r),r.haptic&&ft(r.haptic)}};function wt(t){return void 0!==t&&"none"!==t.action}function kt(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 At(t){return void 0!==t&&"none"!==t.action}var $t=function(t,e,i){void 0===i&&(i=!0);var n={};e.forEach((function(e){if(nt.includes(t.states[e].state)===i){var o=j(e),r=["cover","lock"].includes(o)?o:"homeassistant";r in n||(n[r]=[]),n[r].push(e)}})),Object.keys(n).forEach((function(e){var o;switch(e){case"lock":o=i?"unlock":"lock";break;case"cover":o=i?"open_cover":"close_cover";break;default:o=i?"turn_on":"turn_off"}t.callService(e,o,{entity_id:n[e]})}))},Mt=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},St={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Et={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 Ct("cover",t.state)}},sensor:function(t){var e=t.attributes.device_class;if(e&&e in St)return St[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 o=t.attributes.unit_of_measurement;return"°C"===o||"°F"===o?"mdi:thermometer":Ct("sensor")},input_datetime:function(t){return t.attributes.has_date?t.attributes.has_time?Ct("input_datetime"):"mdi:calendar":"mdi:clock"}},Tt=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=j(t.entity_id);return e in Et?Et[e](t):Ct(e,t.state)}},992:function(t,e,i){var n=this&&this.__decorate||function(t,e,i,n){var o,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,i,s):o(e,i))||s);return r>3&&s&&Object.defineProperty(e,i,s),s},o=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{c(n.next(t))}catch(t){r(t)}}function a(t){try{c(n.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const r=i(147),s=i(62),a=i(595),c=i(197),l=i(554);console.info(`%c ANDROID-TV-CARD v${r.version}`,"color: white; font-weight: bold; background: green"),window.customCards=window.customCards||[],window.customCards.push({type:"android-tv-card",name:"Android TV Card",description:"Remote for Android TV"});let u=class extends s.LitElement{constructor(){super(),this.defaultKeys=l.defaultKeys,this.defaultSources=l.defaultSources,this.customKeys={},this.customSources={},this.customIcons={},this.clickTimer=null,this.clickCount=0,this.touchAction="",this.touchTimer=null,this.touchInterval=null,this.touchLongClick=!1,this.holdAction="",this.holdTimer=null,this.holdInterval=null,this.holdLongClick=!1}static get properties(){return{_hass:{},_config:{},_apps:{}}}static getStubConfig(){return{}}getCardSize(){let t=this._config.rows.length;return"title"in this._config&&(t+=1),t}setConfig(t){var e;return o(this,void 0,void 0,(function*(){this._config=Object.assign({theme:"default"},t),this.customKeys=t.custom_keys||{},this.customSources=t.custom_sources||{},this.customIcons=t.custom_icons||{},this.defaultKeys=l.defaultKeys,this.defaultSources=l.defaultSources,this._config.alt_volume_icons&&this.useAltVolumeIcons(),this.convertToRowsArray(),yield window.loadCardHelpers(),(null===(e=this._config.rows)||void 0===e?void 0:e.toString().includes("volume_slider"))&&(yield this.renderVolumeSlider())}))}isButtonEnabled(t,e){return t.includes("_row")&&this._config[t].includes(e)}set hass(t){this._hass=t,this.volume_slider&&(this.volume_slider.hass=t)}get hass(){return this._hass}fireHapticEvent(t){(void 0===this._config.enable_button_feedback||this._config.enable_button_feedback)&&(0,c.forwardHaptic)(t)}renderVolumeSlider(){return o(this,void 0,void 0,(function*(){let t={type:"custom:my-slider",entity:this._config.media_player_id,height:"50px",mainSliderColor:"white",secondarySliderColor:"rgb(60, 60, 60)",mainSliderColorOff:"rgb(60, 60, 60)",secondarySliderColorOff:"rgb(60, 60, 60)",thumbWidth:"0px",thumbHorizontalPadding:"0px",radius:"25px"};this._config.slider_config instanceof Object&&(t=Object.assign(Object.assign({},t),this._config.slider_config));for(let e=0;e<5;e++)try{this.volume_slider=yield(0,c.createThing)(t,!0),this.volume_slider.setAttribute("style","flex: 0.9;")}catch(t){yield new Promise((t=>setTimeout(t,100)))}this.volume_slider.addEventListener("ontouchstart",(t=>{t.stopImmediatePropagation(),(null==this._config.enable_slider_feedback||this._config.enable_slider_feedback)&&(0,c.forwardHaptic)("selection")}),{passive:!0}),this.volume_slider.addEventListener("input",(t=>{(null==this._config.enable_slider_feedback||this._config.enable_slider_feedback)&&(0,c.forwardHaptic)("light")}),!0),this.volume_slider.hass=this._hass}))}useAltVolumeIcons(){this.defaultKeys.volume_up.icon="mdi:volume-high",this.defaultKeys.volume_down.icon="mdi:volume-medium",this.defaultKeys.volume_mute.icon="mdi:volume-variant-off"}convertToRowsArray(){if(!this._config.rows||!this._config.rows.length){const t=[],e=Object.keys(this._config).filter((t=>t.includes("_row")));for(const i of e){let e=this._config[i];"string"==typeof e&&(e=[e]),"volume_row"==i?e=["volume_"+e[0]]:"navigation_row"==i&&(e=["navigation_"+e[0]]),t.push(e)}this._config.rows=t}}sendKey(t,e=!1){const i={entity_id:this._config.remote_id,command:t};e&&(i.hold_secs=.5),this._hass.callService("remote","send_command",i)}getInfo(t){return this.customKeys[t]||this.customSources[t]||this.defaultKeys[t]||this.defaultSources[t]||{}}sendAction(t,e=!1){const i=this.getInfo(t);if("key"in i){const t=i.key;this.sendKey(t,e)}else if("source"in i)this.changeSource(i.source);else if("service"in i){const t=JSON.parse(JSON.stringify(i.service_data||{}));e&&"remote.send_command"==i.service&&(t.hold_secs=.5);const[n,o]=i.service.split(".",2);this._hass.callService(n,o,t)}}changeSource(t){this._hass.callService("remote","turn_on",{activity:t,entity_id:this._config.remote_id})}onTouchClick(t){t.stopImmediatePropagation();const e=()=>{clearTimeout(this.clickTimer),this.clickTimer=null,this.onButtonClick(t,"center",!1),this.clickCount=0};t.detail&&t.detail>this.clickCount&&this.clickCount++,this._config.enable_double_click?2==this.clickCount?this.onTouchDoubleClick(t):this.clickTimer=setTimeout(e,200):e()}onTouchDoubleClick(t){var e;clearTimeout(this.clickTimer),this.clickTimer=null,this.clickCount=0;const i=null!==(e=this._config.double_click_keycode)&&void 0!==e?e:"back";this.onButtonClick(t,i,!1)}onTouchStart(t){this.touchTimer=setTimeout((()=>{var e;this.touchLongClick=!0,["up","down","left","right"].includes(this.touchAction)?this.touchInterval=setInterval((()=>{this.onButtonClick(t,this.touchAction,!1)}),100):this.onButtonClick(t,null!==(e=this._config.long_click_keycode)&&void 0!==e?e:"center",!0)}),500),window.initialX=t.touches[0].clientX,window.initialY=t.touches[0].clientY}onTouchEnd(t){this.touchLongClick&&(this.touchLongClick=!1,t.stopImmediatePropagation(),t.preventDefault()),clearTimeout(this.touchTimer),clearInterval(this.touchInterval),clearTimeout(this.clickTimer),this.touchAction="",this.touchTimer=null,this.touchInterval=null,this.clickTimer=null}onTouchMove(t){if(!window.initialX||!window.initialY)return;const e=t.touches[0].clientX||0,i=t.touches[0].clientY||0,n=window.initialX-e,o=window.initialY-i;let r;r=Math.abs(n)>Math.abs(o)?n>0?"left":"right":o>0?"up":"down",this.touchAction=r,this.onButtonClick(t,r,!1),window.initialX=void 0,window.initialY=void 0}onButtonClick(t,e,i=!1){var n;e=e||(null===(n=t.currentTarget)||void 0===n?void 0:n.action)||"";const o=this.getInfo(e);let r=i?"medium":"light";switch(["up","down","left","right"].includes(e)?r="selection":(e==this._config.double_click_keycode||!this._config.double_click_keycode&&"back"==e)&&(r="success"),this.fireHapticEvent(r),"key"in o?o.key:""){case"KEYBOARD":this.onKeyboardPress(t,i);break;case"TEXTBOX":this.onTextboxPress(t,i);break;case"SEARCH":this.onSearchPress(t,i);break;default:this.sendAction(e,i)}}onButtonLongClickStart(t){this.holdAction=t.currentTarget.action,this.holdTimer=setTimeout((()=>{this.holdLongClick=!0,["up","down","left","right","volume_up","volume_down","delete"].includes(this.holdAction)?this.holdInterval=setInterval((()=>{this.onButtonClick(t,this.holdAction,!1)}),100):this.onButtonClick(t,this.holdAction,!0)}),500)}onButtonLongClickEnd(t){this.holdLongClick&&(this.holdLongClick=!1,t.stopImmediatePropagation(),t.preventDefault()),clearTimeout(this.holdTimer),clearInterval(this.holdInterval),this.holdAction="",this.holdTimer=null,this.holdInterval=null}onKeyDown(t){var e;t.stopImmediatePropagation();const i={Backspace:"delete",Delete:"forward_delete",Enter:"enter",ArrowLeft:"left",ArrowRight:"right"}[null!==(e=t.key)&&void 0!==e?e:""];i&&(""!=t.currentTarget.value&&(t.currentTarget.blur(),t.currentTarget.value="",t.currentTarget.focus()),this.sendAction(i))}onInput(t){if(t.stopImmediatePropagation(),t.data){const e={entity_id:this._config.adb_id,command:'input text "'+t.data+'"'};this._hass.callService("androidtv","adb_command",e)}}onPaste(t){var e;t.stopImmediatePropagation(),t.preventDefault();const i=null===(e=t.clipboardData)||void 0===e?void 0:e.getData("Text");if(i){const t={entity_id:this._config.adb_id,command:'input text "'+i+'"'};this._hass.callService("androidtv","adb_command",t)}t.currentTarget.blur(),t.currentTarget.value="",t.currentTarget.focus()}onFocus(t){t.currentTarget.value="",t.currentTarget.parentElement.children[0].style.color="var(--state-active-color)",t.currentTarget.style.zIndex="9",t.currentTarget.parentElement.style.zIndex="1"}onFocusOut(t){t.currentTarget.value="",t.currentTarget.parentElement.children[0].style.color="",t.currentTarget.style.zIndex="",t.currentTarget.parentElement.style.zIndex=""}onKeyboardPress(t,e){t.currentTarget.children[1].focus()}onTextboxPress(t,e){t.stopImmediatePropagation();const i=prompt("Text Input: ");if(i){const t={entity_id:this._config.adb_id,command:'input text "'+i+'"'};this._hass.callService("androidtv","adb_command",t)}}onSearchPress(t,e){t.stopImmediatePropagation();const i=prompt("Google Assistant Search: ");if(i){const t={entity_id:this._config.adb_id,command:'am start -a "android.search.action.GLOBAL_SEARCH" --es query "'+i+'"'};this._hass.callService("androidtv","adb_command",t)}}buildIconButton(t){var e,i,n,o,r;const a=this.getInfo(t);let c=null!==(e=null==a?void 0:a.icon)&&void 0!==e?e:"",l=null!==(n=null!==(i=a.svg_path)&&void 0!==i?i:this.customIcons[c])&&void 0!==n?n:"";if(!Object.keys(a).length)return s.html`
`;if(!c&&!l){const e=this.defaultKeys[t]||this.defaultSources[t]||{};c=null!==(o=null==e?void 0:e.icon)&&void 0!==o?o:"",l=null!==(r=null==e?void 0:e.svg_path)&&void 0!==r?r:""}let u=s.html``;return"key"in a&&"KEYBOARD"==a.key&&(u=s.html` +(()=>{"use strict";var t={197:(t,e,i)=>{i.r(e),i.d(e,{DEFAULT_DOMAIN_ICON:()=>G,DEFAULT_PANEL:()=>J,DEFAULT_VIEW_ENTITY_ID:()=>at,DOMAINS_HIDE_MORE_INFO:()=>et,DOMAINS_MORE_INFO_NO_HISTORY:()=>it,DOMAINS_TOGGLE:()=>ot,DOMAINS_WITH_CARD:()=>Q,DOMAINS_WITH_MORE_INFO:()=>tt,NumberFormat:()=>n,STATES_OFF:()=>nt,TimeFormat:()=>o,UNIT_C:()=>rt,UNIT_F:()=>st,applyThemesOnElement:()=>U,computeCardSize:()=>Z,computeDomain:()=>j,computeEntity:()=>F,computeRTL:()=>B,computeRTLDirection:()=>H,computeStateDisplay:()=>X,computeStateDomain:()=>V,createThing:()=>dt,debounce:()=>ht,domainIcon:()=>Ct,evaluateFilter:()=>pt,fireEvent:()=>ct,fixedIcons:()=>mt,formatDate:()=>u,formatDateMonth:()=>_,formatDateMonthYear:()=>f,formatDateNumeric:()=>h,formatDateShort:()=>C,formatDateTime:()=>w,formatDateTimeNumeric:()=>M,formatDateTimeWithSeconds:()=>A,formatDateWeekday:()=>c,formatDateYear:()=>y,formatNumber:()=>W,formatTime:()=>E,formatTimeWeekday:()=>D,formatTimeWithSeconds:()=>O,forwardHaptic:()=>ft,getLovelace:()=>Mt,handleAction:()=>Lt,handleActionConfig:()=>yt,handleClick:()=>bt,hasAction:()=>wt,hasConfigOrEntityChanged:()=>kt,hasDoubleClick:()=>At,isNumericState:()=>z,navigate:()=>vt,numberFormatToLocale:()=>K,relativeTime:()=>P,round:()=>q,stateIcon:()=>Tt,timerTimeRemaining:()=>N,toggleEntity:()=>gt,turnOnOffEntities:()=>$t,turnOnOffEntity:()=>_t});var n,o,r,s=function(){return s=Object.assign||function(t){for(var e,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 C=o/604800;return{value:Math.round(C),unit:"week"}}(t,i);return n?function(t){return new Intl.RelativeTimeFormat(t.language,{numeric:"auto"})}(e).format(o.value,o.unit):Intl.NumberFormat(e.language,{style:"unit",unit:o.unit,unitDisplay:"long"}).format(Math.abs(o.value))};function N(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(),o=new Date(t.last_changed).getTime();i=Math.max(i-(n-o)/1e3,0)}return i}function R(){return(R=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;i.minimumFractionDigits=n,i.maximumFractionDigits=n}return i},X=function(t,e,i,n){var o=void 0!==n?n:e.state;if("unknown"===o||"unavailable"===o)return t("state.default."+o);if(z(e)){if("monetary"===e.attributes.device_class)try{return W(o,i,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return W(o,i)+(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var r=V(e);if("input_datetime"===r){var s;if(void 0===n)return e.attributes.has_date&&e.attributes.has_time?(s=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),w(s,i)):e.attributes.has_date?(s=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),u(s,i)):e.attributes.has_time?((s=new Date).setHours(e.attributes.hour,e.attributes.minute),E(s,i)):e.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 E(new Date(c.toISOString().split("T")[0]+"T"+n),i)}}return n}catch(t){return n}}return"humidifier"===r&&"on"===o&&e.attributes.humidity?e.attributes.humidity+" %":"counter"===r||"number"===r||"input_number"===r?W(o,i):e.attributes.device_class&&t("component."+r+".state."+e.attributes.device_class+"."+o)||t("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"],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"],ot=new Set(["fan","input_boolean","light","switch","group","automation"]),rt="°C",st="°F",at="group.default_view",ct=function(t,e,i,n){n=n||{},i=null==i?{}:i;var o=new Event(e,{bubbles:void 0===n.bubbles||n.bubbles,cancelable:Boolean(n.cancelable),composed:void 0===n.composed||n.composed});return o.detail=i,t.dispatchEvent(o),o},lt=new Set(["call-service","divider","section","weblink","cast","select"]),ut={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 o=t.type;if(o&&o.startsWith("custom:"))o=o.substr(7);else if(e)if(lt.has(o))o="hui-"+o+"-row";else{if(!t.entity)return i("Invalid config given.",t);var r=t.entity.split(".",1)[0];o="hui-"+(ut[r]||"text")+"-entity-row"}else o="hui-"+o+"-card";if(customElements.get(o))return n(o,t);var s=i("Custom element doesn't exist: "+t.type+".",t);s.style.display="None";var a=setTimeout((function(){s.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(a),ct(s,"ll-rebuild",{},s)})),s},ht=function(t,e,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||t.apply(r,o)}),e),s&&t.apply(r,o)}},mt={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 Ct(t,e){if(t in mt)return mt[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}},ft=function(t){ct(window,"haptic",t)},vt=function(t,e,i){void 0===i&&(i=!1),i?history.replaceState(null,"",e):history.pushState(null,"",e),ct(window,"location-changed",{replace:i})},_t=function(t,e,i){void 0===i&&(i=!0);var n,o=j(e),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 t.callService(r,n,{entity_id:e})},gt=function(t,e){var i=nt.includes(t.states[e].state);return _t(t,e,i)},yt=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}))||(ft("warning"),confirm(n.confirmation.text||"Are you sure you want to "+n.action+"?")))switch(n.action){case"more-info":(i.entity||i.camera_image)&&ct(t,"hass-more-info",{entityId:i.entity?i.entity:i.camera_image});break;case"navigate":n.navigation_path&&vt(0,n.navigation_path);break;case"url":n.url_path&&window.open(n.url_path);break;case"toggle":i.entity&&(gt(e,i.entity),ft("success"));break;case"call-service":if(!n.service)return void ft("failure");var o=n.service.split(".",2);e.callService(o[0],o[1],n.service_data,n.target),ft("success");break;case"fire-dom-event":ct(t,"ll-custom",n)}},Lt=function(t,e,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),yt(t,e,i,o)},bt=function(t,e,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(t){return t.user===e.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)&&(ct(t,"hass-more-info",{entityId:r.entity?r.entity:i.entity?i.entity:i.camera_image}),r.haptic&&ft(r.haptic));break;case"navigate":r.navigation_path&&(vt(0,r.navigation_path),r.haptic&&ft(r.haptic));break;case"url":r.url_path&&window.open(r.url_path),r.haptic&&ft(r.haptic);break;case"toggle":i.entity&&(gt(e,i.entity),r.haptic&&ft(r.haptic));break;case"call-service":if(!r.service)return;var s=r.service.split(".",2),a=s[0],c=s[1],l=R({},r.service_data);"entity"===l.entity_id&&(l.entity_id=i.entity),e.callService(a,c,l,r.target),r.haptic&&ft(r.haptic);break;case"fire-dom-event":ct(t,"ll-custom",r),r.haptic&&ft(r.haptic)}};function wt(t){return void 0!==t&&"none"!==t.action}function kt(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 At(t){return void 0!==t&&"none"!==t.action}var $t=function(t,e,i){void 0===i&&(i=!0);var n={};e.forEach((function(e){if(nt.includes(t.states[e].state)===i){var o=j(e),r=["cover","lock"].includes(o)?o:"homeassistant";r in n||(n[r]=[]),n[r].push(e)}})),Object.keys(n).forEach((function(e){var o;switch(e){case"lock":o=i?"unlock":"lock";break;case"cover":o=i?"open_cover":"close_cover";break;default:o=i?"turn_on":"turn_off"}t.callService(e,o,{entity_id:n[e]})}))},Mt=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},St={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},Et={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 Ct("cover",t.state)}},sensor:function(t){var e=t.attributes.device_class;if(e&&e in St)return St[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 o=t.attributes.unit_of_measurement;return"°C"===o||"°F"===o?"mdi:thermometer":Ct("sensor")},input_datetime:function(t){return t.attributes.has_date?t.attributes.has_time?Ct("input_datetime"):"mdi:calendar":"mdi:clock"}},Tt=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=j(t.entity_id);return e in Et?Et[e](t):Ct(e,t.state)}},992:function(t,e,i){var n=this&&this.__decorate||function(t,e,i,n){var o,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(r<3?o(s):r>3?o(e,i,s):o(e,i))||s);return r>3&&s&&Object.defineProperty(e,i,s),s},o=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{c(n.next(t))}catch(t){r(t)}}function a(t){try{c(n.throw(t))}catch(t){r(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,a)}c((n=n.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const r=i(147),s=i(62),a=i(595),c=i(197),l=i(554);console.info(`%c ANDROID-TV-CARD v${r.version}`,"color: white; font-weight: bold; background: green"),window.customCards=window.customCards||[],window.customCards.push({type:"android-tv-card",name:"Android TV Card",description:"Remote for Android TV"});let u=class extends s.LitElement{constructor(){super(),this.defaultKeys=l.defaultKeys,this.defaultSources=l.defaultSources,this.customKeys={},this.customSources={},this.customIcons={},this.clickTimer=null,this.clickCount=0,this.touchAction="",this.touchTimer=null,this.touchInterval=null,this.touchLongClick=!1,this.holdAction="",this.holdTimer=null,this.holdInterval=null,this.holdLongClick=!1}static get properties(){return{_hass:{},_config:{},_apps:{}}}static getStubConfig(){return{}}getCardSize(){let t=this._config.rows.length;return"title"in this._config&&(t+=1),t}setConfig(t){var e;return o(this,void 0,void 0,(function*(){this._config=Object.assign({theme:"default"},t),this.customKeys=t.custom_keys||{},this.customSources=t.custom_sources||{},this.customIcons=t.custom_icons||{},this.defaultKeys=l.defaultKeys,this.defaultSources=l.defaultSources,this._config.alt_volume_icons&&this.useAltVolumeIcons(),this.convertToRowsArray(),yield window.loadCardHelpers(),(null===(e=this._config.rows)||void 0===e?void 0:e.toString().includes("volume_slider"))&&(yield this.renderVolumeSlider())}))}isButtonEnabled(t,e){return t.includes("_row")&&this._config[t].includes(e)}set hass(t){this._hass=t,this.volume_slider&&(this.volume_slider.hass=t)}get hass(){return this._hass}fireHapticEvent(t){(void 0===this._config.enable_button_feedback||this._config.enable_button_feedback)&&(0,c.forwardHaptic)(t)}renderVolumeSlider(){return o(this,void 0,void 0,(function*(){let t={type:"custom:my-slider",entity:this._config.media_player_id,height:"50px",mainSliderColor:"white",secondarySliderColor:"rgb(60, 60, 60)",mainSliderColorOff:"rgb(60, 60, 60)",secondarySliderColorOff:"rgb(60, 60, 60)",thumbWidth:"0px",thumbHorizontalPadding:"0px",radius:"25px"};this._config.slider_config instanceof Object&&(t=Object.assign(Object.assign({},t),this._config.slider_config));for(let e=0;e<10;e++)try{this.volume_slider=(0,c.createThing)(t,!0),this.volume_slider.setAttribute("style","flex: 0.9;")}catch(t){yield new Promise((t=>setTimeout(t,100)))}this.volume_slider.addEventListener("ontouchstart",(t=>{t.stopImmediatePropagation(),(null==this._config.enable_slider_feedback||this._config.enable_slider_feedback)&&(0,c.forwardHaptic)("selection")}),{passive:!0}),this.volume_slider.addEventListener("input",(t=>{(null==this._config.enable_slider_feedback||this._config.enable_slider_feedback)&&(0,c.forwardHaptic)("light")}),!0),this.volume_slider.hass=this._hass}))}useAltVolumeIcons(){this.defaultKeys.volume_up.icon="mdi:volume-high",this.defaultKeys.volume_down.icon="mdi:volume-medium",this.defaultKeys.volume_mute.icon="mdi:volume-variant-off"}convertToRowsArray(){if(!this._config.rows||!this._config.rows.length){const t=[],e=Object.keys(this._config).filter((t=>t.includes("_row")));for(const i of e){let e=this._config[i];"string"==typeof e&&(e=[e]),"volume_row"==i?e=["volume_"+e[0]]:"navigation_row"==i&&(e=["navigation_"+e[0]]),t.push(e)}this._config.rows=t}}sendKey(t,e=!1){const i={entity_id:this._config.remote_id,command:t};e&&(i.hold_secs=.5),this._hass.callService("remote","send_command",i)}getInfo(t){return this.customKeys[t]||this.customSources[t]||this.defaultKeys[t]||this.defaultSources[t]||{}}sendAction(t,e=!1){const i=this.getInfo(t);if("key"in i){const t=i.key;this.sendKey(t,e)}else if("source"in i)this.changeSource(i.source);else if("service"in i){const t=JSON.parse(JSON.stringify(i.service_data||{}));e&&"remote.send_command"==i.service&&(t.hold_secs=.5);const[n,o]=i.service.split(".",2);this._hass.callService(n,o,t)}}changeSource(t){this._hass.callService("remote","turn_on",{activity:t,entity_id:this._config.remote_id})}onTouchClick(t){t.stopImmediatePropagation();const e=()=>{clearTimeout(this.clickTimer),this.clickTimer=null,this.onButtonClick(t,"center",!1),this.clickCount=0};t.detail&&t.detail>this.clickCount&&this.clickCount++,this._config.enable_double_click?2==this.clickCount?this.onTouchDoubleClick(t):this.clickTimer=setTimeout(e,200):e()}onTouchDoubleClick(t){var e;clearTimeout(this.clickTimer),this.clickTimer=null,this.clickCount=0;const i=null!==(e=this._config.double_click_keycode)&&void 0!==e?e:"back";this.onButtonClick(t,i,!1)}onTouchStart(t){this.touchTimer=setTimeout((()=>{var e;this.touchLongClick=!0,["up","down","left","right"].includes(this.touchAction)?this.touchInterval=setInterval((()=>{this.onButtonClick(t,this.touchAction,!1)}),100):this.onButtonClick(t,null!==(e=this._config.long_click_keycode)&&void 0!==e?e:"center",!0)}),500),window.initialX=t.touches[0].clientX,window.initialY=t.touches[0].clientY}onTouchEnd(t){this.touchLongClick&&(this.touchLongClick=!1,t.stopImmediatePropagation(),t.preventDefault()),clearTimeout(this.touchTimer),clearInterval(this.touchInterval),clearTimeout(this.clickTimer),this.touchAction="",this.touchTimer=null,this.touchInterval=null,this.clickTimer=null}onTouchMove(t){if(!window.initialX||!window.initialY)return;const e=t.touches[0].clientX||0,i=t.touches[0].clientY||0,n=window.initialX-e,o=window.initialY-i;let r;r=Math.abs(n)>Math.abs(o)?n>0?"left":"right":o>0?"up":"down",this.touchAction=r,this.onButtonClick(t,r,!1),window.initialX=void 0,window.initialY=void 0}onButtonClick(t,e,i=!1){var n;e=e||(null===(n=t.currentTarget)||void 0===n?void 0:n.action)||"";const o=this.getInfo(e);let r=i?"medium":"light";switch(["up","down","left","right"].includes(e)?r="selection":(e==this._config.double_click_keycode||!this._config.double_click_keycode&&"back"==e)&&(r="success"),this.fireHapticEvent(r),"key"in o?o.key:""){case"KEYBOARD":this.onKeyboardPress(t,i);break;case"TEXTBOX":this.onTextboxPress(t,i);break;case"SEARCH":this.onSearchPress(t,i);break;default:this.sendAction(e,i)}}onButtonLongClickStart(t){this.holdAction=t.currentTarget.action,this.holdTimer=setTimeout((()=>{this.holdLongClick=!0,["up","down","left","right","volume_up","volume_down","delete"].includes(this.holdAction)?this.holdInterval=setInterval((()=>{this.onButtonClick(t,this.holdAction,!1)}),100):this.onButtonClick(t,this.holdAction,!0)}),500)}onButtonLongClickEnd(t){this.holdLongClick&&(this.holdLongClick=!1,t.stopImmediatePropagation(),t.preventDefault()),clearTimeout(this.holdTimer),clearInterval(this.holdInterval),this.holdAction="",this.holdTimer=null,this.holdInterval=null}onKeyDown(t){var e;t.stopImmediatePropagation();const i={Backspace:"delete",Delete:"forward_delete",Enter:"enter",ArrowLeft:"left",ArrowRight:"right"}[null!==(e=t.key)&&void 0!==e?e:""];i&&(""!=t.currentTarget.value&&(t.currentTarget.blur(),t.currentTarget.value="",t.currentTarget.focus()),this.sendAction(i))}onInput(t){if(t.stopImmediatePropagation(),t.data){const e={entity_id:this._config.adb_id,command:'input text "'+t.data+'"'};this._hass.callService("androidtv","adb_command",e)}}onPaste(t){var e;t.stopImmediatePropagation(),t.preventDefault();const i=null===(e=t.clipboardData)||void 0===e?void 0:e.getData("Text");if(i){const t={entity_id:this._config.adb_id,command:'input text "'+i+'"'};this._hass.callService("androidtv","adb_command",t)}t.currentTarget.blur(),t.currentTarget.value="",t.currentTarget.focus()}onFocus(t){t.currentTarget.value="",t.currentTarget.parentElement.children[0].style.color="var(--state-active-color)",t.currentTarget.style.zIndex="9",t.currentTarget.parentElement.style.zIndex="1"}onFocusOut(t){t.currentTarget.value="",t.currentTarget.parentElement.children[0].style.color="",t.currentTarget.style.zIndex="",t.currentTarget.parentElement.style.zIndex=""}onKeyboardPress(t,e){t.currentTarget.children[1].focus()}onTextboxPress(t,e){t.stopImmediatePropagation();const i=prompt("Text Input: ");if(i){const t={entity_id:this._config.adb_id,command:'input text "'+i+'"'};this._hass.callService("androidtv","adb_command",t)}}onSearchPress(t,e){t.stopImmediatePropagation();const i=prompt("Google Assistant Search: ");if(i){const t={entity_id:this._config.adb_id,command:'am start -a "android.search.action.GLOBAL_SEARCH" --es query "'+i+'"'};this._hass.callService("androidtv","adb_command",t)}}buildIconButton(t){var e,i,n,o,r;const a=this.getInfo(t);let c=null!==(e=null==a?void 0:a.icon)&&void 0!==e?e:"",l=null!==(n=null!==(i=a.svg_path)&&void 0!==i?i:this.customIcons[c])&&void 0!==n?n:"";if(!Object.keys(a).length)return s.html`
`;if(!c&&!l){const e=this.defaultKeys[t]||this.defaultSources[t]||{};c=null!==(o=null==e?void 0:e.icon)&&void 0!==o?o:"",l=null!==(r=null==e?void 0:e.svg_path)&&void 0!==r?r:""}let u=s.html``;return"key"in a&&"KEYBOARD"==a.key&&(u=s.html` setTimeout(resolve, 100));