mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-26 02:36:37 +00:00
Support offset on input_datetime time trigger (#23855)
* Support offset on input_datetime time trigger * no time entities
This commit is contained in:
parent
2effb0935c
commit
1532093426
@ -9,9 +9,11 @@ import type { SchemaUnion } from "../../../../../components/ha-form/types";
|
|||||||
import type { TimeTrigger } from "../../../../../data/automation";
|
import type { TimeTrigger } from "../../../../../data/automation";
|
||||||
import type { HomeAssistant } from "../../../../../types";
|
import type { HomeAssistant } from "../../../../../types";
|
||||||
import type { TriggerElement } from "../ha-automation-trigger-row";
|
import type { TriggerElement } from "../ha-automation-trigger-row";
|
||||||
|
import { computeDomain } from "../../../../../common/entity/compute_domain";
|
||||||
|
|
||||||
const MODE_TIME = "time";
|
const MODE_TIME = "time";
|
||||||
const MODE_ENTITY = "entity";
|
const MODE_ENTITY = "entity";
|
||||||
|
const VALID_DOMAINS = ["sensor", "input_datetime"];
|
||||||
|
|
||||||
@customElement("ha-automation-trigger-time")
|
@customElement("ha-automation-trigger-time")
|
||||||
export class HaTimeTrigger extends LitElement implements TriggerElement {
|
export class HaTimeTrigger extends LitElement implements TriggerElement {
|
||||||
@ -33,8 +35,7 @@ export class HaTimeTrigger extends LitElement implements TriggerElement {
|
|||||||
private _schema = memoizeOne(
|
private _schema = memoizeOne(
|
||||||
(
|
(
|
||||||
localize: LocalizeFunc,
|
localize: LocalizeFunc,
|
||||||
inputMode: typeof MODE_TIME | typeof MODE_ENTITY,
|
inputMode: typeof MODE_TIME | typeof MODE_ENTITY
|
||||||
showOffset: boolean
|
|
||||||
) =>
|
) =>
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
@ -65,16 +66,13 @@ export class HaTimeTrigger extends LitElement implements TriggerElement {
|
|||||||
entity: {
|
entity: {
|
||||||
filter: [
|
filter: [
|
||||||
{ domain: "input_datetime" },
|
{ domain: "input_datetime" },
|
||||||
{ domain: "time" },
|
|
||||||
{ domain: "sensor", device_class: "timestamp" },
|
{ domain: "sensor", device_class: "timestamp" },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{ name: "offset", selector: { text: {} } },
|
||||||
] as const)),
|
] as const)),
|
||||||
...(showOffset
|
|
||||||
? ([{ name: "offset", selector: { text: {} } }] as const)
|
|
||||||
: ([] as const)),
|
|
||||||
] as const
|
] as const
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -107,9 +105,7 @@ export class HaTimeTrigger extends LitElement implements TriggerElement {
|
|||||||
const entity =
|
const entity =
|
||||||
typeof at === "object"
|
typeof at === "object"
|
||||||
? at.entity_id
|
? at.entity_id
|
||||||
: at?.startsWith("input_datetime.") ||
|
: at && VALID_DOMAINS.includes(computeDomain(at))
|
||||||
at?.startsWith("time.") ||
|
|
||||||
at?.startsWith("sensor.")
|
|
||||||
? at
|
? at
|
||||||
: undefined;
|
: undefined;
|
||||||
const time = entity ? undefined : (at as string | 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 data = this._data(this._inputMode, at);
|
||||||
const showOffset =
|
const schema = this._schema(this.hass.localize, data.mode);
|
||||||
data.mode === MODE_ENTITY && data.entity?.startsWith("sensor.");
|
|
||||||
const schema = this._schema(this.hass.localize, data.mode, !!showOffset);
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-form
|
<ha-form
|
||||||
@ -157,9 +151,6 @@ export class HaTimeTrigger extends LitElement implements TriggerElement {
|
|||||||
delete newValue.offset;
|
delete newValue.offset;
|
||||||
} else {
|
} else {
|
||||||
delete newValue.time;
|
delete newValue.time;
|
||||||
if (!newValue.entity?.startsWith("sensor.")) {
|
|
||||||
delete newValue.offset;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
fireEvent(this, "value-changed", {
|
fireEvent(this, "value-changed", {
|
||||||
value: {
|
value: {
|
||||||
|
@ -3704,7 +3704,7 @@
|
|||||||
},
|
},
|
||||||
"time": {
|
"time": {
|
||||||
"type_value": "Fixed time",
|
"type_value": "Fixed time",
|
||||||
"type_input": "Value of a date/time helper, time entity or timestamp-class sensor",
|
"type_input": "Value of a date/time helper or timestamp-class sensor",
|
||||||
"label": "Time",
|
"label": "Time",
|
||||||
"at": "At time",
|
"at": "At time",
|
||||||
"offset": "[%key:ui::panel::config::automation::editor::triggers::type::sun::offset%]",
|
"offset": "[%key:ui::panel::config::automation::editor::triggers::type::sun::offset%]",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user