import { LitElement, html, } from "https://unpkg.com/lit-element@2.0.1/lit-element.js?module"; class NFLCard extends LitElement { static get properties() { return { hass: {}, _config: {}, }; } setConfig(config) { this._config = config; } getCardSize() { return 5; } render() { if (!this.hass || !this._config) { return html``; } const stateObj = this.hass.states[this._config.entity]; const outline = this._config.outline; const outlineColor = this._config.outline_color; const teamProb = (stateObj.attributes.team_win_probability * 100).toFixed(0); const oppoProb = (stateObj.attributes.opponent_win_probability * 100).toFixed(0); var tScr = stateObj.attributes.team_score; var oScr = stateObj.attributes.opponent_score; var dateForm = new Date (stateObj.attributes.date); var gameDay = dateForm.toLocaleDateString('en-US', { weekday: 'long' }); var gameTime = dateForm.toLocaleTimeString('en-US', { hour: '2-digit', minute:'2-digit' }); var gameMonth = dateForm.toLocaleDateString('en-US', { month: 'short' }); var gameDate = dateForm.toLocaleDateString('en-US', { day: '2-digit' }); var outColor = outlineColor; if (outline == true) { var clrOut = 1; var toRadius = 4; var probRadius = 7; } if (!this._config.outline || outline == false){ var clrOut = 0; var toRadius = 3; var probRadius = 6; } if (!this._config.outline_color) { var outColor = '#ffffff'; } if (stateObj.attributes.possession == stateObj.attributes.team_id) { var teamPoss = 1; } if (stateObj.attributes.possession == stateObj.attributes.opponent_id) { var oppoPoss = 1; } if (Boolean(stateObj.state == 'POST') && Number(tScr) > Number(oScr)) { var oppoScore = 0.6; var teamScore = 1; } if (Boolean(stateObj.state == 'POST') && Number(tScr) < Number(oScr)) { var oppoScore = 1; var teamScore = 0.6; } if (Boolean(stateObj.state == 'POST') && Number(tScr) == Number(oScr)) { var oppoScore = 1; var teamScore = 1; } if (stateObj.attributes.team_homeaway == 'home') { var teamColor = stateObj.attributes.team_colors[0]; var oppoColor = stateObj.attributes.opponent_colors[1]; } if (stateObj.attributes.team_homeaway == 'away') { var teamColor = stateObj.attributes.team_colors[1]; var oppoColor = stateObj.attributes.opponent_colors[0]; } if (!stateObj) { return html` Unknown entity: ${this._config.entity} `; } if (stateObj.state == 'unavailable') { return html` Sensor unavailable: ${this._config.entity} `; } if (stateObj.state == 'POST') { return html`
${stateObj.attributes.team_name}
${stateObj.attributes.team_record}
${tScr}
-
${oScr}
${stateObj.attributes.opponent_name}
${stateObj.attributes.opponent_record}
${gameMonth} ${gameDate} - FINAL
`; } if (stateObj.state == 'IN') { return html`
${stateObj.attributes.team_name}
${stateObj.attributes.team_record}
${stateObj.attributes.team_score}
-
${stateObj.attributes.opponent_score}
${stateObj.attributes.opponent_name}
${stateObj.attributes.opponent_record}
Q${stateObj.attributes.quarter} - ${stateObj.attributes.clock}
${stateObj.attributes.venue}
${stateObj.attributes.down_distance_text}
${stateObj.attributes.location}
${stateObj.attributes.tv_network}

${stateObj.attributes.last_play}

Win Probability
${teamProb}%
${oppoProb}%
`; } if (stateObj.state == 'PRE') { return html`
${stateObj.attributes.team_name}
${stateObj.attributes.team_record}
${gameDay}
${gameTime}
${stateObj.attributes.opponent_name}
${stateObj.attributes.opponent_record}
Kickoff ${stateObj.attributes.kickoff_in}
${stateObj.attributes.odds}
${stateObj.attributes.venue}
O/U: ${stateObj.attributes.overunder}
${stateObj.attributes.location}
${stateObj.attributes.tv_network}
`; } if (stateObj.state == 'BYE') { return html`
${stateObj.attributes.team_name}
BYE
`; } if (stateObj.state == 'NOT_FOUND') { return html`
Better Luck
Next Year
`; } } } customElements.define("nfl-card", NFLCard);