mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 19:56:42 +00:00
Automation - State Condition display 'for:' in frontend (#8124)
* Automation - State Condition display 'for:' in frontend * rename variable to better name
This commit is contained in:
parent
f42587af22
commit
aba0e1f026
@ -157,6 +157,7 @@ export interface StateCondition {
|
|||||||
entity_id: string;
|
entity_id: string;
|
||||||
attribute?: string;
|
attribute?: string;
|
||||||
state: string | number;
|
state: string | number;
|
||||||
|
for?: string | number | ForDict;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface NumericStateCondition {
|
export interface NumericStateCondition {
|
||||||
|
@ -2,7 +2,7 @@ import "@polymer/paper-input/paper-input";
|
|||||||
import { customElement, html, LitElement, property } from "lit-element";
|
import { customElement, html, LitElement, property } from "lit-element";
|
||||||
import "../../../../../components/entity/ha-entity-attribute-picker";
|
import "../../../../../components/entity/ha-entity-attribute-picker";
|
||||||
import "../../../../../components/entity/ha-entity-picker";
|
import "../../../../../components/entity/ha-entity-picker";
|
||||||
import { StateCondition } from "../../../../../data/automation";
|
import { ForDict, StateCondition } from "../../../../../data/automation";
|
||||||
import { HomeAssistant } from "../../../../../types";
|
import { HomeAssistant } from "../../../../../types";
|
||||||
import {
|
import {
|
||||||
ConditionElement,
|
ConditionElement,
|
||||||
@ -21,6 +21,23 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
|||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
const { entity_id, attribute, state } = this.condition;
|
const { entity_id, attribute, state } = this.condition;
|
||||||
|
let forTime = this.condition.for;
|
||||||
|
|
||||||
|
if (
|
||||||
|
forTime &&
|
||||||
|
((forTime as ForDict).hours ||
|
||||||
|
(forTime as ForDict).minutes ||
|
||||||
|
(forTime as ForDict).seconds)
|
||||||
|
) {
|
||||||
|
// If the trigger was defined using the yaml dict syntax, convert it to
|
||||||
|
// the equivalent string format
|
||||||
|
let { hours = 0, minutes = 0, seconds = 0 } = forTime as ForDict;
|
||||||
|
hours = hours.toString().padStart(2, "0");
|
||||||
|
minutes = minutes.toString().padStart(2, "0");
|
||||||
|
seconds = seconds.toString().padStart(2, "0");
|
||||||
|
|
||||||
|
forTime = `${hours}:${minutes}:${seconds}`;
|
||||||
|
}
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-entity-picker
|
<ha-entity-picker
|
||||||
@ -49,6 +66,14 @@ export class HaStateCondition extends LitElement implements ConditionElement {
|
|||||||
.value=${state}
|
.value=${state}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
></paper-input>
|
></paper-input>
|
||||||
|
<paper-input
|
||||||
|
.label=${this.hass.localize(
|
||||||
|
"ui.panel.config.automation.editor.triggers.type.state.for"
|
||||||
|
)}
|
||||||
|
.name=${"for"}
|
||||||
|
.value=${forTime}
|
||||||
|
@value-changed=${this._valueChanged}
|
||||||
|
></paper-input>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user