From dd963be7230f6abd4ccd8a35c8c9460785a3ab42 Mon Sep 17 00:00:00 2001 From: Zack Barett Date: Thu, 24 Mar 2022 19:57:20 -0500 Subject: [PATCH] Add Day to duration selector (#12125) --- src/components/ha-base-time-input.ts | 47 +++++++++++++++++-- src/components/ha-duration-input.ts | 15 ++++++ .../ha-selector/ha-selector-duration.ts | 1 + src/data/selector.ts | 5 +- 4 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/components/ha-base-time-input.ts b/src/components/ha-base-time-input.ts index 4c1f1d7ff4..9b102faee5 100644 --- a/src/components/ha-base-time-input.ts +++ b/src/components/ha-base-time-input.ts @@ -1,12 +1,13 @@ -import { LitElement, html, TemplateResult, css } from "lit"; -import { customElement, property } from "lit/decorators"; -import "./ha-select"; import "@material/mwc-list/mwc-list-item"; -import "./ha-textfield"; +import { css, html, LitElement, TemplateResult } from "lit"; +import { customElement, property } from "lit/decorators"; import { fireEvent } from "../common/dom/fire_event"; import { stopPropagation } from "../common/dom/stop_propagation"; +import "./ha-select"; +import "./ha-textfield"; export interface TimeChangedEvent { + days?: number; hours: number; minutes: number; seconds: number; @@ -46,6 +47,11 @@ export class HaBaseTimeInput extends LitElement { */ @property({ type: Boolean }) disabled = false; + /** + * day + */ + @property({ type: Number }) days = 0; + /** * hour */ @@ -66,6 +72,11 @@ export class HaBaseTimeInput extends LitElement { */ @property({ type: Number }) milliseconds = 0; + /** + * Label for the day input + */ + @property() dayLabel = ""; + /** * Label for the hour input */ @@ -96,6 +107,11 @@ export class HaBaseTimeInput extends LitElement { */ @property({ type: Boolean }) enableMillisecond = false; + /** + * show the day field + */ + @property({ type: Boolean }) enableDay = false; + /** * limit hours input */ @@ -115,6 +131,29 @@ export class HaBaseTimeInput extends LitElement { return html` ${this.label ? html`` : ""}
+ ${this.enableDay + ? html` + + + ` + : ""} + 24) { + value.days = (value.days ?? 0) + Math.floor(value.hours / 24); + value.hours %= 24; + } + fireEvent(this, "value-changed", { value, }); diff --git a/src/components/ha-selector/ha-selector-duration.ts b/src/components/ha-selector/ha-selector-duration.ts index 73266aaed5..61bde6fa21 100644 --- a/src/components/ha-selector/ha-selector-duration.ts +++ b/src/components/ha-selector/ha-selector-duration.ts @@ -28,6 +28,7 @@ export class HaTimeDuration extends LitElement { .data=${this.value} .disabled=${this.disabled} .required=${this.required} + .enableDay=${this.selector.duration.enable_day} > `; } diff --git a/src/data/selector.ts b/src/data/selector.ts index 427697d3cf..ae985f1343 100644 --- a/src/data/selector.ts +++ b/src/data/selector.ts @@ -96,8 +96,9 @@ export interface DeviceSelector { } export interface DurationSelector { - // eslint-disable-next-line @typescript-eslint/ban-types - duration: {}; + duration: { + enable_day?: boolean; + }; } export interface EntitySelector {