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) {