From a893222a59638f6a85055e05068689e971702e9d Mon Sep 17 00:00:00 2001 From: schelv <13403863+schelv@users.noreply.github.com> Date: Thu, 16 Nov 2023 19:09:37 +0100 Subject: [PATCH] use null instead of undefined. --- src/components/ha-base-time-input.ts | 4 +--- src/components/ha-time-input.ts | 15 ++++++++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/ha-base-time-input.ts b/src/components/ha-base-time-input.ts index d1af4a9af3b5..ec19ad400921 100644 --- a/src/components/ha-base-time-input.ts +++ b/src/components/ha-base-time-input.ts @@ -268,10 +268,8 @@ export class HaBaseTimeInput extends LitElement { } private _clearValue(): void { - const value = undefined; - fireEvent(this, "value-changed", { - value, + value: null, }); } diff --git a/src/components/ha-time-input.ts b/src/components/ha-time-input.ts index 5d35d56395b8..908a5830efe5 100644 --- a/src/components/ha-time-input.ts +++ b/src/components/ha-time-input.ts @@ -56,19 +56,20 @@ export class HaTimeInput extends LitElement { `; } - private _timeChanged(ev: CustomEvent<{ value: TimeChangedEvent }>) { + private _timeChanged(ev: CustomEvent<{ value: TimeChangedEvent | null }>) { ev.stopPropagation(); const eventValue = ev.detail.value; const useAMPM = useAmPm(this.locale); let value; - if (typeof eventValue === "undefined") { - value = undefined; - } else if ( - !isNaN(eventValue.hours) || - !isNaN(eventValue.minutes) || - !isNaN(eventValue.seconds) + // An eventValue of null means the value is being cleared, + // and value will (intentionally) be left undefined. + if ( + eventValue !== null && + (!isNaN(eventValue.hours) || + !isNaN(eventValue.minutes) || + !isNaN(eventValue.seconds)) ) { let hours = eventValue.hours || 0; if (eventValue && useAMPM) {