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
This commit is contained in:
karwosts 2023-01-23 10:59:50 -08:00 committed by GitHub
parent 88ee409987
commit 38c1112308
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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;