Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/data/automation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export interface StateCondition {
entity_id: string;
attribute?: string;
state: string | number;
for?: string | number | ForDict;
}

export interface NumericStateCondition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -21,6 +21,23 @@ export class HaStateCondition extends LitElement implements ConditionElement {

protected render() {
const { entity_id, attribute, state } = this.condition;
let trgFor = this.condition.for;

if (
trgFor &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let give this variable a logical name, like for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not exactly that, but something better, yes.
forTime?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree and the variable is now renamed

((trgFor as ForDict).hours ||
(trgFor as ForDict).minutes ||
(trgFor 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 } = trgFor as ForDict;
hours = hours.toString().padStart(2, "0");
minutes = minutes.toString().padStart(2, "0");
seconds = seconds.toString().padStart(2, "0");

trgFor = `${hours}:${minutes}:${seconds}`;
}

return html`
<ha-entity-picker
Expand Down Expand Up @@ -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=${trgFor}
@value-changed=${this._valueChanged}
></paper-input>
`;
}

Expand Down