From 38c1112308c7f843cddd42e06a08ad835f3ce014 Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 23 Jan 2023 10:59:50 -0800 Subject: [PATCH] Prevent optional time fields in ha-service-control from auto-enabling (#15124) * Fix select box overflowing entities-row * Revert "Fix select box overflowing entities-row" This reverts commit b4e668dd064614cf2e544c0d1ea24256703ab84c. * Fix optional time fields in service control from auto-enabling --- src/components/ha-time-input.ts | 36 ++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/components/ha-time-input.ts b/src/components/ha-time-input.ts index cba4a0a95a..29893298dc 100644 --- a/src/components/ha-time-input.ts +++ b/src/components/ha-time-input.ts @@ -58,20 +58,32 @@ export class HaTimeInput extends LitElement { const eventValue = ev.detail.value; const useAMPM = useAmPm(this.locale); - let hours = eventValue.hours || 0; - if (eventValue && useAMPM) { - if (eventValue.amPm === "PM" && hours < 12) { - hours += 12; - } - if (eventValue.amPm === "AM" && hours === 12) { - hours = 0; + let value; + + if ( + !isNaN(eventValue.hours) || + !isNaN(eventValue.minutes) || + !isNaN(eventValue.seconds) + ) { + let hours = eventValue.hours || 0; + if (eventValue && useAMPM) { + if (eventValue.amPm === "PM" && hours < 12) { + hours += 12; + } + if (eventValue.amPm === "AM" && hours === 12) { + hours = 0; + } } + value = `${hours.toString().padStart(2, "0")}:${ + eventValue.minutes + ? eventValue.minutes.toString().padStart(2, "0") + : "00" + }:${ + eventValue.seconds + ? eventValue.seconds.toString().padStart(2, "0") + : "00" + }`; } - const value = `${hours.toString().padStart(2, "0")}:${ - eventValue.minutes ? eventValue.minutes.toString().padStart(2, "0") : "00" - }:${ - eventValue.seconds ? eventValue.seconds.toString().padStart(2, "0") : "00" - }`; if (value === this.value) { return;