From 153209342686a969022dfe0e0802051e51ecd9ab Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Thu, 23 Jan 2025 02:23:27 -0800 Subject: [PATCH] Support offset on input_datetime time trigger (#23855) * Support offset on input_datetime time trigger * no time entities --- .../types/ha-automation-trigger-time.ts | 21 ++++++------------- src/translations/en.json | 2 +- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts b/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts index e72a60dd02..9154b1e86f 100644 --- a/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts +++ b/src/panels/config/automation/trigger/types/ha-automation-trigger-time.ts @@ -9,9 +9,11 @@ import type { SchemaUnion } from "../../../../../components/ha-form/types"; import type { TimeTrigger } from "../../../../../data/automation"; import type { HomeAssistant } from "../../../../../types"; import type { TriggerElement } from "../ha-automation-trigger-row"; +import { computeDomain } from "../../../../../common/entity/compute_domain"; const MODE_TIME = "time"; const MODE_ENTITY = "entity"; +const VALID_DOMAINS = ["sensor", "input_datetime"]; @customElement("ha-automation-trigger-time") export class HaTimeTrigger extends LitElement implements TriggerElement { @@ -33,8 +35,7 @@ export class HaTimeTrigger extends LitElement implements TriggerElement { private _schema = memoizeOne( ( localize: LocalizeFunc, - inputMode: typeof MODE_TIME | typeof MODE_ENTITY, - showOffset: boolean + inputMode: typeof MODE_TIME | typeof MODE_ENTITY ) => [ { @@ -65,16 +66,13 @@ export class HaTimeTrigger extends LitElement implements TriggerElement { entity: { filter: [ { domain: "input_datetime" }, - { domain: "time" }, { domain: "sensor", device_class: "timestamp" }, ], }, }, }, + { name: "offset", selector: { text: {} } }, ] as const)), - ...(showOffset - ? ([{ name: "offset", selector: { text: {} } }] as const) - : ([] as const)), ] as const ); @@ -107,9 +105,7 @@ export class HaTimeTrigger extends LitElement implements TriggerElement { const entity = typeof at === "object" ? at.entity_id - : at?.startsWith("input_datetime.") || - at?.startsWith("time.") || - at?.startsWith("sensor.") + : at && VALID_DOMAINS.includes(computeDomain(at)) ? at : undefined; const time = entity ? undefined : (at as string | undefined); @@ -132,9 +128,7 @@ export class HaTimeTrigger extends LitElement implements TriggerElement { } const data = this._data(this._inputMode, at); - const showOffset = - data.mode === MODE_ENTITY && data.entity?.startsWith("sensor."); - const schema = this._schema(this.hass.localize, data.mode, !!showOffset); + const schema = this._schema(this.hass.localize, data.mode); return html`