From e20477a243bc12e8dab61178b83234589773fcda Mon Sep 17 00:00:00 2001 From: David Date: Sun, 30 Oct 2022 08:14:08 -0400 Subject: [PATCH 1/4] Correct %s showing instead of 0 --- dist/ha-teamtracker-card.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/ha-teamtracker-card.js b/dist/ha-teamtracker-card.js index 8270d8d..de5e459 100644 --- a/dist/ha-teamtracker-card.js +++ b/dist/ha-teamtracker-card.js @@ -113,7 +113,7 @@ class TeamTrackerCard extends LitElement { var overUnder = ''; if (stateObj.attributes.overunder) { - overUnder = t.translate(sport + ".overUnder", "%s", stateObj.attributes.overunder); + overUnder = t.translate(sport + ".overUnder", "%s", String(stateObj.attributes.overunder)); } var gameStat1 = ''; if (stateObj.attributes.down_distance_text) { @@ -185,9 +185,9 @@ class TeamTrackerCard extends LitElement { var onThirdOp = 0.2; } if (sport.includes("baseball")) { - gameStat1 = t.translate("baseball.gameStat1", "%s", stateObj.attributes.balls); - gameStat2 = t.translate("baseball.gameStat2", "%s", stateObj.attributes.strikes); - gameStat3 = t.translate("baseball.gameStat3", "%s", stateObj.attributes.outs); + gameStat1 = t.translate("baseball.gameStat1", "%s", String(stateObj.attributes.balls)); + gameStat2 = t.translate("baseball.gameStat2", "%s", String(stateObj.attributes.strikes)); + gameStat3 = t.translate("baseball.gameStat3", "%s", String(stateObj.attributes.outs)); outsDisplay = 'inherit'; timeoutsDisplay = 'none'; basesDisplay = 'inherit'; @@ -212,8 +212,8 @@ class TeamTrackerCard extends LitElement { gameBar = t.translate("volleyball.gameBar", "%s", stateObj.attributes.clock); teamProb = stateObj.attributes.team_score; oppoProb = stateObj.attributes.opponent_score; - teamBarLabel = t.translate("volleyball.teamBarLabel", "%s", stateObj.attributes.team_score); - oppoBarLabel = t.translate("volleyball.oppoBarLabel", "%s", stateObj.attributes.opponent_score); + teamBarLabel = t.translate("volleyball.teamBarLabel", "%s", String(stateObj.attributes.team_score)); + oppoBarLabel = t.translate("volleyball.oppoBarLabel", "%s", String(stateObj.attributes.opponent_score)); teamTimeouts = stateObj.attributes.team_sets_won; oppoTimeouts = stateObj.attributes.opponent_sets_won; timeoutsDisplay = 'inline'; @@ -232,8 +232,8 @@ class TeamTrackerCard extends LitElement { if (sport.includes("hockey")) { teamProb = stateObj.attributes.team_shots_on_target; oppoProb = stateObj.attributes.opponent_shots_on_target; - teamBarLabel = t.translate("hockey.teamBarLabel", "%s", stateObj.attributes.team_shots_on_target); - oppoBarLabel = t.translate("hockey.oppoBarLabel", "%s", stateObj.attributes.opponent_shots_on_target); + teamBarLabel = t.translate("hockey.teamBarLabel", "%s", String(stateObj.attributes.team_shots_on_target)); + oppoBarLabel = t.translate("hockey.oppoBarLabel", "%s", String(stateObj.attributes.opponent_shots_on_target)); timeoutsDisplay = 'none'; } From fb7b9fba99734877c3bee0b933b5a0c8b340eff8 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 30 Oct 2022 14:54:22 -0400 Subject: [PATCH 2/4] Honor Time Format selected in user profile --- dist/ha-teamtracker-card.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/dist/ha-teamtracker-card.js b/dist/ha-teamtracker-card.js index de5e459..c2c0f2c 100644 --- a/dist/ha-teamtracker-card.js +++ b/dist/ha-teamtracker-card.js @@ -25,17 +25,35 @@ class TeamTrackerCard extends LitElement { const stateObj = this.hass.states[this._config.entity]; const outline = this._config.outline; const outlineColor = this._config.outline_color; - var teamProb = (stateObj.attributes.team_win_probability * 100).toFixed(0); - var oppoProb = (stateObj.attributes.opponent_win_probability * 100).toFixed(0); + var teamProb = 0; + if (stateObj.attributes.team_win_probability) { + var teamProb = (stateObj.attributes.team_win_probability * 100).toFixed(0); + } + var oppoProb = 0; + if (stateObj.attributes.opponent_win_probability) { + oppoProb = (stateObj.attributes.opponent_win_probability * 100).toFixed(0); + } var tScr = stateObj.attributes.team_score; var oScr = stateObj.attributes.opponent_score; var lang = this.hass.selectedLanguage || this.hass.language || navigator.language || "en" + var time_format = this.hass.locale["time_format"] || "language"; + var t = new Translator(lang); var dateForm = new Date (stateObj.attributes.date); var gameDay = dateForm.toLocaleDateString(lang, { weekday: 'long' }); var gameTime = dateForm.toLocaleTimeString(lang, { hour: '2-digit', minute:'2-digit' }); + if (time_format == "24") { + gameTime = dateForm.toLocaleTimeString(lang, { hour: '2-digit', minute:'2-digit', hour12:false }); + } + if (time_format == "12") { + gameTime = dateForm.toLocaleTimeString(lang, { hour: '2-digit', minute:'2-digit', hour12:true }); + } + if (time_format == "system") { + var sys_lang = navigator.language || "en" + gameTime = dateForm.toLocaleTimeString(sys_lang, { hour: '2-digit', minute:'2-digit', hour12:true }); + } var gameMonth = dateForm.toLocaleDateString(lang, { month: 'short' }); var gameDate = dateForm.toLocaleDateString(lang, { day: '2-digit' }); var outColor = outlineColor; From c52b1eb15f83a7d0b30df4533ef8658febfb0cdf Mon Sep 17 00:00:00 2001 From: David Date: Sun, 30 Oct 2022 16:31:15 -0400 Subject: [PATCH 3/4] Added try/catch in case locale doesn't exist --- dist/ha-teamtracker-card.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/dist/ha-teamtracker-card.js b/dist/ha-teamtracker-card.js index c2c0f2c..93bfb58 100644 --- a/dist/ha-teamtracker-card.js +++ b/dist/ha-teamtracker-card.js @@ -37,7 +37,14 @@ class TeamTrackerCard extends LitElement { var oScr = stateObj.attributes.opponent_score; var lang = this.hass.selectedLanguage || this.hass.language || navigator.language || "en" - var time_format = this.hass.locale["time_format"] || "language"; + + var time_format = "language"; + try { + time_format = this.hass.locale["time_format"] || "language"; + } + catch (e) { + time_format = "language" + } var t = new Translator(lang); From 80ebaf5e2aa7bad121704cd6be6e83414a3eeca7 Mon Sep 17 00:00:00 2001 From: David Date: Sun, 30 Oct 2022 16:36:05 -0400 Subject: [PATCH 4/4] Fixed defect w/ system format --- dist/ha-teamtracker-card.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/ha-teamtracker-card.js b/dist/ha-teamtracker-card.js index 93bfb58..67b86aa 100644 --- a/dist/ha-teamtracker-card.js +++ b/dist/ha-teamtracker-card.js @@ -59,7 +59,7 @@ class TeamTrackerCard extends LitElement { } if (time_format == "system") { var sys_lang = navigator.language || "en" - gameTime = dateForm.toLocaleTimeString(sys_lang, { hour: '2-digit', minute:'2-digit', hour12:true }); + gameTime = dateForm.toLocaleTimeString(sys_lang, { hour: '2-digit', minute:'2-digit' }); } var gameMonth = dateForm.toLocaleDateString(lang, { month: 'short' }); var gameDate = dateForm.toLocaleDateString(lang, { day: '2-digit' });