diff --git a/README.md b/README.md index dcb2bfe..c923f58 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ or added by clicking the "Add to lovelace" button on the HACS dashboard after in | translations | dictionary | _[translations](#Translations)_ | Dictionary to override the default translation | | actions | object | _[Actions](#actions)_ | The tap, double tap or hold actions set on the image of the countdown, last_result, results, qualifying_results and next-race cards | | row_limit | number | | Limit the schedule, results, last_result, driver_standings and constructor_standings to this amount of row | +| countdown_type | string | 'race' | Set the event to countdown to (race,qualifying,practice1,practice2,practice3,sprint) | ### Actions diff --git a/formulaone-card.js b/formulaone-card.js index 421cfd1..48b0e9f 100644 --- a/formulaone-card.js +++ b/formulaone-card.js @@ -1,5 +1,5 @@ /*! For license information please see formulaone-card.js.LICENSE.txt */ -(()=>{"use strict";var t={197:(t,e,n)=>{n.r(e),n.d(e,{DEFAULT_DOMAIN_ICON:()=>J,DEFAULT_PANEL:()=>K,DEFAULT_VIEW_ENTITY_ID:()=>st,DOMAINS_HIDE_MORE_INFO:()=>et,DOMAINS_MORE_INFO_NO_HISTORY:()=>nt,DOMAINS_TOGGLE:()=>rt,DOMAINS_WITH_CARD:()=>Z,DOMAINS_WITH_MORE_INFO:()=>tt,NumberFormat:()=>i,STATES_OFF:()=>it,TimeFormat:()=>r,UNIT_C:()=>at,UNIT_F:()=>ot,applyThemesOnElement:()=>L,computeCardSize:()=>j,computeDomain:()=>H,computeEntity:()=>U,computeRTL:()=>B,computeRTLDirection:()=>G,computeStateDisplay:()=>W,computeStateDomain:()=>V,createThing:()=>ut,debounce:()=>ht,domainIcon:()=>pt,evaluateFilter:()=>ft,fireEvent:()=>ct,fixedIcons:()=>mt,formatDate:()=>d,formatDateMonth:()=>y,formatDateMonthYear:()=>g,formatDateNumeric:()=>h,formatDateShort:()=>p,formatDateTime:()=>S,formatDateTimeNumeric:()=>D,formatDateTimeWithSeconds:()=>A,formatDateWeekday:()=>c,formatDateYear:()=>b,formatNumber:()=>X,formatTime:()=>x,formatTimeWeekday:()=>M,formatTimeWithSeconds:()=>E,forwardHaptic:()=>gt,getLovelace:()=>Dt,handleAction:()=>$t,handleActionConfig:()=>bt,handleClick:()=>wt,hasAction:()=>St,hasConfigOrEntityChanged:()=>Ct,hasDoubleClick:()=>At,isNumericState:()=>q,navigate:()=>vt,numberFormatToLocale:()=>z,relativeTime:()=>P,round:()=>Q,stateIcon:()=>kt,timerTimeRemaining:()=>I,toggleEntity:()=>_t,turnOnOffEntities:()=>Tt,turnOnOffEntity:()=>yt});var i,r,a,o=function(){return o=Object.assign||function(t){for(var e,n=1,i=arguments.length;n0)return{value:Math.round(h),unit:"year"};var m=12*h+d.getMonth()-u.getMonth();if(Math.round(Math.abs(m))>0)return{value:Math.round(m),unit:"month"};var p=r/604800;return{value:Math.round(p),unit:"week"}}(t,n);return i?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 I(t){var e,n=3600*(e=t.attributes.remaining.split(":").map(Number))[0]+60*e[1]+e[2];if("active"===t.state){var i=(new Date).getTime(),r=new Date(t.last_changed).getTime();n=Math.max(n-(i-r)/1e3,0)}return n}function F(){return(F=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;n.minimumFractionDigits=i,n.maximumFractionDigits=i}return n},W=function(t,e,n,i){var r=void 0!==i?i:e.state;if("unknown"===r||"unavailable"===r)return t("state.default."+r);if(q(e)){if("monetary"===e.attributes.device_class)try{return X(r,n,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return X(r,n)+(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var a=V(e);if("input_datetime"===a){var o;if(void 0===i)return e.attributes.has_date&&e.attributes.has_time?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),S(o,n)):e.attributes.has_date?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),d(o,n)):e.attributes.has_time?((o=new Date).setHours(e.attributes.hour,e.attributes.minute),x(o,n)):e.state;try{var s=i.split(" ");if(2===s.length)return S(new Date(s.join("T")),n);if(1===s.length){if(i.includes("-"))return d(new Date(i+"T00:00"),n);if(i.includes(":")){var c=new Date;return x(new Date(c.toISOString().split("T")[0]+"T"+i),n)}}return i}catch(t){return i}}return"humidifier"===a&&"on"===r&&e.attributes.humidity?e.attributes.humidity+" %":"counter"===a||"number"===a||"input_number"===a?X(r,n):e.attributes.device_class&&t("component."+a+".state."+e.attributes.device_class+"."+r)||t("component."+a+".state._."+r)||r},J="mdi:bookmark",K="lovelace",Z=["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"],nt=["camera","configurator","history_graph","scene"],it=["closed","locked","off"],rt=new Set(["fan","input_boolean","light","switch","group","automation"]),at="°C",ot="°F",st="group.default_view",ct=function(t,e,n,i){i=i||{},n=null==n?{}:n;var r=new Event(e,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return r.detail=n,t.dispatchEvent(r),r},lt=new Set(["call-service","divider","section","weblink","cast","select"]),dt={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"},ut=function(t,e){void 0===e&&(e=!1);var n=function(t,e){return i("hui-error-card",{type:"error",error:t,config:e})},i=function(t,e){var i=window.document.createElement(t);try{if(!i.setConfig)return;i.setConfig(e)}catch(i){return console.error(t,i),n(i.message,e)}return i};if(!t||"object"!=typeof t||!e&&!t.type)return n("No type defined",t);var r=t.type;if(r&&r.startsWith("custom:"))r=r.substr("custom:".length);else if(e)if(lt.has(r))r="hui-"+r+"-row";else{if(!t.entity)return n("Invalid config given.",t);var a=t.entity.split(".",1)[0];r="hui-"+(dt[a]||"text")+"-entity-row"}else r="hui-"+r+"-card";if(customElements.get(r))return i(r,t);var o=n("Custom element doesn't exist: "+t.type+".",t);o.style.display="None";var s=setTimeout((function(){o.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(s),ct(o,"ll-rebuild",{},o)})),o},ht=function(t,e,n){var i;return void 0===n&&(n=!1),function(){var r=[].slice.call(arguments),a=this,o=function(){i=null,n||t.apply(a,r)},s=n&&!i;clearTimeout(i),i=setTimeout(o,e),s&&t.apply(a,r)}},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 pt(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 ft=function(t,e){var n=e.value||e,i=e.attribute?t.attributes[e.attribute]:t.state;switch(e.operator||"=="){case"==":return i===n;case"<=":return i<=n;case"<":return i=":return i>=n;case">":return i>n;case"!=":return i!==n;case"regex":return i.match(n);default:return!1}},gt=function(t){ct(window,"haptic",t)},vt=function(t,e,n){void 0===n&&(n=!1),n?history.replaceState(null,"",e):history.pushState(null,"",e),ct(window,"location-changed",{replace:n})},yt=function(t,e,n){void 0===n&&(n=!0);var i,r=H(e),a="group"===r?"homeassistant":r;switch(r){case"lock":i=n?"unlock":"lock";break;case"cover":i=n?"open_cover":"close_cover";break;default:i=n?"turn_on":"turn_off"}return t.callService(a,i,{entity_id:e})},_t=function(t,e){var n=it.includes(t.states[e].state);return yt(t,e,n)},bt=function(t,e,n,i){if(i||(i={action:"more-info"}),!i.confirmation||i.confirmation.exemptions&&i.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||(gt("warning"),confirm(i.confirmation.text||"Are you sure you want to "+i.action+"?")))switch(i.action){case"more-info":(n.entity||n.camera_image)&&ct(t,"hass-more-info",{entityId:n.entity?n.entity:n.camera_image});break;case"navigate":i.navigation_path&&vt(0,i.navigation_path);break;case"url":i.url_path&&window.open(i.url_path);break;case"toggle":n.entity&&(_t(e,n.entity),gt("success"));break;case"call-service":if(!i.service)return void gt("failure");var r=i.service.split(".",2);e.callService(r[0],r[1],i.service_data,i.target),gt("success");break;case"fire-dom-event":ct(t,"ll-custom",i)}},$t=function(t,e,n,i){var r;"double_tap"===i&&n.double_tap_action?r=n.double_tap_action:"hold"===i&&n.hold_action?r=n.hold_action:"tap"===i&&n.tap_action&&(r=n.tap_action),bt(t,e,n,r)},wt=function(t,e,n,i,r){var a;if(r&&n.double_tap_action?a=n.double_tap_action:i&&n.hold_action?a=n.hold_action:!i&&n.tap_action&&(a=n.tap_action),a||(a={action:"more-info"}),!a.confirmation||a.confirmation.exemptions&&a.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||confirm(a.confirmation.text||"Are you sure you want to "+a.action+"?"))switch(a.action){case"more-info":(a.entity||n.entity||n.camera_image)&&(ct(t,"hass-more-info",{entityId:a.entity?a.entity:n.entity?n.entity:n.camera_image}),a.haptic&>(a.haptic));break;case"navigate":a.navigation_path&&(vt(0,a.navigation_path),a.haptic&>(a.haptic));break;case"url":a.url_path&&window.open(a.url_path),a.haptic&>(a.haptic);break;case"toggle":n.entity&&(_t(e,n.entity),a.haptic&>(a.haptic));break;case"call-service":if(!a.service)return;var o=a.service.split(".",2),s=o[0],c=o[1],l=F({},a.service_data);"entity"===l.entity_id&&(l.entity_id=n.entity),e.callService(s,c,l,a.target),a.haptic&>(a.haptic);break;case"fire-dom-event":ct(t,"ll-custom",a),a.haptic&>(a.haptic)}};function St(t){return void 0!==t&&"none"!==t.action}function Ct(t,e,n){if(e.has("config")||n)return!0;if(t.config.entity){var i=e.get("hass");return!i||i.states[t.config.entity]!==t.hass.states[t.config.entity]}return!1}function At(t){return void 0!==t&&"none"!==t.action}var Tt=function(t,e,n){void 0===n&&(n=!0);var i={};e.forEach((function(e){if(it.includes(t.states[e].state)===n){var r=H(e),a=["cover","lock"].includes(r)?r:"homeassistant";a in i||(i[a]=[]),i[a].push(e)}})),Object.keys(i).forEach((function(e){var r;switch(e){case"lock":r=n?"unlock":"lock";break;case"cover":r=n?"open_cover":"close_cover";break;default:r=n?"turn_on":"turn_off"}t.callService(e,r,{entity_id:i[e]})}))},Dt=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},Rt={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},xt={binary_sensor:function(t,e){var n="off"===t;switch(null==e?void 0:e.attributes.device_class){case"battery":return n?"mdi:battery":"mdi:battery-outline";case"battery_charging":return n?"mdi:battery":"mdi:battery-charging";case"cold":return n?"mdi:thermometer":"mdi:snowflake";case"connectivity":return n?"mdi:server-network-off":"mdi:server-network";case"door":return n?"mdi:door-closed":"mdi:door-open";case"garage_door":return n?"mdi:garage":"mdi:garage-open";case"power":case"plug":return n?"mdi:power-plug-off":"mdi:power-plug";case"gas":case"problem":case"safety":case"tamper":return n?"mdi:check-circle":"mdi:alert-circle";case"smoke":return n?"mdi:check-circle":"mdi:smoke";case"heat":return n?"mdi:thermometer":"mdi:fire";case"light":return n?"mdi:brightness-5":"mdi:brightness-7";case"lock":return n?"mdi:lock":"mdi:lock-open";case"moisture":return n?"mdi:water-off":"mdi:water";case"motion":return n?"mdi:walk":"mdi:run";case"occupancy":case"presence":return n?"mdi:home-outline":"mdi:home";case"opening":return n?"mdi:square":"mdi:square-outline";case"running":return n?"mdi:stop":"mdi:play";case"sound":return n?"mdi:music-note-off":"mdi:music-note";case"update":return n?"mdi:package":"mdi:package-up";case"vibration":return n?"mdi:crop-portrait":"mdi:vibrate";case"window":return n?"mdi:window-closed":"mdi:window-open";default:return n?"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 Rt)return Rt[e];if("battery"===e){var n=Number(t.state);if(isNaN(n))return"mdi:battery-unknown";var i=10*Math.round(n/10);return i>=100?"mdi:battery":i<=0?"mdi:battery-alert":"hass:battery-"+i}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"}},kt=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=H(t.entity_id);return e in xt?xt[e](t):pt(e,t.state)}},239:function(t,e){var n=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function o(t){try{c(i.next(t))}catch(t){a(t)}}function s(t){try{c(i.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.ClientBase=void 0,e.ClientBase=class{GetData(t,e,i){return n(this,void 0,void 0,(function*(){const n=localStorage.getItem(t);if(n&&e){const t=JSON.parse(n),e=new Date;if(e.setHours(e.getHours()-i),new Date(t.created)>e)return JSON.parse(t.data)}const r=yield fetch(`${this.baseUrl}/${t}`,{headers:{Accept:"application/json"}}),a=yield r.json(),o={data:JSON.stringify(a),created:new Date};return e&&localStorage.setItem(t,JSON.stringify(o)),a}))}}},171:function(t,e,n){var i=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function o(t){try{c(i.next(t))}catch(t){a(t)}}function s(t){try{c(i.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const r=n(593),a=n(239);class o extends a.ClientBase{constructor(){super(...arguments),this.baseUrl="https://ergast.com/api/f1"}GetSchedule(t){return i(this,void 0,void 0,(function*(){const e=yield this.GetData(`${t}.json`,!0,72);return null==e?void 0:e.MRData.RaceTable.Races}))}GetLastResult(){return i(this,void 0,void 0,(function*(){const t=(0,r.getRefreshTime)("current/last/results.json"),e=yield this.GetData("current/last/results.json",!0,t);return null==e?void 0:e.MRData.RaceTable.Races[0]}))}GetDriverStandings(){return i(this,void 0,void 0,(function*(){const t=(0,r.getRefreshTime)("current/driverStandings.json"),e=yield this.GetData("current/driverStandings.json",!0,t);return null==e?void 0:e.MRData.StandingsTable.StandingsLists[0].DriverStandings}))}GetConstructorStandings(){return i(this,void 0,void 0,(function*(){const t=(0,r.getRefreshTime)("current/constructorStandings.json"),e=yield this.GetData("current/constructorStandings.json",!0,t);return null==e?void 0:e.MRData.StandingsTable.StandingsLists[0].ConstructorStandings}))}GetSprintResults(t,e){return i(this,void 0,void 0,(function*(){const n=yield this.GetData(`${t}/${e}/sprint.json`,!1,0);return null==n?void 0:n.MRData.RaceTable}))}GetQualifyingResults(t,e){return i(this,void 0,void 0,(function*(){const n=yield this.GetData(`${t}/${e}/qualifying.json`,!1,0);return null==n?void 0:n.MRData.RaceTable}))}GetResults(t,e){return i(this,void 0,void 0,(function*(){const n=yield this.GetData(`${t}/${e}/results.json`,!1,0);return null==n?void 0:n.MRData.RaceTable}))}GetSeasons(){return i(this,void 0,void 0,(function*(){const t=yield this.GetData("seasons.json?limit=200",!0,72);return null==t?void 0:t.MRData.SeasonTable.Seasons}))}GetSeasonRaces(t){return i(this,void 0,void 0,(function*(){return(yield this.GetData(`${t}.json`,!0,72)).MRData.RaceTable.Races}))}}e.default=o},930:function(t,e,n){var i=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function o(t){try{c(i.next(t))}catch(t){a(t)}}function s(t){try{c(i.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const r=n(239);class a extends r.ClientBase{constructor(){super(...arguments),this.baseUrl="https://restcountries.com/v2"}GetAll(){return i(this,void 0,void 0,(function*(){return yield this.GetData("all",!0,730)}))}GetCountriesFromLocalStorage(){const t=localStorage.getItem("all");if(t){const e=JSON.parse(t);return JSON.parse(e.data)}return[]}}e.default=a},243:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BaseCard=void 0;const i=n(171);e.BaseCard=class{constructor(t){this.config=t.config,this.client=new i.default,this.hass=t._hass,this.parent=t}translation(t){return!this.config.translations||Object.keys(this.config.translations).indexOf(t)<0?this.defaultTranslations[t]:this.config.translations[t]}getProperties(){var t,e;const n=null===(t=this.parent.properties)||void 0===t?void 0:t.get("cardValues");return{races:null==n?void 0:n.races,selectedRace:null==n?void 0:n.selectedRace,selectedSeason:null==n?void 0:n.selectedSeason,selectedTabIndex:null!==(e=null==n?void 0:n.selectedTabIndex)&&void 0!==e?e:0}}getParentCardValues(){var t,e;const n=null!==(t=this.parent.properties)&&void 0!==t?t:new Map;return{properties:null!==(e=n.get("cardValues"))&&void 0!==e?e:{},cardValues:n}}}},521:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=n(692),r=n(345),a=n(593),o=n(243);class s extends o.BaseCard{constructor(t){super(t),this.defaultTranslations={constructor:"Constructor",points:"Pts",wins:"Wins"}}cardSize(){return 11}renderStandingRow(t){var e;return i.html` +(()=>{"use strict";var t={197:(t,e,n)=>{n.r(e),n.d(e,{DEFAULT_DOMAIN_ICON:()=>J,DEFAULT_PANEL:()=>K,DEFAULT_VIEW_ENTITY_ID:()=>st,DOMAINS_HIDE_MORE_INFO:()=>et,DOMAINS_MORE_INFO_NO_HISTORY:()=>nt,DOMAINS_TOGGLE:()=>rt,DOMAINS_WITH_CARD:()=>Z,DOMAINS_WITH_MORE_INFO:()=>tt,NumberFormat:()=>i,STATES_OFF:()=>it,TimeFormat:()=>r,UNIT_C:()=>at,UNIT_F:()=>ot,applyThemesOnElement:()=>L,computeCardSize:()=>j,computeDomain:()=>H,computeEntity:()=>U,computeRTL:()=>B,computeRTLDirection:()=>G,computeStateDisplay:()=>W,computeStateDomain:()=>q,createThing:()=>ut,debounce:()=>ht,domainIcon:()=>pt,evaluateFilter:()=>ft,fireEvent:()=>ct,fixedIcons:()=>mt,formatDate:()=>d,formatDateMonth:()=>y,formatDateMonthYear:()=>g,formatDateNumeric:()=>h,formatDateShort:()=>p,formatDateTime:()=>S,formatDateTimeNumeric:()=>D,formatDateTimeWithSeconds:()=>A,formatDateWeekday:()=>c,formatDateYear:()=>b,formatNumber:()=>X,formatTime:()=>x,formatTimeWeekday:()=>N,formatTimeWithSeconds:()=>E,forwardHaptic:()=>gt,getLovelace:()=>Dt,handleAction:()=>$t,handleActionConfig:()=>bt,handleClick:()=>wt,hasAction:()=>St,hasConfigOrEntityChanged:()=>Ct,hasDoubleClick:()=>At,isNumericState:()=>V,navigate:()=>vt,numberFormatToLocale:()=>z,relativeTime:()=>P,round:()=>Q,stateIcon:()=>kt,timerTimeRemaining:()=>I,toggleEntity:()=>_t,turnOnOffEntities:()=>Tt,turnOnOffEntity:()=>yt});var i,r,a,o=function(){return o=Object.assign||function(t){for(var e,n=1,i=arguments.length;n0)return{value:Math.round(h),unit:"year"};var m=12*h+d.getMonth()-u.getMonth();if(Math.round(Math.abs(m))>0)return{value:Math.round(m),unit:"month"};var p=r/604800;return{value:Math.round(p),unit:"week"}}(t,n);return i?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 I(t){var e,n=3600*(e=t.attributes.remaining.split(":").map(Number))[0]+60*e[1]+e[2];if("active"===t.state){var i=(new Date).getTime(),r=new Date(t.last_changed).getTime();n=Math.max(n-(i-r)/1e3,0)}return n}function F(){return(F=Object.assign||function(t){for(var e=1;e-1?t.split(".")[1].length:0;n.minimumFractionDigits=i,n.maximumFractionDigits=i}return n},W=function(t,e,n,i){var r=void 0!==i?i:e.state;if("unknown"===r||"unavailable"===r)return t("state.default."+r);if(V(e)){if("monetary"===e.attributes.device_class)try{return X(r,n,{style:"currency",currency:e.attributes.unit_of_measurement})}catch(t){}return X(r,n)+(e.attributes.unit_of_measurement?" "+e.attributes.unit_of_measurement:"")}var a=q(e);if("input_datetime"===a){var o;if(void 0===i)return e.attributes.has_date&&e.attributes.has_time?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day,e.attributes.hour,e.attributes.minute),S(o,n)):e.attributes.has_date?(o=new Date(e.attributes.year,e.attributes.month-1,e.attributes.day),d(o,n)):e.attributes.has_time?((o=new Date).setHours(e.attributes.hour,e.attributes.minute),x(o,n)):e.state;try{var s=i.split(" ");if(2===s.length)return S(new Date(s.join("T")),n);if(1===s.length){if(i.includes("-"))return d(new Date(i+"T00:00"),n);if(i.includes(":")){var c=new Date;return x(new Date(c.toISOString().split("T")[0]+"T"+i),n)}}return i}catch(t){return i}}return"humidifier"===a&&"on"===r&&e.attributes.humidity?e.attributes.humidity+" %":"counter"===a||"number"===a||"input_number"===a?X(r,n):e.attributes.device_class&&t("component."+a+".state."+e.attributes.device_class+"."+r)||t("component."+a+".state._."+r)||r},J="mdi:bookmark",K="lovelace",Z=["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"],nt=["camera","configurator","history_graph","scene"],it=["closed","locked","off"],rt=new Set(["fan","input_boolean","light","switch","group","automation"]),at="°C",ot="°F",st="group.default_view",ct=function(t,e,n,i){i=i||{},n=null==n?{}:n;var r=new Event(e,{bubbles:void 0===i.bubbles||i.bubbles,cancelable:Boolean(i.cancelable),composed:void 0===i.composed||i.composed});return r.detail=n,t.dispatchEvent(r),r},lt=new Set(["call-service","divider","section","weblink","cast","select"]),dt={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"},ut=function(t,e){void 0===e&&(e=!1);var n=function(t,e){return i("hui-error-card",{type:"error",error:t,config:e})},i=function(t,e){var i=window.document.createElement(t);try{if(!i.setConfig)return;i.setConfig(e)}catch(i){return console.error(t,i),n(i.message,e)}return i};if(!t||"object"!=typeof t||!e&&!t.type)return n("No type defined",t);var r=t.type;if(r&&r.startsWith("custom:"))r=r.substr("custom:".length);else if(e)if(lt.has(r))r="hui-"+r+"-row";else{if(!t.entity)return n("Invalid config given.",t);var a=t.entity.split(".",1)[0];r="hui-"+(dt[a]||"text")+"-entity-row"}else r="hui-"+r+"-card";if(customElements.get(r))return i(r,t);var o=n("Custom element doesn't exist: "+t.type+".",t);o.style.display="None";var s=setTimeout((function(){o.style.display=""}),2e3);return customElements.whenDefined(t.type).then((function(){clearTimeout(s),ct(o,"ll-rebuild",{},o)})),o},ht=function(t,e,n){var i;return void 0===n&&(n=!1),function(){var r=[].slice.call(arguments),a=this,o=function(){i=null,n||t.apply(a,r)},s=n&&!i;clearTimeout(i),i=setTimeout(o,e),s&&t.apply(a,r)}},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 pt(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 ft=function(t,e){var n=e.value||e,i=e.attribute?t.attributes[e.attribute]:t.state;switch(e.operator||"=="){case"==":return i===n;case"<=":return i<=n;case"<":return i=":return i>=n;case">":return i>n;case"!=":return i!==n;case"regex":return i.match(n);default:return!1}},gt=function(t){ct(window,"haptic",t)},vt=function(t,e,n){void 0===n&&(n=!1),n?history.replaceState(null,"",e):history.pushState(null,"",e),ct(window,"location-changed",{replace:n})},yt=function(t,e,n){void 0===n&&(n=!0);var i,r=H(e),a="group"===r?"homeassistant":r;switch(r){case"lock":i=n?"unlock":"lock";break;case"cover":i=n?"open_cover":"close_cover";break;default:i=n?"turn_on":"turn_off"}return t.callService(a,i,{entity_id:e})},_t=function(t,e){var n=it.includes(t.states[e].state);return yt(t,e,n)},bt=function(t,e,n,i){if(i||(i={action:"more-info"}),!i.confirmation||i.confirmation.exemptions&&i.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||(gt("warning"),confirm(i.confirmation.text||"Are you sure you want to "+i.action+"?")))switch(i.action){case"more-info":(n.entity||n.camera_image)&&ct(t,"hass-more-info",{entityId:n.entity?n.entity:n.camera_image});break;case"navigate":i.navigation_path&&vt(0,i.navigation_path);break;case"url":i.url_path&&window.open(i.url_path);break;case"toggle":n.entity&&(_t(e,n.entity),gt("success"));break;case"call-service":if(!i.service)return void gt("failure");var r=i.service.split(".",2);e.callService(r[0],r[1],i.service_data,i.target),gt("success");break;case"fire-dom-event":ct(t,"ll-custom",i)}},$t=function(t,e,n,i){var r;"double_tap"===i&&n.double_tap_action?r=n.double_tap_action:"hold"===i&&n.hold_action?r=n.hold_action:"tap"===i&&n.tap_action&&(r=n.tap_action),bt(t,e,n,r)},wt=function(t,e,n,i,r){var a;if(r&&n.double_tap_action?a=n.double_tap_action:i&&n.hold_action?a=n.hold_action:!i&&n.tap_action&&(a=n.tap_action),a||(a={action:"more-info"}),!a.confirmation||a.confirmation.exemptions&&a.confirmation.exemptions.some((function(t){return t.user===e.user.id}))||confirm(a.confirmation.text||"Are you sure you want to "+a.action+"?"))switch(a.action){case"more-info":(a.entity||n.entity||n.camera_image)&&(ct(t,"hass-more-info",{entityId:a.entity?a.entity:n.entity?n.entity:n.camera_image}),a.haptic&>(a.haptic));break;case"navigate":a.navigation_path&&(vt(0,a.navigation_path),a.haptic&>(a.haptic));break;case"url":a.url_path&&window.open(a.url_path),a.haptic&>(a.haptic);break;case"toggle":n.entity&&(_t(e,n.entity),a.haptic&>(a.haptic));break;case"call-service":if(!a.service)return;var o=a.service.split(".",2),s=o[0],c=o[1],l=F({},a.service_data);"entity"===l.entity_id&&(l.entity_id=n.entity),e.callService(s,c,l,a.target),a.haptic&>(a.haptic);break;case"fire-dom-event":ct(t,"ll-custom",a),a.haptic&>(a.haptic)}};function St(t){return void 0!==t&&"none"!==t.action}function Ct(t,e,n){if(e.has("config")||n)return!0;if(t.config.entity){var i=e.get("hass");return!i||i.states[t.config.entity]!==t.hass.states[t.config.entity]}return!1}function At(t){return void 0!==t&&"none"!==t.action}var Tt=function(t,e,n){void 0===n&&(n=!0);var i={};e.forEach((function(e){if(it.includes(t.states[e].state)===n){var r=H(e),a=["cover","lock"].includes(r)?r:"homeassistant";a in i||(i[a]=[]),i[a].push(e)}})),Object.keys(i).forEach((function(e){var r;switch(e){case"lock":r=n?"unlock":"lock";break;case"cover":r=n?"open_cover":"close_cover";break;default:r=n?"turn_on":"turn_off"}t.callService(e,r,{entity_id:i[e]})}))},Dt=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},Rt={humidity:"mdi:water-percent",illuminance:"mdi:brightness-5",temperature:"mdi:thermometer",pressure:"mdi:gauge",power:"mdi:flash",signal_strength:"mdi:wifi"},xt={binary_sensor:function(t,e){var n="off"===t;switch(null==e?void 0:e.attributes.device_class){case"battery":return n?"mdi:battery":"mdi:battery-outline";case"battery_charging":return n?"mdi:battery":"mdi:battery-charging";case"cold":return n?"mdi:thermometer":"mdi:snowflake";case"connectivity":return n?"mdi:server-network-off":"mdi:server-network";case"door":return n?"mdi:door-closed":"mdi:door-open";case"garage_door":return n?"mdi:garage":"mdi:garage-open";case"power":case"plug":return n?"mdi:power-plug-off":"mdi:power-plug";case"gas":case"problem":case"safety":case"tamper":return n?"mdi:check-circle":"mdi:alert-circle";case"smoke":return n?"mdi:check-circle":"mdi:smoke";case"heat":return n?"mdi:thermometer":"mdi:fire";case"light":return n?"mdi:brightness-5":"mdi:brightness-7";case"lock":return n?"mdi:lock":"mdi:lock-open";case"moisture":return n?"mdi:water-off":"mdi:water";case"motion":return n?"mdi:walk":"mdi:run";case"occupancy":case"presence":return n?"mdi:home-outline":"mdi:home";case"opening":return n?"mdi:square":"mdi:square-outline";case"running":return n?"mdi:stop":"mdi:play";case"sound":return n?"mdi:music-note-off":"mdi:music-note";case"update":return n?"mdi:package":"mdi:package-up";case"vibration":return n?"mdi:crop-portrait":"mdi:vibrate";case"window":return n?"mdi:window-closed":"mdi:window-open";default:return n?"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 Rt)return Rt[e];if("battery"===e){var n=Number(t.state);if(isNaN(n))return"mdi:battery-unknown";var i=10*Math.round(n/10);return i>=100?"mdi:battery":i<=0?"mdi:battery-alert":"hass:battery-"+i}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"}},kt=function(t){if(!t)return"mdi:bookmark";if(t.attributes.icon)return t.attributes.icon;var e=H(t.entity_id);return e in xt?xt[e](t):pt(e,t.state)}},239:function(t,e){var n=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function o(t){try{c(i.next(t))}catch(t){a(t)}}function s(t){try{c(i.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.ClientBase=void 0,e.ClientBase=class{GetData(t,e,i){return n(this,void 0,void 0,(function*(){const n=localStorage.getItem(t);if(n&&e){const t=JSON.parse(n),e=new Date;if(e.setHours(e.getHours()-i),new Date(t.created)>e)return JSON.parse(t.data)}const r=yield fetch(`${this.baseUrl}/${t}`,{headers:{Accept:"application/json"}}),a=yield r.json(),o={data:JSON.stringify(a),created:new Date};return e&&localStorage.setItem(t,JSON.stringify(o)),a}))}}},171:function(t,e,n){var i=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function o(t){try{c(i.next(t))}catch(t){a(t)}}function s(t){try{c(i.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const r=n(593),a=n(239);class o extends a.ClientBase{constructor(){super(...arguments),this.baseUrl="https://ergast.com/api/f1"}GetSchedule(t){return i(this,void 0,void 0,(function*(){const e=yield this.GetData(`${t}.json`,!0,72);return null==e?void 0:e.MRData.RaceTable.Races}))}GetLastResult(){return i(this,void 0,void 0,(function*(){const t=(0,r.getRefreshTime)("current/last/results.json"),e=yield this.GetData("current/last/results.json",!0,t);return null==e?void 0:e.MRData.RaceTable.Races[0]}))}GetDriverStandings(){return i(this,void 0,void 0,(function*(){const t=(0,r.getRefreshTime)("current/driverStandings.json"),e=yield this.GetData("current/driverStandings.json",!0,t);return null==e?void 0:e.MRData.StandingsTable.StandingsLists[0].DriverStandings}))}GetConstructorStandings(){return i(this,void 0,void 0,(function*(){const t=(0,r.getRefreshTime)("current/constructorStandings.json"),e=yield this.GetData("current/constructorStandings.json",!0,t);return null==e?void 0:e.MRData.StandingsTable.StandingsLists[0].ConstructorStandings}))}GetSprintResults(t,e){return i(this,void 0,void 0,(function*(){const n=yield this.GetData(`${t}/${e}/sprint.json`,!1,0);return null==n?void 0:n.MRData.RaceTable}))}GetQualifyingResults(t,e){return i(this,void 0,void 0,(function*(){const n=yield this.GetData(`${t}/${e}/qualifying.json`,!1,0);return null==n?void 0:n.MRData.RaceTable}))}GetResults(t,e){return i(this,void 0,void 0,(function*(){const n=yield this.GetData(`${t}/${e}/results.json`,!1,0);return null==n?void 0:n.MRData.RaceTable}))}GetSeasons(){return i(this,void 0,void 0,(function*(){const t=yield this.GetData("seasons.json?limit=200",!0,72);return null==t?void 0:t.MRData.SeasonTable.Seasons}))}GetSeasonRaces(t){return i(this,void 0,void 0,(function*(){return(yield this.GetData(`${t}.json`,!0,72)).MRData.RaceTable.Races}))}}e.default=o},930:function(t,e,n){var i=this&&this.__awaiter||function(t,e,n,i){return new(n||(n=Promise))((function(r,a){function o(t){try{c(i.next(t))}catch(t){a(t)}}function s(t){try{c(i.throw(t))}catch(t){a(t)}}function c(t){var e;t.done?r(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(o,s)}c((i=i.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0});const r=n(239);class a extends r.ClientBase{constructor(){super(...arguments),this.baseUrl="https://restcountries.com/v2"}GetAll(){return i(this,void 0,void 0,(function*(){return yield this.GetData("all",!0,730)}))}GetCountriesFromLocalStorage(){const t=localStorage.getItem("all");if(t){const e=JSON.parse(t);return JSON.parse(e.data)}return[]}}e.default=a},243:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.BaseCard=void 0;const i=n(171);e.BaseCard=class{constructor(t){this.config=t.config,this.client=new i.default,this.hass=t._hass,this.parent=t}translation(t){return!this.config.translations||Object.keys(this.config.translations).indexOf(t)<0?this.defaultTranslations[t]:this.config.translations[t]}getProperties(){var t,e;const n=null===(t=this.parent.properties)||void 0===t?void 0:t.get("cardValues");return{races:null==n?void 0:n.races,selectedRace:null==n?void 0:n.selectedRace,selectedSeason:null==n?void 0:n.selectedSeason,selectedTabIndex:null!==(e=null==n?void 0:n.selectedTabIndex)&&void 0!==e?e:0}}getParentCardValues(){var t,e;const n=null!==(t=this.parent.properties)&&void 0!==t?t:new Map;return{properties:null!==(e=n.get("cardValues"))&&void 0!==e?e:{},cardValues:n}}}},521:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=n(692),r=n(345),a=n(593),o=n(243);class s extends o.BaseCard{constructor(t){super(t),this.defaultTranslations={constructor:"Constructor",points:"Pts",wins:"Wins"}}cardSize(){return 11}renderStandingRow(t){var e;return i.html` ${t.position} ${(null===(e=this.config.standings)||void 0===e?void 0:e.show_teamlogo)?i.html` `:""}${t.Constructor.name} @@ -19,8 +19,8 @@ ${(0,a.reduceArray)(t,this.config.row_limit).map((t=>this.renderStandingRow(t)))} - `:i.html`${(0,a.getApiErrorMessage)("standings")}`)),i.html`${(0,a.getApiLoadingMessage)()}`)}`}}e.default=s},765:function(t,e,n){var i=this&&this.__await||function(t){return this instanceof i?(this.v=t,this):new i(t)},r=this&&this.__asyncGenerator||function(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r,a=n.apply(t,e||[]),o=[];return r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r;function s(t){a[t]&&(r[t]=function(e){return new Promise((function(n,i){o.push([t,e,n,i])>1||c(t,e)}))})}function c(t,e){try{(n=a[t](e)).value instanceof i?Promise.resolve(n.value.v).then(l,d):u(o[0][2],n)}catch(t){u(o[0][3],t)}var n}function l(t){c("next",t)}function d(t){c("throw",t)}function u(t,e){t(e),o.shift(),o.length&&c(o[0][0],o[0][1])}};Object.defineProperty(e,"__esModule",{value:!0});const a=n(692),o=n(345),s=n(593),c=n(243),l=n(530),d=n(197),u=n(342);class h extends c.BaseCard{constructor(t){super(t),this.defaultTranslations={days:"d",hours:"h",minutes:"m",seconds:"s",endofseason:"Season is over. See you next year!",racenow:"We are racing!",date:"Date",practice1:"Practice 1",practice2:"Practice 2",practice3:"Practice 3",race:"Race",racename:"Race name",circuitname:"Circuit name",location:"Location",city:"City",racetime:"Race",sprint:"Sprint",qualifying:"Qualifying"}}cardSize(){return this.config.show_raceinfo?12:6}renderHeader(t){return this.config.show_raceinfo?a.html` - ${(0,s.renderRaceInfo)(this,t)}
${(0,s.renderHeader)(this,t,!0)}
`:null}countDownTillDate(t){return r(this,arguments,(function*(){for(;t>new Date;){const e=(new Date).getTime(),n=t.getTime()-e,r=Math.floor(n/864e5),a=Math.floor(n%864e5/36e5),o=Math.floor(n%36e5/6e4),s=Math.floor(n%6e4/1e3);yield yield i(`${r}${this.translation("days")} ${a}${this.translation("hours")} ${o}${this.translation("minutes")} ${s}${this.translation("seconds")} `),yield i(new Promise((t=>setTimeout(t,1e3))))}yield yield i(this.translation("racenow"))}))}render(){const t=t=>{this.hass&&this.config.actions&&t.detail.action&&(0,s.clickHandler)(this.parent,this.config,this.hass,t)};return a.html`${(0,o.until)(this.client.GetSchedule((new Date).getFullYear()).then((e=>{var n,i;if(!e)return a.html`${(0,s.getApiErrorMessage)("next race")}`;const r=e.filter((t=>{const e=new Date(t.date+"T"+t.time);return e.setHours(e.getHours()+3),e>=new Date}))[0];if(!r)return(0,s.getEndOfSeasonMessage)(this.translation("endofseason"));const o=new Date(r.date+"T"+r.time),c=this.countDownTillDate(o),h=void 0!==this.config.actions;return a.html`1||c(t,e)}))})}function c(t,e){try{(n=a[t](e)).value instanceof i?Promise.resolve(n.value.v).then(l,d):u(o[0][2],n)}catch(t){u(o[0][3],t)}var n}function l(t){c("next",t)}function d(t){c("throw",t)}function u(t,e){t(e),o.shift(),o.length&&c(o[0][0],o[0][1])}};Object.defineProperty(e,"__esModule",{value:!0});const a=n(692),o=n(345),s=n(593),c=n(243),l=n(530),d=n(197),u=n(342),h=n(98);class m extends c.BaseCard{constructor(t){super(t),this.defaultTranslations={days:"d",hours:"h",minutes:"m",seconds:"s",endofseason:"Season is over. See you next year!",racenow:"We are racing!",date:"Date",practice1:"Practice 1",practice2:"Practice 2",practice3:"Practice 3",race:"Race",racename:"Race name",circuitname:"Circuit name",location:"Location",city:"City",racetime:"Race",sprint:"Sprint",qualifying:"Qualifying"}}cardSize(){return this.config.show_raceinfo?12:6}renderHeader(t){return this.config.show_raceinfo?a.html`
+ ${(0,s.renderRaceInfo)(this,t)}
${(0,s.renderHeader)(this,t,!0)}
`:null}countDownTillDate(t){return r(this,arguments,(function*(){for(;t>new Date;){const e=(new Date).getTime(),n=t.getTime()-e,r=Math.floor(n/864e5),a=Math.floor(n%864e5/36e5),o=Math.floor(n%36e5/6e4),s=Math.floor(n%6e4/1e3);yield yield i(`${r}${this.translation("days")} ${a}${this.translation("hours")} ${o}${this.translation("minutes")} ${s}${this.translation("seconds")} `),yield i(new Promise((t=>setTimeout(t,1e3))))}yield yield i(this.translation("racenow"))}))}render(){const t=t=>{this.hass&&this.config.actions&&t.detail.action&&(0,s.clickHandler)(this.parent,this.config,this.hass,t)};return a.html`${(0,o.until)(this.client.GetSchedule((new Date).getFullYear()).then((e=>{var n,i;if(!e)return a.html`${(0,s.getApiErrorMessage)("next race")}`;const{nextRace:r,raceDateTime:o}=this.getNextEvent(e);if(!r)return(0,s.getEndOfSeasonMessage)(this.translation("endofseason"));const c=this.countDownTillDate(o),h=void 0!==this.config.actions;return a.html`
@@ -33,7 +33,7 @@
- ${this.renderHeader(r)}`})),a.html`${(0,s.getApiLoadingMessage)()}`)}`}}e.default=h},412:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=n(692),r=n(345),a=n(593),o=n(243);class s extends o.BaseCard{constructor(t){super(t),this.defaultTranslations={driver:"Driver",team:"Team",points:"Pts",wins:"Wins"}}cardSize(){return 12}renderStandingRow(t){var e,n;return i.html` + ${this.renderHeader(r)}`})),a.html`${(0,s.getApiLoadingMessage)()}`)}`}getNextEvent(t){const e=t.filter((t=>{const e=new Date(t.date+"T"+t.time);return e.setHours(e.getHours()+3),e>=new Date}))[0];let n=null;if(e)switch(this.config.countdown_type){case h.CountdownType.Practice1:n=new Date(e.FirstPractice.date+"T"+e.FirstPractice.time);break;case h.CountdownType.Practice2:n=new Date(e.SecondPractice.date+"T"+e.SecondPractice.time);break;case h.CountdownType.Practice3:n=new Date(e.ThirdPractice.date+"T"+e.ThirdPractice.time);break;case h.CountdownType.Qualifying:n=new Date(e.Qualifying.date+"T"+e.Qualifying.time);break;case h.CountdownType.Sprint:e.Sprint&&(n=new Date(e.Sprint.date+"T"+e.Sprint.time));break;default:n=new Date(e.date+"T"+e.time)}return{nextRace:e,raceDateTime:n}}}e.default=m},412:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0});const i=n(692),r=n(345),a=n(593),o=n(243);class s extends o.BaseCard{constructor(t){super(t),this.defaultTranslations={driver:"Driver",team:"Team",points:"Pts",wins:"Wins"}}cardSize(){return 12}renderStandingRow(t){var e,n;return i.html` ${t.position} ${(null===(e=this.config.standings)||void 0===e?void 0:e.show_flag)?i.html` `:""}${t.Driver.code} @@ -301,10 +301,10 @@ .transparent { background-color: transparent !important; } -`},98:(t,e)=>{var n,i;Object.defineProperty(e,"__esModule",{value:!0}),e.FormulaOneCardType=e.PreviousRaceDisplay=void 0,(i=e.PreviousRaceDisplay||(e.PreviousRaceDisplay={})).Strikethrough="strikethrough",i.Italic="italic",i.Hide="hide",(n=e.FormulaOneCardType||(e.FormulaOneCardType={})).DriverStandings="driver_standings",n.ConstructorStandings="constructor_standings",n.NextRace="next_race",n.Schedule="schedule",n.LastResult="last_result",n.Results="results",n.Countdown="countdown"},593:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.renderConstructorColumn=e.reduceArray=e.getRefreshTime=e.renderRaceInfo=e.renderHeader=e.clickHandler=e.getEndOfSeasonMessage=e.getApiLoadingMessage=e.getApiErrorMessage=e.getDriverName=e.getCircuitName=e.getTeamImageUrl=e.checkConfig=e.getCountryFlagByName=e.getCountryFlagByNationality=e.getCountries=e.hasConfigOrCardValuesChanged=void 0;const i=n(677),r=n(98),a=n(347),o=n(197),s=n(247),c=n(623),l=n(342),d=n(930);e.hasConfigOrCardValuesChanged=(t,e)=>{if(e.has("config"))return!0;const n=e.get("card");if(n&&n.parent)return n.parent.properties!==t.properties;const i=e.get("cardValues");return!!i&&i!=t.properties},e.getCountries=()=>(new d.default).GetCountriesFromLocalStorage(),e.getCountryFlagByNationality=t=>{const n=(0,e.getCountries)().filter((e=>e.demonym==t));return n.length>1?n.sort(((t,e)=>t.population>e.population?-1:1))[0].flags.png:n[0].flags.png},e.getCountryFlagByName=t=>(0,e.getCountries)().filter((e=>{var n;return e.name==t||e.nativeName==t||(null===(n=e.altSpellings)||void 0===n?void 0:n.includes(t))}))[0].flags.png,e.checkConfig=t=>{if(void 0===t.card_type)throw new Error("Please define FormulaOne card type (card_type).")},e.getTeamImageUrl=t=>{t=t.toLocaleLowerCase().replace("_","-");const e=[{teamName:"red-bull",corrected:"red-bull-racing"},{teamName:"alfa",corrected:"alfa-romeo"},{teamName:"haas",corrected:"haas-f1-team"}].filter((e=>e.teamName==t));return e.length>0&&(t=e[0].corrected),`${c.ImageConstants.TeamLogoCDN}/2023/${t.toLowerCase()}-logo.png.transform/2col-retina/image.png`},e.getCircuitName=t=>{const e=[{countryDashed:"UAE",name:"Abu_Dhabi"},{countryDashed:"UK",name:"Great_Britain"},{countryDashed:"Monaco",name:"Monoco"},{countryDashed:"Azerbaijan",name:"Baku"},{countryDashed:"Saudi-Arabia",name:"Saudi_Arabia"}].filter((e=>e.countryDashed==t));return e.length>0&&(t=e[0].name),t},e.getDriverName=(t,e)=>{const n="VER"==t.code?1:t.permanentNumber;return`${t.givenName} ${t.familyName}${e.show_carnumber?` #${n}`:""}`},e.getApiErrorMessage=t=>i.html`
Error getting ${t}
`,e.getApiLoadingMessage=()=>i.html`
Loading...
`,e.getEndOfSeasonMessage=t=>i.html`
${t}
`,e.clickHandler=(t,e,n,i)=>{(0,o.handleAction)(t,n,e.actions,i.detail.action)},e.renderHeader=(t,n,a=!1)=>{var s,d;const u=n.Circuit.Location.country.replace(" ","-"),h=(0,e.getCircuitName)(u),m=t.config.image_clickable||void 0!==t.config.actions,p=n.Circuit.url;t.config.image_clickable&&!t.config.actions&&(t.config.actions={tap_action:{action:"url",url_path:p}});const f=i.html`{t.hass&&t.config.actions&&n.detail.action&&!a&&(0,e.clickHandler)(t.parent,t.config,t.hass,n)}} +`},98:(t,e)=>{var n,i,r;Object.defineProperty(e,"__esModule",{value:!0}),e.FormulaOneCardType=e.PreviousRaceDisplay=e.CountdownType=void 0,(r=e.CountdownType||(e.CountdownType={})).Race="race",r.Qualifying="qualifying",r.Practice1="practice1",r.Practice2="practice2",r.Practice3="practice3",r.Sprint="sprint",(i=e.PreviousRaceDisplay||(e.PreviousRaceDisplay={})).Strikethrough="strikethrough",i.Italic="italic",i.Hide="hide",(n=e.FormulaOneCardType||(e.FormulaOneCardType={})).DriverStandings="driver_standings",n.ConstructorStandings="constructor_standings",n.NextRace="next_race",n.Schedule="schedule",n.LastResult="last_result",n.Results="results",n.Countdown="countdown"},593:(t,e,n)=>{Object.defineProperty(e,"__esModule",{value:!0}),e.renderConstructorColumn=e.reduceArray=e.getRefreshTime=e.renderRaceInfo=e.renderHeader=e.clickHandler=e.getEndOfSeasonMessage=e.getApiLoadingMessage=e.getApiErrorMessage=e.getDriverName=e.getCircuitName=e.getTeamImageUrl=e.checkConfig=e.getCountryFlagByName=e.getCountryFlagByNationality=e.getCountries=e.hasConfigOrCardValuesChanged=void 0;const i=n(677),r=n(98),a=n(347),o=n(197),s=n(247),c=n(623),l=n(342),d=n(930);e.hasConfigOrCardValuesChanged=(t,e)=>{if(e.has("config"))return!0;const n=e.get("card");if(n&&n.parent)return n.parent.properties!==t.properties;const i=e.get("cardValues");return!!i&&i!=t.properties},e.getCountries=()=>(new d.default).GetCountriesFromLocalStorage(),e.getCountryFlagByNationality=t=>{const n=(0,e.getCountries)().filter((e=>e.demonym==t));return n.length>1?n.sort(((t,e)=>t.population>e.population?-1:1))[0].flags.png:n[0].flags.png},e.getCountryFlagByName=t=>(0,e.getCountries)().filter((e=>{var n;return e.name==t||e.nativeName==t||(null===(n=e.altSpellings)||void 0===n?void 0:n.includes(t))}))[0].flags.png,e.checkConfig=t=>{if(void 0===t.card_type)throw new Error("Please define FormulaOne card type (card_type).")},e.getTeamImageUrl=t=>{t=t.toLocaleLowerCase().replace("_","-");const e=[{teamName:"red-bull",corrected:"red-bull-racing"},{teamName:"alfa",corrected:"alfa-romeo"},{teamName:"haas",corrected:"haas-f1-team"}].filter((e=>e.teamName==t));return e.length>0&&(t=e[0].corrected),`${c.ImageConstants.TeamLogoCDN}/2023/${t.toLowerCase()}-logo.png.transform/2col-retina/image.png`},e.getCircuitName=t=>{const e=[{countryDashed:"UAE",name:"Abu_Dhabi"},{countryDashed:"UK",name:"Great_Britain"},{countryDashed:"Monaco",name:"Monoco"},{countryDashed:"Azerbaijan",name:"Baku"},{countryDashed:"Saudi-Arabia",name:"Saudi_Arabia"}].filter((e=>e.countryDashed==t));return e.length>0&&(t=e[0].name),t},e.getDriverName=(t,e)=>{const n="VER"==t.code?1:t.permanentNumber;return`${t.givenName} ${t.familyName}${e.show_carnumber?` #${n}`:""}`},e.getApiErrorMessage=t=>i.html`
Error getting ${t}
`,e.getApiLoadingMessage=()=>i.html`
Loading...
`,e.getEndOfSeasonMessage=t=>i.html`
${t}
`,e.clickHandler=(t,e,n,i)=>{(0,o.handleAction)(t,n,e.actions,i.detail.action)},e.renderHeader=(t,n,a=!1)=>{var s,d;const u=n.Circuit.Location.country.replace(" ","-"),h=(0,e.getCircuitName)(u),m=t.config.image_clickable||void 0!==t.config.actions,p=n.Circuit.url;t.config.image_clickable&&!t.config.actions&&(t.config.actions={tap_action:{action:"url",url_path:p}});const f=i.html`{t.hass&&t.config.actions&&n.detail.action&&!a&&(0,e.clickHandler)(t.parent,t.config,t.hass,n)}} .actionHandler=${(0,l.actionHandler)({hasHold:(0,o.hasAction)(null===(s=t.config.actions)||void 0===s?void 0:s.hold_action),hasDoubleClick:(0,o.hasAction)(null===(d=t.config.actions)||void 0===d?void 0:d.double_tap_action)})} class="${m?" clickable":null}" />`,g=i.html`

  ${n.round} : ${n.raceName}

`;return i.html`${t.config.card_type==r.FormulaOneCardType.Countdown?i.html``:g} ${t.config.hide_tracklayout?i.html``:f}
`},e.renderRaceInfo=(t,e)=>{const n=t.config,r=t.hass;if(n.hide_racedatetimes)return i.html``;const o=new Date(e.date+"T"+e.time),c=(0,a.formatDateTimeRaceInfo)(new Date(e.FirstPractice.date+"T"+e.FirstPractice.time),r.locale),l=(0,a.formatDateTimeRaceInfo)(new Date(e.SecondPractice.date+"T"+e.SecondPractice.time),r.locale),d=void 0!==e.ThirdPractice?(0,a.formatDateTimeRaceInfo)(new Date(e.ThirdPractice.date+"T"+e.ThirdPractice.time),r.locale):"-",u=(0,a.formatDateTimeRaceInfo)(o,r.locale),h=(0,a.formatDateTimeRaceInfo)(new Date(e.Qualifying.date+"T"+e.Qualifying.time),r.locale),m=void 0!==e.Sprint?(0,a.formatDateTimeRaceInfo)(new Date(e.Sprint.date+"T"+e.Sprint.time),r.locale):"-";return i.html`${t.translation("date")}${(0,s.formatDateNumeric)(o,r.locale,n.date_locale)} ${t.translation("practice1")}${c} ${t.translation("race")}${e.round} ${t.translation("practice2")}${l} ${t.translation("racename")}${e.raceName} ${t.translation("practice3")}${d} ${t.translation("circuitname")}${e.Circuit.circuitName} ${t.translation("qualifying")}${h} ${t.translation("location")}${e.Circuit.Location.country} ${t.translation("sprint")}${m} - ${t.translation("city")}${e.Circuit.Location.locality} ${t.translation("racetime")}${u}`},e.getRefreshTime=t=>{let e=24;const n=new Date,i=localStorage.getItem(`${n.getFullYear()}.json`);if(i){const r=JSON.parse(i),a=JSON.parse(r.data).MRData.RaceTable.Races.filter((t=>new Date(t.date).toLocaleDateString==n.toLocaleDateString));if(a.length>0){const n=a[0],i=new Date(n.date+"T"+n.time),r=localStorage.getItem(t);if(r){const t=JSON.parse(r);new Date(t.created)void 0===t?[]:e?t.slice(0,e):t,e.renderConstructorColumn=(t,n)=>i.html`${t.standings.show_teamlogo?i.html` `:""}${n.name}`},206:(t,e,n)=>{n.d(e,{sR:()=>u});var i=n(232),r=n(875);const a=(t,e)=>{var n,i;const r=t._$AN;if(void 0===r)return!1;for(const t of r)null===(i=(n=t)._$AO)||void 0===i||i.call(n,e,!1),a(t,e);return!0},o=t=>{let e,n;do{if(void 0===(e=t._$AM))break;n=e._$AN,n.delete(t),t=e}while(0===(null==n?void 0:n.size))},s=t=>{for(let e;e=t._$AM;t=e){let n=e._$AN;if(void 0===n)e._$AN=n=new Set;else if(n.has(t))break;n.add(t),d(e)}};function c(t){void 0!==this._$AN?(o(this),this._$AM=t,s(this)):this._$AM=t}function l(t,e=!1,n=0){const i=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(e)if(Array.isArray(i))for(let t=n;t{var e,n,i,a;t.type==r.pX.CHILD&&(null!==(e=(i=t)._$AP)&&void 0!==e||(i._$AP=l),null!==(n=(a=t)._$AQ)&&void 0!==n||(a._$AQ=c))};class u extends r.Xe{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,n){super._$AT(t,e,n),s(this),this.isConnected=t._$AU}_$AO(t,e=!0){var n,i;t!==this.isConnected&&(this.isConnected=t,t?null===(n=this.reconnected)||void 0===n||n.call(this):null===(i=this.disconnected)||void 0===i||i.call(this)),e&&(a(this,t),o(this))}setValue(t){if((0,i.OR)(this._$Ct))this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}},232:(t,e,n)=>{n.d(e,{OR:()=>o,pt:()=>a});var i=n(692);const{I:r}=i._$LH,a=t=>null===t||"object"!=typeof t&&"function"!=typeof t,o=t=>void 0===t.strings},875:(t,e,n)=>{n.d(e,{XM:()=>r,Xe:()=>a,pX:()=>i});const i={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},r=t=>(...e)=>({_$litDirective$:t,values:e});class a{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,n){this._$Ct=t,this._$AM=e,this._$Ci=n}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}},69:(t,e,n)=>{n.d(e,{dS:()=>a,gw:()=>i,nX:()=>r});const i=async(t,e)=>{for await(const n of t)if(!1===await e(n))return};class r{constructor(t){this.Y=t}disconnect(){this.Y=void 0}reconnect(t){this.Y=t}deref(){return this.Y}}class a{constructor(){this.Z=void 0,this.q=void 0}get(){return this.Z}pause(){var t;null!==(t=this.Z)&&void 0!==t||(this.Z=new Promise((t=>this.q=t)))}resume(){var t;null===(t=this.q)||void 0===t||t.call(this),this.Z=this.q=void 0}}},345:(t,e,n)=>{n.r(e),n.d(e,{UntilDirective:()=>l,until:()=>d});var i=n(692),r=n(232),a=n(206),o=n(69),s=n(875);const c=t=>!(0,r.pt)(t)&&"function"==typeof t.then;class l extends a.sR{constructor(){super(...arguments),this._$Cwt=1073741823,this._$Cyt=[],this._$CK=new o.nX(this),this._$CX=new o.dS}render(...t){var e;return null!==(e=t.find((t=>!c(t))))&&void 0!==e?e:i.noChange}update(t,e){const n=this._$Cyt;let r=n.length;this._$Cyt=e;const a=this._$CK,o=this._$CX;this.isConnected||this.disconnected();for(let t=0;tthis._$Cwt);t++){const i=e[t];if(!c(i))return this._$Cwt=t,i;t{for(;o.get();)await o.get();const e=a.deref();if(void 0!==e){const n=e._$Cyt.indexOf(i);n>-1&&n{var i;n.r(e),n.d(e,{_$LH:()=>H,html:()=>S,noChange:()=>A,nothing:()=>T,render:()=>B,svg:()=>C});const r=window,a=r.trustedTypes,o=a?a.createPolicy("lit-html",{createHTML:t=>t}):void 0,s=`lit$${(Math.random()+"").slice(9)}$`,c="?"+s,l=`<${c}>`,d=document,u=(t="")=>d.createComment(t),h=t=>null===t||"object"!=typeof t&&"function"!=typeof t,m=Array.isArray,p=t=>m(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,g=/-->/g,v=/>/g,y=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),_=/'/g,b=/"/g,$=/^(?:script|style|textarea|title)$/i,w=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),S=w(1),C=w(2),A=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),D=new WeakMap,R=d.createTreeWalker(d,129,null,!1),x=(t,e)=>{const n=t.length-1,i=[];let r,a=2===e?"":"",c=f;for(let e=0;e"===d[0]?(c=null!=r?r:f,u=-1):void 0===d[1]?u=-2:(u=c.lastIndex-d[2].length,o=d[1],c=void 0===d[3]?y:'"'===d[3]?b:_):c===b||c===_?c=y:c===g||c===v?c=f:(c=y,r=void 0);const m=c===y&&t[e+1].startsWith("/>")?" ":"";a+=c===f?n+l:u>=0?(i.push(o),n.slice(0,u)+"$lit$"+n.slice(u)+s+m):n+s+(-2===u?(i.push(void 0),e):m)}const d=a+(t[n]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==o?o.createHTML(d):d,i]};class k{constructor({strings:t,_$litType$:e},n){let i;this.parts=[];let r=0,o=0;const l=t.length-1,d=this.parts,[h,m]=x(t,e);if(this.el=k.createElement(h,n),R.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(i=R.nextNode())&&d.length0){i.textContent=a?a.emptyScript:"";for(let n=0;n2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=T}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,n,i){const r=this.strings;let a=!1;if(void 0===r)t=E(this,t,e,0),a=!h(t)||t!==this._$AH&&t!==A,a&&(this._$AH=t);else{const i=t;let o,s;for(t=r[0],o=0;o{var i,r;const a=null!==(i=null==n?void 0:n.renderBefore)&&void 0!==i?i:e;let o=a._$litPart$;if(void 0===o){const t=null!==(r=null==n?void 0:n.renderBefore)&&void 0!==r?r:null;a._$litPart$=o=new M(e.insertBefore(u(),t),t,void 0,null!=n?n:{})}return o._$AI(t),o}},595:(t,e,n)=>{n.r(e),n.d(e,{customElement:()=>i,eventOptions:()=>c,property:()=>a,query:()=>l,queryAll:()=>d,queryAssignedElements:()=>p,queryAssignedNodes:()=>f,queryAsync:()=>u,state:()=>o});const i=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:n,elements:i}=e;return{kind:n,elements:i,finisher(e){customElements.define(t,e)}}})(t,e),r=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(n){n.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(n){n.createProperty(e.key,t)}};function a(t){return(e,n)=>void 0!==n?((t,e,n)=>{e.constructor.createProperty(n,t)})(t,e,n):r(t,e)}function o(t){return a({...t,state:!0})}const s=({finisher:t,descriptor:e})=>(n,i)=>{var r;if(void 0===i){const i=null!==(r=n.originalKey)&&void 0!==r?r:n.key,a=null!=e?{kind:"method",placement:"prototype",key:i,descriptor:e(n.key)}:{...n,key:i};return null!=t&&(a.finisher=function(e){t(e,i)}),a}{const r=n.constructor;void 0!==e&&Object.defineProperty(n,i,e(i)),null==t||t(r,i)}};function c(t){return s({finisher:(e,n)=>{Object.assign(e.prototype[n],t)}})}function l(t,e){return s({descriptor:n=>{const i={get(){var e,n;return null!==(n=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==n?n:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof n?Symbol():"__"+n;i.get=function(){var n,i;return void 0===this[e]&&(this[e]=null!==(i=null===(n=this.renderRoot)||void 0===n?void 0:n.querySelector(t))&&void 0!==i?i:null),this[e]}}return i}})}function d(t){return s({descriptor:e=>({get(){var e,n;return null!==(n=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelectorAll(t))&&void 0!==n?n:[]},enumerable:!0,configurable:!0})})}function u(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 h;const m=null!=(null===(h=window.HTMLSlotElement)||void 0===h?void 0:h.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:n}=null!=t?t:{};return s({descriptor:i=>({get(){var i;const r="slot"+(e?`[name=${e}]`:":not([name])"),a=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(r),o=null!=a?m(a,t):[];return n?o.filter((t=>t.matches(n))):o},enumerable:!0,configurable:!0})})}function f(t,e,n){let i,r=t;return"object"==typeof t?(r=t.slot,i=t):i={flatten:e},n?p({slot:r,flatten:e,selector:n}):s({descriptor:t=>({get(){var t,e;const n="slot"+(r?`[name=${r}]`:":not([name])"),a=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(n);return null!==(e=null==a?void 0:a.assignedNodes(i))&&void 0!==e?e:[]},enumerable:!0,configurable:!0})})}},82:(t,e,n)=>{n.r(e),n.d(e,{Directive:()=>i.Xe,PartType:()=>i.pX,directive:()=>i.XM});var i=n(875)},530:(t,e,n)=>{n.r(e),n.d(e,{AsyncReplaceDirective:()=>s,asyncReplace:()=>c});var i=n(692),r=n(206),a=n(69),o=n(875);class s extends r.sR{constructor(){super(...arguments),this._$CK=new a.nX(this),this._$CX=new a.dS}render(t,e){return i.noChange}update(t,[e,n]){if(this.isConnected||this.disconnected(),e===this._$CJ)return;this._$CJ=e;let r=0;const{_$CK:o,_$CX:s}=this;return(0,a.gw)(e,(async t=>{for(;s.get();)await s.get();const i=o.deref();if(void 0!==i){if(i._$CJ!==e)return!1;void 0!==n&&(t=n(t,r)),i.commitValue(t,r),r++}return!0})),i.noChange}commitValue(t,e){this.setValue(t)}disconnected(){this._$CK.disconnect(),this._$CX.pause()}reconnected(){this._$CK.reconnect(this),this._$CX.resume()}}const c=(0,o.XM)(s)},677:(t,e,n)=>{n.r(e),n.d(e,{CSSResult:()=>s,LitElement:()=>A,ReactiveElement:()=>b,UpdatingElement:()=>C,_$LE:()=>D,_$LH:()=>S._$LH,adoptStyles:()=>d,css:()=>l,defaultConverter:()=>v,getCompatibleStyle:()=>u,html:()=>S.html,isServer:()=>R,noChange:()=>S.noChange,notEqual:()=>y,nothing:()=>S.nothing,render:()=>S.render,supportsAdoptingStyleSheets:()=>r,svg:()=>S.svg,unsafeCSS:()=>c});const i=window,r=i.ShadowRoot&&(void 0===i.ShadyCSS||i.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),o=new WeakMap;class s{constructor(t,e,n){if(this._$cssResult$=!0,n!==a)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 n=void 0!==e&&1===e.length;n&&(t=o.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),n&&o.set(e,t))}return t}toString(){return this.cssText}}const c=t=>new s("string"==typeof t?t:t+"",void 0,a),l=(t,...e)=>{const n=1===t.length?t[0]:e.reduce(((e,n,i)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[i+1]),t[0]);return new s(n,t,a)},d=(t,e)=>{r?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const n=document.createElement("style"),r=i.litNonce;void 0!==r&&n.setAttribute("nonce",r),n.textContent=e.cssText,t.appendChild(n)}))},u=r?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return c(e)})(t):t;var h;const m=window,p=m.trustedTypes,f=p?p.emptyScript:"",g=m.reactiveElementPolyfillSupport,v={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 n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},y=(t,e)=>e!==t&&(e==e||t==t),_={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:y};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;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,n)=>{const i=this._$Ep(n,e);void 0!==i&&(this._$Ev.set(i,n),t.push(i))})),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 n="symbol"==typeof t?Symbol():"__"+t,i=this.getPropertyDescriptor(t,n,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}}static getPropertyDescriptor(t,e,n){return{get(){return this[e]},set(i){const r=this[t];this[e]=i,this.requestUpdate(t,r,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||_}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),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 n of e)this.createProperty(n,t[n])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(u(t))}else void 0!==t&&e.push(u(t));return e}static _$Ep(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"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,n;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(n=t.hostConnected)||void 0===n||n.call(t))}removeController(t){var e;null===(e=this._$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 d(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,n){this._$AK(t,n)}_$EO(t,e,n=_){var i;const r=this.constructor._$Ep(t,n);if(void 0!==r&&!0===n.reflect){const a=(void 0!==(null===(i=n.converter)||void 0===i?void 0:i.toAttribute)?n.converter:v).toAttribute(e,n.type);this._$El=t,null==a?this.removeAttribute(r):this.setAttribute(r,a),this._$El=null}}_$AK(t,e){var n;const i=this.constructor,r=i._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=i.getPropertyOptions(r),a="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(n=t.converter)||void 0===n?void 0:n.fromAttribute)?t.converter:v;this._$El=r,this[r]=a.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,n){let i=!0;void 0!==t&&(((n=n||this.constructor.getPropertyOptions(t)).hasChanged||y)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===n.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,n))):i=!1),!this.isUpdatePending&&i&&(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 n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),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(n)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(n)}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){}}b.finalized=!0,b.elementProperties=new Map,b.elementStyles=[],b.shadowRootOptions={mode:"open"},null==g||g({ReactiveElement:b}),(null!==(h=m.reactiveElementVersions)&&void 0!==h?h:m.reactiveElementVersions=[]).push("1.6.1");var $,w,S=n(692);const C=b;class A extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t,e;const n=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=n.firstChild),n}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=(0,S.render)(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return S.noChange}}A.finalized=!0,A._$litElement$=!0,null===($=globalThis.litElementHydrateSupport)||void 0===$||$.call(globalThis,{LitElement:A});const T=globalThis.litElementPolyfillSupport;null==T||T({LitElement:A});const D={_$AK:(t,e,n)=>{t._$AK(e,n)},_$AL:t=>t._$AL};(null!==(w=globalThis.litElementVersions)&&void 0!==w?w:globalThis.litElementVersions=[]).push("3.2.2");const R=!1},147:t=>{t.exports=JSON.parse('{"name":"formulaone-card","version":"1.0.3","description":"Frontend card for Home Assistant to display Formula One data","main":"index.js","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/formulaone-card/formulaone-card/jest.results.json","prebuild":"copy git-hooks\\\\pre-commit .git\\\\hooks\\\\ && echo \'hook copied\'"},"repository":{"type":"git","url":"git+https://github.com/marcokreeft87/formulaone-card.git"},"keywords":[],"author":"","license":"ISC","bugs":{"url":"https://github.com/marcokreeft87/formulaone-card/issues"},"homepage":"https://github.com/marcokreeft87/formulaone-card#readme","devDependencies":{"@types/jest":"^29.2.6","@typescript-eslint/eslint-plugin":"^5.52.0","@typescript-eslint/parser":"^5.52.0","codecov":"^3.8.3","eslint":"^8.34.0","home-assistant-js-websocket":"^8.0.1","lit":"^2.6.1","typescript":"^4.9.5","webpack":"^5.75.0","webpack-cli":"^5.0.1"},"dependencies":{"@babel/plugin-transform-runtime":"^7.19.6","@babel/preset-env":"^7.20.2","@lit-labs/scoped-registry-mixin":"^1.0.1","babel-jest":"^29.4.3","compression-webpack-plugin":"^10.0.0","custom-card-helpers":"^1.9.0","isomorphic-fetch":"^3.0.0","jest-environment-jsdom":"^29.4.3","jest-ts-auto-mock":"^2.1.0","ts-auto-mock":"^3.6.4","ts-jest":"^29.0.5","ts-loader":"^9.4.2","ttypescript":"^1.5.15","yarn":"^1.22.19"}}')}},e={};function n(i){var r=e[i];if(void 0!==r)return r.exports;var a=e[i]={exports:{}};return t[i].call(a.exports,a,a.exports,n),a.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(607)})(); \ No newline at end of file + ${t.translation("city")}${e.Circuit.Location.locality} ${t.translation("racetime")}${u}`},e.getRefreshTime=t=>{let e=24;const n=new Date,i=localStorage.getItem(`${n.getFullYear()}.json`);if(i){const r=JSON.parse(i),a=JSON.parse(r.data).MRData.RaceTable.Races.filter((t=>new Date(t.date).toLocaleDateString==n.toLocaleDateString));if(a.length>0){const n=a[0],i=new Date(n.date+"T"+n.time),r=localStorage.getItem(t);if(r){const t=JSON.parse(r);new Date(t.created)void 0===t?[]:e?t.slice(0,e):t,e.renderConstructorColumn=(t,n)=>i.html`${t.standings.show_teamlogo?i.html` `:""}${n.name}`},206:(t,e,n)=>{n.d(e,{sR:()=>u});var i=n(232),r=n(875);const a=(t,e)=>{var n,i;const r=t._$AN;if(void 0===r)return!1;for(const t of r)null===(i=(n=t)._$AO)||void 0===i||i.call(n,e,!1),a(t,e);return!0},o=t=>{let e,n;do{if(void 0===(e=t._$AM))break;n=e._$AN,n.delete(t),t=e}while(0===(null==n?void 0:n.size))},s=t=>{for(let e;e=t._$AM;t=e){let n=e._$AN;if(void 0===n)e._$AN=n=new Set;else if(n.has(t))break;n.add(t),d(e)}};function c(t){void 0!==this._$AN?(o(this),this._$AM=t,s(this)):this._$AM=t}function l(t,e=!1,n=0){const i=this._$AH,r=this._$AN;if(void 0!==r&&0!==r.size)if(e)if(Array.isArray(i))for(let t=n;t{var e,n,i,a;t.type==r.pX.CHILD&&(null!==(e=(i=t)._$AP)&&void 0!==e||(i._$AP=l),null!==(n=(a=t)._$AQ)&&void 0!==n||(a._$AQ=c))};class u extends r.Xe{constructor(){super(...arguments),this._$AN=void 0}_$AT(t,e,n){super._$AT(t,e,n),s(this),this.isConnected=t._$AU}_$AO(t,e=!0){var n,i;t!==this.isConnected&&(this.isConnected=t,t?null===(n=this.reconnected)||void 0===n||n.call(this):null===(i=this.disconnected)||void 0===i||i.call(this)),e&&(a(this,t),o(this))}setValue(t){if((0,i.OR)(this._$Ct))this._$Ct._$AI(t,this);else{const e=[...this._$Ct._$AH];e[this._$Ci]=t,this._$Ct._$AI(e,this,0)}}disconnected(){}reconnected(){}}},232:(t,e,n)=>{n.d(e,{OR:()=>o,pt:()=>a});var i=n(692);const{I:r}=i._$LH,a=t=>null===t||"object"!=typeof t&&"function"!=typeof t,o=t=>void 0===t.strings},875:(t,e,n)=>{n.d(e,{XM:()=>r,Xe:()=>a,pX:()=>i});const i={ATTRIBUTE:1,CHILD:2,PROPERTY:3,BOOLEAN_ATTRIBUTE:4,EVENT:5,ELEMENT:6},r=t=>(...e)=>({_$litDirective$:t,values:e});class a{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,e,n){this._$Ct=t,this._$AM=e,this._$Ci=n}_$AS(t,e){return this.update(t,e)}update(t,e){return this.render(...e)}}},69:(t,e,n)=>{n.d(e,{dS:()=>a,gw:()=>i,nX:()=>r});const i=async(t,e)=>{for await(const n of t)if(!1===await e(n))return};class r{constructor(t){this.Y=t}disconnect(){this.Y=void 0}reconnect(t){this.Y=t}deref(){return this.Y}}class a{constructor(){this.Z=void 0,this.q=void 0}get(){return this.Z}pause(){var t;null!==(t=this.Z)&&void 0!==t||(this.Z=new Promise((t=>this.q=t)))}resume(){var t;null===(t=this.q)||void 0===t||t.call(this),this.Z=this.q=void 0}}},345:(t,e,n)=>{n.r(e),n.d(e,{UntilDirective:()=>l,until:()=>d});var i=n(692),r=n(232),a=n(206),o=n(69),s=n(875);const c=t=>!(0,r.pt)(t)&&"function"==typeof t.then;class l extends a.sR{constructor(){super(...arguments),this._$Cwt=1073741823,this._$Cyt=[],this._$CK=new o.nX(this),this._$CX=new o.dS}render(...t){var e;return null!==(e=t.find((t=>!c(t))))&&void 0!==e?e:i.noChange}update(t,e){const n=this._$Cyt;let r=n.length;this._$Cyt=e;const a=this._$CK,o=this._$CX;this.isConnected||this.disconnected();for(let t=0;tthis._$Cwt);t++){const i=e[t];if(!c(i))return this._$Cwt=t,i;t{for(;o.get();)await o.get();const e=a.deref();if(void 0!==e){const n=e._$Cyt.indexOf(i);n>-1&&n{var i;n.r(e),n.d(e,{_$LH:()=>H,html:()=>S,noChange:()=>A,nothing:()=>T,render:()=>B,svg:()=>C});const r=window,a=r.trustedTypes,o=a?a.createPolicy("lit-html",{createHTML:t=>t}):void 0,s=`lit$${(Math.random()+"").slice(9)}$`,c="?"+s,l=`<${c}>`,d=document,u=(t="")=>d.createComment(t),h=t=>null===t||"object"!=typeof t&&"function"!=typeof t,m=Array.isArray,p=t=>m(t)||"function"==typeof(null==t?void 0:t[Symbol.iterator]),f=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,g=/-->/g,v=/>/g,y=RegExp(">|[ \t\n\f\r](?:([^\\s\"'>=/]+)([ \t\n\f\r]*=[ \t\n\f\r]*(?:[^ \t\n\f\r\"'`<>=]|(\"|')|))|$)","g"),_=/'/g,b=/"/g,$=/^(?:script|style|textarea|title)$/i,w=t=>(e,...n)=>({_$litType$:t,strings:e,values:n}),S=w(1),C=w(2),A=Symbol.for("lit-noChange"),T=Symbol.for("lit-nothing"),D=new WeakMap,R=d.createTreeWalker(d,129,null,!1),x=(t,e)=>{const n=t.length-1,i=[];let r,a=2===e?"":"",c=f;for(let e=0;e"===d[0]?(c=null!=r?r:f,u=-1):void 0===d[1]?u=-2:(u=c.lastIndex-d[2].length,o=d[1],c=void 0===d[3]?y:'"'===d[3]?b:_):c===b||c===_?c=y:c===g||c===v?c=f:(c=y,r=void 0);const m=c===y&&t[e+1].startsWith("/>")?" ":"";a+=c===f?n+l:u>=0?(i.push(o),n.slice(0,u)+"$lit$"+n.slice(u)+s+m):n+s+(-2===u?(i.push(void 0),e):m)}const d=a+(t[n]||"")+(2===e?"":"");if(!Array.isArray(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return[void 0!==o?o.createHTML(d):d,i]};class k{constructor({strings:t,_$litType$:e},n){let i;this.parts=[];let r=0,o=0;const l=t.length-1,d=this.parts,[h,m]=x(t,e);if(this.el=k.createElement(h,n),R.currentNode=this.el.content,2===e){const t=this.el.content,e=t.firstChild;e.remove(),t.append(...e.childNodes)}for(;null!==(i=R.nextNode())&&d.length0){i.textContent=a?a.emptyScript:"";for(let n=0;n2||""!==n[0]||""!==n[1]?(this._$AH=Array(n.length-1).fill(new String),this.strings=n):this._$AH=T}get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}_$AI(t,e=this,n,i){const r=this.strings;let a=!1;if(void 0===r)t=E(this,t,e,0),a=!h(t)||t!==this._$AH&&t!==A,a&&(this._$AH=t);else{const i=t;let o,s;for(t=r[0],o=0;o{var i,r;const a=null!==(i=null==n?void 0:n.renderBefore)&&void 0!==i?i:e;let o=a._$litPart$;if(void 0===o){const t=null!==(r=null==n?void 0:n.renderBefore)&&void 0!==r?r:null;a._$litPart$=o=new N(e.insertBefore(u(),t),t,void 0,null!=n?n:{})}return o._$AI(t),o}},595:(t,e,n)=>{n.r(e),n.d(e,{customElement:()=>i,eventOptions:()=>c,property:()=>a,query:()=>l,queryAll:()=>d,queryAssignedElements:()=>p,queryAssignedNodes:()=>f,queryAsync:()=>u,state:()=>o});const i=t=>e=>"function"==typeof e?((t,e)=>(customElements.define(t,e),e))(t,e):((t,e)=>{const{kind:n,elements:i}=e;return{kind:n,elements:i,finisher(e){customElements.define(t,e)}}})(t,e),r=(t,e)=>"method"===e.kind&&e.descriptor&&!("value"in e.descriptor)?{...e,finisher(n){n.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(n){n.createProperty(e.key,t)}};function a(t){return(e,n)=>void 0!==n?((t,e,n)=>{e.constructor.createProperty(n,t)})(t,e,n):r(t,e)}function o(t){return a({...t,state:!0})}const s=({finisher:t,descriptor:e})=>(n,i)=>{var r;if(void 0===i){const i=null!==(r=n.originalKey)&&void 0!==r?r:n.key,a=null!=e?{kind:"method",placement:"prototype",key:i,descriptor:e(n.key)}:{...n,key:i};return null!=t&&(a.finisher=function(e){t(e,i)}),a}{const r=n.constructor;void 0!==e&&Object.defineProperty(n,i,e(i)),null==t||t(r,i)}};function c(t){return s({finisher:(e,n)=>{Object.assign(e.prototype[n],t)}})}function l(t,e){return s({descriptor:n=>{const i={get(){var e,n;return null!==(n=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelector(t))&&void 0!==n?n:null},enumerable:!0,configurable:!0};if(e){const e="symbol"==typeof n?Symbol():"__"+n;i.get=function(){var n,i;return void 0===this[e]&&(this[e]=null!==(i=null===(n=this.renderRoot)||void 0===n?void 0:n.querySelector(t))&&void 0!==i?i:null),this[e]}}return i}})}function d(t){return s({descriptor:e=>({get(){var e,n;return null!==(n=null===(e=this.renderRoot)||void 0===e?void 0:e.querySelectorAll(t))&&void 0!==n?n:[]},enumerable:!0,configurable:!0})})}function u(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 h;const m=null!=(null===(h=window.HTMLSlotElement)||void 0===h?void 0:h.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:n}=null!=t?t:{};return s({descriptor:i=>({get(){var i;const r="slot"+(e?`[name=${e}]`:":not([name])"),a=null===(i=this.renderRoot)||void 0===i?void 0:i.querySelector(r),o=null!=a?m(a,t):[];return n?o.filter((t=>t.matches(n))):o},enumerable:!0,configurable:!0})})}function f(t,e,n){let i,r=t;return"object"==typeof t?(r=t.slot,i=t):i={flatten:e},n?p({slot:r,flatten:e,selector:n}):s({descriptor:t=>({get(){var t,e;const n="slot"+(r?`[name=${r}]`:":not([name])"),a=null===(t=this.renderRoot)||void 0===t?void 0:t.querySelector(n);return null!==(e=null==a?void 0:a.assignedNodes(i))&&void 0!==e?e:[]},enumerable:!0,configurable:!0})})}},82:(t,e,n)=>{n.r(e),n.d(e,{Directive:()=>i.Xe,PartType:()=>i.pX,directive:()=>i.XM});var i=n(875)},530:(t,e,n)=>{n.r(e),n.d(e,{AsyncReplaceDirective:()=>s,asyncReplace:()=>c});var i=n(692),r=n(206),a=n(69),o=n(875);class s extends r.sR{constructor(){super(...arguments),this._$CK=new a.nX(this),this._$CX=new a.dS}render(t,e){return i.noChange}update(t,[e,n]){if(this.isConnected||this.disconnected(),e===this._$CJ)return;this._$CJ=e;let r=0;const{_$CK:o,_$CX:s}=this;return(0,a.gw)(e,(async t=>{for(;s.get();)await s.get();const i=o.deref();if(void 0!==i){if(i._$CJ!==e)return!1;void 0!==n&&(t=n(t,r)),i.commitValue(t,r),r++}return!0})),i.noChange}commitValue(t,e){this.setValue(t)}disconnected(){this._$CK.disconnect(),this._$CX.pause()}reconnected(){this._$CK.reconnect(this),this._$CX.resume()}}const c=(0,o.XM)(s)},677:(t,e,n)=>{n.r(e),n.d(e,{CSSResult:()=>s,LitElement:()=>A,ReactiveElement:()=>b,UpdatingElement:()=>C,_$LE:()=>D,_$LH:()=>S._$LH,adoptStyles:()=>d,css:()=>l,defaultConverter:()=>v,getCompatibleStyle:()=>u,html:()=>S.html,isServer:()=>R,noChange:()=>S.noChange,notEqual:()=>y,nothing:()=>S.nothing,render:()=>S.render,supportsAdoptingStyleSheets:()=>r,svg:()=>S.svg,unsafeCSS:()=>c});const i=window,r=i.ShadowRoot&&(void 0===i.ShadyCSS||i.ShadyCSS.nativeShadow)&&"adoptedStyleSheets"in Document.prototype&&"replace"in CSSStyleSheet.prototype,a=Symbol(),o=new WeakMap;class s{constructor(t,e,n){if(this._$cssResult$=!0,n!==a)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 n=void 0!==e&&1===e.length;n&&(t=o.get(e)),void 0===t&&((this.o=t=new CSSStyleSheet).replaceSync(this.cssText),n&&o.set(e,t))}return t}toString(){return this.cssText}}const c=t=>new s("string"==typeof t?t:t+"",void 0,a),l=(t,...e)=>{const n=1===t.length?t[0]:e.reduce(((e,n,i)=>e+(t=>{if(!0===t._$cssResult$)return t.cssText;if("number"==typeof t)return t;throw Error("Value passed to 'css' function must be a 'css' function result: "+t+". Use 'unsafeCSS' to pass non-literal values, but take care to ensure page security.")})(n)+t[i+1]),t[0]);return new s(n,t,a)},d=(t,e)=>{r?t.adoptedStyleSheets=e.map((t=>t instanceof CSSStyleSheet?t:t.styleSheet)):e.forEach((e=>{const n=document.createElement("style"),r=i.litNonce;void 0!==r&&n.setAttribute("nonce",r),n.textContent=e.cssText,t.appendChild(n)}))},u=r?t=>t:t=>t instanceof CSSStyleSheet?(t=>{let e="";for(const n of t.cssRules)e+=n.cssText;return c(e)})(t):t;var h;const m=window,p=m.trustedTypes,f=p?p.emptyScript:"",g=m.reactiveElementPolyfillSupport,v={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 n=t;switch(e){case Boolean:n=null!==t;break;case Number:n=null===t?null:Number(t);break;case Object:case Array:try{n=JSON.parse(t)}catch(t){n=null}}return n}},y=(t,e)=>e!==t&&(e==e||t==t),_={attribute:!0,type:String,converter:v,reflect:!1,hasChanged:y};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;this.finalize(),(null!==(e=this.h)&&void 0!==e?e:this.h=[]).push(t)}static get observedAttributes(){this.finalize();const t=[];return this.elementProperties.forEach(((e,n)=>{const i=this._$Ep(n,e);void 0!==i&&(this._$Ev.set(i,n),t.push(i))})),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 n="symbol"==typeof t?Symbol():"__"+t,i=this.getPropertyDescriptor(t,n,e);void 0!==i&&Object.defineProperty(this.prototype,t,i)}}static getPropertyDescriptor(t,e,n){return{get(){return this[e]},set(i){const r=this[t];this[e]=i,this.requestUpdate(t,r,n)},configurable:!0,enumerable:!0}}static getPropertyOptions(t){return this.elementProperties.get(t)||_}static finalize(){if(this.hasOwnProperty("finalized"))return!1;this.finalized=!0;const t=Object.getPrototypeOf(this);if(t.finalize(),void 0!==t.h&&(this.h=[...t.h]),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 n of e)this.createProperty(n,t[n])}return this.elementStyles=this.finalizeStyles(this.styles),!0}static finalizeStyles(t){const e=[];if(Array.isArray(t)){const n=new Set(t.flat(1/0).reverse());for(const t of n)e.unshift(u(t))}else void 0!==t&&e.push(u(t));return e}static _$Ep(t,e){const n=e.attribute;return!1===n?void 0:"string"==typeof n?n:"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,n;(null!==(e=this._$ES)&&void 0!==e?e:this._$ES=[]).push(t),void 0!==this.renderRoot&&this.isConnected&&(null===(n=t.hostConnected)||void 0===n||n.call(t))}removeController(t){var e;null===(e=this._$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 d(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,n){this._$AK(t,n)}_$EO(t,e,n=_){var i;const r=this.constructor._$Ep(t,n);if(void 0!==r&&!0===n.reflect){const a=(void 0!==(null===(i=n.converter)||void 0===i?void 0:i.toAttribute)?n.converter:v).toAttribute(e,n.type);this._$El=t,null==a?this.removeAttribute(r):this.setAttribute(r,a),this._$El=null}}_$AK(t,e){var n;const i=this.constructor,r=i._$Ev.get(t);if(void 0!==r&&this._$El!==r){const t=i.getPropertyOptions(r),a="function"==typeof t.converter?{fromAttribute:t.converter}:void 0!==(null===(n=t.converter)||void 0===n?void 0:n.fromAttribute)?t.converter:v;this._$El=r,this[r]=a.fromAttribute(e,t.type),this._$El=null}}requestUpdate(t,e,n){let i=!0;void 0!==t&&(((n=n||this.constructor.getPropertyOptions(t)).hasChanged||y)(this[t],e)?(this._$AL.has(t)||this._$AL.set(t,e),!0===n.reflect&&this._$El!==t&&(void 0===this._$EC&&(this._$EC=new Map),this._$EC.set(t,n))):i=!1),!this.isUpdatePending&&i&&(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 n=this._$AL;try{e=this.shouldUpdate(n),e?(this.willUpdate(n),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(n)):this._$Ek()}catch(t){throw e=!1,this._$Ek(),t}e&&this._$AE(n)}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){}}b.finalized=!0,b.elementProperties=new Map,b.elementStyles=[],b.shadowRootOptions={mode:"open"},null==g||g({ReactiveElement:b}),(null!==(h=m.reactiveElementVersions)&&void 0!==h?h:m.reactiveElementVersions=[]).push("1.6.1");var $,w,S=n(692);const C=b;class A extends b{constructor(){super(...arguments),this.renderOptions={host:this},this._$Do=void 0}createRenderRoot(){var t,e;const n=super.createRenderRoot();return null!==(t=(e=this.renderOptions).renderBefore)&&void 0!==t||(e.renderBefore=n.firstChild),n}update(t){const e=this.render();this.hasUpdated||(this.renderOptions.isConnected=this.isConnected),super.update(t),this._$Do=(0,S.render)(e,this.renderRoot,this.renderOptions)}connectedCallback(){var t;super.connectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!0)}disconnectedCallback(){var t;super.disconnectedCallback(),null===(t=this._$Do)||void 0===t||t.setConnected(!1)}render(){return S.noChange}}A.finalized=!0,A._$litElement$=!0,null===($=globalThis.litElementHydrateSupport)||void 0===$||$.call(globalThis,{LitElement:A});const T=globalThis.litElementPolyfillSupport;null==T||T({LitElement:A});const D={_$AK:(t,e,n)=>{t._$AK(e,n)},_$AL:t=>t._$AL};(null!==(w=globalThis.litElementVersions)&&void 0!==w?w:globalThis.litElementVersions=[]).push("3.2.2");const R=!1},147:t=>{t.exports=JSON.parse('{"name":"formulaone-card","version":"1.1.0","description":"Frontend card for Home Assistant to display Formula One data","main":"index.js","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/formulaone-card/formulaone-card/jest.results.json","prebuild":"copy git-hooks\\\\pre-commit .git\\\\hooks\\\\ && echo \'hook copied\'"},"repository":{"type":"git","url":"git+https://github.com/marcokreeft87/formulaone-card.git"},"keywords":[],"author":"","license":"ISC","bugs":{"url":"https://github.com/marcokreeft87/formulaone-card/issues"},"homepage":"https://github.com/marcokreeft87/formulaone-card#readme","devDependencies":{"@types/jest":"^29.2.6","@typescript-eslint/eslint-plugin":"^5.52.0","@typescript-eslint/parser":"^5.52.0","codecov":"^3.8.3","eslint":"^8.34.0","home-assistant-js-websocket":"^8.0.1","lit":"^2.6.1","typescript":"^4.9.5","webpack":"^5.75.0","webpack-cli":"^5.0.1"},"dependencies":{"@babel/plugin-transform-runtime":"^7.19.6","@babel/preset-env":"^7.20.2","@lit-labs/scoped-registry-mixin":"^1.0.1","babel-jest":"^29.4.3","compression-webpack-plugin":"^10.0.0","custom-card-helpers":"^1.9.0","isomorphic-fetch":"^3.0.0","jest-environment-jsdom":"^29.4.3","jest-ts-auto-mock":"^2.1.0","ts-auto-mock":"^3.6.4","ts-jest":"^29.0.5","ts-loader":"^9.4.2","ttypescript":"^1.5.15","yarn":"^1.22.19"}}')}},e={};function n(i){var r=e[i];if(void 0!==r)return r.exports;var a=e[i]={exports:{}};return t[i].call(a.exports,a,a.exports,n),a.exports}n.d=(t,e)=>{for(var i in e)n.o(e,i)&&!n.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:e[i]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n(607)})(); \ No newline at end of file diff --git a/formulaone-card.js.gz b/formulaone-card.js.gz index 5fa6d87..0e02ea3 100644 Binary files a/formulaone-card.js.gz and b/formulaone-card.js.gz differ diff --git a/package-lock.json b/package-lock.json index 758e279..e979687 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "formulaone-card", - "version": "1.0.3", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "formulaone-card", - "version": "1.0.3", + "version": "1.1.0", "license": "ISC", "dependencies": { "@babel/plugin-transform-runtime": "^7.21.0", diff --git a/package.json b/package.json index 7c499f3..82e5680 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "formulaone-card", - "version": "1.0.3", + "version": "1.1.0", "description": "Frontend card for Home Assistant to display Formula One data", "main": "index.js", "scripts": { diff --git a/src/cards/countdown.ts b/src/cards/countdown.ts index 8dd0c43..2b42c46 100644 --- a/src/cards/countdown.ts +++ b/src/cards/countdown.ts @@ -7,6 +7,7 @@ import { Race } from "../api/models"; import { ActionHandlerEvent, hasAction, HomeAssistant } from "custom-card-helpers"; import FormulaOneCard from ".."; import { actionHandler } from "../directives/action-handler-directive"; +import { CountdownType } from "../types/formulaone-card-types"; export default class Countdown extends BaseCard { hass: HomeAssistant; @@ -81,17 +82,12 @@ export default class Countdown extends BaseCard { return html`${getApiErrorMessage('next race')}` } - const nextRace = response.filter(race => { - const raceDateTime = new Date(race.date + 'T' + race.time); - raceDateTime.setHours(raceDateTime.getHours() + 3); - return raceDateTime >= new Date(); - })[0]; + const { nextRace, raceDateTime } = this.getNextEvent(response); if(!nextRace) { return getEndOfSeasonMessage(this.translation('endofseason')); } - const raceDateTime = new Date(nextRace.date + 'T' + nextRace.time); const timer = this.countDownTillDate(raceDateTime); const hasConfigAction = this.config.actions !== undefined; @@ -117,4 +113,41 @@ export default class Countdown extends BaseCard { html`${getApiLoadingMessage()}` )}`; } + + getNextEvent(response: Race[]) { + + const nextRace = response.filter(race => { + const raceDateTime = new Date(race.date + 'T' + race.time); + raceDateTime.setHours(raceDateTime.getHours() + 3); + return raceDateTime >= new Date(); + })[0]; + + let raceDateTime = null; + if(nextRace) { + switch(this.config.countdown_type as CountdownType) { + case CountdownType.Practice1: + raceDateTime = new Date(nextRace.FirstPractice.date + 'T' + nextRace.FirstPractice.time); + break; + case CountdownType.Practice2: + raceDateTime = new Date(nextRace.SecondPractice.date + 'T' + nextRace.SecondPractice.time); + break; + case CountdownType.Practice3: + raceDateTime = new Date(nextRace.ThirdPractice.date + 'T' + nextRace.ThirdPractice.time); + break; + case CountdownType.Qualifying: + raceDateTime = new Date(nextRace.Qualifying.date + 'T' + nextRace.Qualifying.time); + break; + case CountdownType.Sprint: + if(nextRace.Sprint) { + raceDateTime = new Date(nextRace.Sprint.date + 'T' + nextRace.Sprint.time); + } + break; + default: + raceDateTime = new Date(nextRace.date + 'T' + nextRace.time); + break; + } + } + + return { nextRace, raceDateTime }; + } } diff --git a/src/types/formulaone-card-types.ts b/src/types/formulaone-card-types.ts index 4444d0d..7c23338 100644 --- a/src/types/formulaone-card-types.ts +++ b/src/types/formulaone-card-types.ts @@ -21,6 +21,16 @@ export interface FormulaOneCardConfig extends LovelaceCardConfig { f1_font?: boolean; row_limit?: number; icons?: CustomIcons; + countdown_type?: CountdownType; +} + +export enum CountdownType { + Race = "race", + Qualifying = "qualifying", + Practice1 = "practice1", + Practice2 = "practice2", + Practice3 = "practice3", + Sprint = "sprint" } export interface ActionOptions { diff --git a/tests/cards/countdown.test.ts b/tests/cards/countdown.test.ts index 3fe782d..e5abf49 100644 --- a/tests/cards/countdown.test.ts +++ b/tests/cards/countdown.test.ts @@ -1,6 +1,6 @@ import { createMock } from "ts-auto-mock"; import Countdown from "../../src/cards/countdown"; -import { FormulaOneCardConfig } from "../../src/types/formulaone-card-types"; +import { CountdownType, FormulaOneCardConfig } from "../../src/types/formulaone-card-types"; import { getRenderStringAsync } from "../utils"; import { MRData } from '../testdata/schedule.json' import { MRData as resultData } from '../testdata/results.json' @@ -235,6 +235,26 @@ describe('Testing countdown file', () => { expect(customCardHelper.handleAction).toBeCalledTimes(3); spy.mockClear(); + }), + test.each` + countdown_type | current_date | expected + ${CountdownType.Practice1}, ${new Date(2022, 3, 19)}, ${new Date("2022-04-22T11:30:00.000Z")} + ${CountdownType.Practice2}, ${new Date(2022, 3, 19)}, ${new Date("2022-04-23T10:30:00.000Z")} + ${CountdownType.Practice3}, ${new Date(2022, 2, 1)}, ${new Date("2022-03-19T12:00:00.000Z")} + ${CountdownType.Qualifying}, ${new Date(2022, 3, 19)}, ${new Date("2022-04-22T15:00:00.000Z")} + ${CountdownType.Race}, ${new Date(2022, 3, 19)}, ${new Date("2022-04-24T13:00:00.000Z")} + ${CountdownType.Sprint}, ${new Date(2022, 3, 19)}, ${new Date("2022-04-23T14:30:00.000Z")} + `(`Calling render with countdown_type $countdown_type`, async ({ countdown_type, current_date, expected }) => { + config.countdown_type = countdown_type; + card.config = config; + + jest.useFakeTimers(); + jest.setSystemTime(current_date); // Weird bug in jest setting this to the last of the month + + const result = card.getNextEvent(MRData.RaceTable.Races); + jest.useRealTimers(); + + expect(result.raceDateTime).toMatchObject(expected); }); });