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:
Nikfinn99 2021-01-11 17:24:39 +01:00 committed by GitHub
parent f42587af22
commit aba0e1f026
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -157,6 +157,7 @@ export interface StateCondition {
entity_id: string;
attribute?: string;
state: string | number;
for?: string | number | ForDict;
}
export interface NumericStateCondition {

View File

@ -2,7 +2,7 @@ import "@polymer/paper-input/paper-input";
import { customElement, html, LitElement, property } from "lit-element";
import "../../../../../components/entity/ha-entity-attribute-picker";
import "../../../../../components/entity/ha-entity-picker";
import { StateCondition } from "../../../../../data/automation";
import { ForDict, StateCondition } from "../../../../../data/automation";
import { HomeAssistant } from "../../../../../types";
import {
ConditionElement,
@ -21,6 +21,23 @@ export class HaStateCondition extends LitElement implements ConditionElement {
protected render() {
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`
<ha-entity-picker
@ -49,6 +66,14 @@ export class HaStateCondition extends LitElement implements ConditionElement {
.value=${state}
@value-changed=${this._valueChanged}
></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>
`;
}