Keep number

This commit is contained in:
Aidan Timson
2025-09-04 14:04:07 +01:00
parent ef9029829a
commit 0ce17e3dea

View File

@@ -1,15 +1,15 @@
import type { PropertyValues } from "lit"; import type { PropertyValues } from "lit";
import { css, html, LitElement, nothing } from "lit"; import { css, html, LitElement, nothing } from "lit";
import { customElement, property, state } from "lit/decorators"; import { customElement, property, state } from "lit/decorators";
import { clampValue } from "../data/number";
import { useAmPm } from "../common/datetime/use_am_pm"; import { useAmPm } from "../common/datetime/use_am_pm";
import { fireEvent } from "../common/dom/fire_event"; import { fireEvent } from "../common/dom/fire_event";
import type { FrontendLocaleData } from "../data/translation"; import type { FrontendLocaleData } from "../data/translation";
import type { HomeAssistant } from "../types"; import type { HomeAssistant } from "../types";
import type { ClampedValue } from "../data/number"; import type { ClampedValue } from "../data/number";
import { clampValue } from "../data/number";
import "./ha-base-time-input"; import "./ha-base-time-input";
import "./ha-numeric-arrow-input";
import "./ha-button"; import "./ha-button";
import "./ha-numeric-arrow-input";
@customElement("ha-time-picker") @customElement("ha-time-picker")
export class HaTimePicker extends LitElement { export class HaTimePicker extends LitElement {
@@ -199,10 +199,13 @@ export class HaTimePicker extends LitElement {
max: this._useAmPm ? 12 : 23, max: this._useAmPm ? 12 : 23,
}), }),
} as CustomEvent<ClampedValue>); } as CustomEvent<ClampedValue>);
const hourMax = this._useAmPm ? 12 : 23;
if (this._hours < hourMax) {
this._minutes = 0; this._minutes = 0;
} }
} }
} }
}
private _secondsChanged(ev: CustomEvent<ClampedValue>) { private _secondsChanged(ev: CustomEvent<ClampedValue>) {
ev.stopPropagation?.(); ev.stopPropagation?.();
@@ -219,10 +222,13 @@ export class HaTimePicker extends LitElement {
this._minutesChanged({ this._minutesChanged({
detail: clampValue({ value: this._minutes + 1, min: 0, max: 59 }), detail: clampValue({ value: this._minutes + 1, min: 0, max: 59 }),
} as CustomEvent<ClampedValue>); } as CustomEvent<ClampedValue>);
const hourMax = this._useAmPm ? 12 : 23;
if (!(this._hours === hourMax && this._minutes === 59)) {
this._seconds = 0; this._seconds = 0;
} }
} }
} }
}
private _toggleAmPm() { private _toggleAmPm() {
this._isPm = !this._isPm; this._isPm = !this._isPm;