-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Automation Conditions to conversion to ha-form or mwc #11727
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
56367ac
Conditions to ha-form and mwc
zsarnett e83b1d5
Update src/panels/config/automation/condition/ha-automation-condition…
zsarnett 768551c
lint partially
zsarnett 3b23159
add type to options
zsarnett 589c0d7
requires
zsarnett a97804b
Reviews
zsarnett 392cbf2
add margin
zsarnett b1182db
reviews
zsarnett b7a36de
autogrow
zsarnett 004bc87
remvoe colon
zsarnett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 7 additions & 4 deletions
11
src/panels/config/automation/condition/types/ha-automation-condition-logical.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 44 additions & 50 deletions
94
src/panels/config/automation/condition/types/ha-automation-condition-numeric_state.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,78 +1,72 @@ | ||
| import "@polymer/paper-input/paper-input"; | ||
| import "@polymer/paper-input/paper-textarea"; | ||
| import "../../../../../components/ha-form/ha-form"; | ||
| import { html, LitElement } from "lit"; | ||
| import { customElement, property } from "lit/decorators"; | ||
| import "../../../../../components/entity/ha-entity-picker"; | ||
| import memoizeOne from "memoize-one"; | ||
| import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
| import type { HaFormSchema } from "../../../../../components/ha-form/types"; | ||
| import { NumericStateCondition } from "../../../../../data/automation"; | ||
| import { HomeAssistant } from "../../../../../types"; | ||
| import { handleChangeEvent } from "../ha-automation-condition-row"; | ||
| import type { HomeAssistant } from "../../../../../types"; | ||
|
|
||
| @customElement("ha-automation-condition-numeric_state") | ||
| export default class HaNumericStateCondition extends LitElement { | ||
| @property({ attribute: false }) public hass!: HomeAssistant; | ||
|
|
||
| @property() public condition!: NumericStateCondition; | ||
| @property({ attribute: false }) public condition!: NumericStateCondition; | ||
|
|
||
| public static get defaultConfig() { | ||
| return { | ||
| entity_id: "", | ||
| }; | ||
| } | ||
|
|
||
| private _schema = memoizeOne((entityId): HaFormSchema[] => [ | ||
| { name: "entity_id", required: true, selector: { entity: {} } }, | ||
| { | ||
| name: "attribute", | ||
| selector: { attribute: { entity_id: entityId } }, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One day I hope we can make ha-form fields "context aware", for example, we would tell this selector to use the entity from |
||
| }, | ||
| { name: "above", selector: { text: {} } }, | ||
| { name: "below", selector: { text: {} } }, | ||
| { | ||
| name: "value_template", | ||
| selector: { text: { multiline: true } }, | ||
| }, | ||
| ]); | ||
|
|
||
| public render() { | ||
| const { value_template, entity_id, attribute, below, above } = | ||
| this.condition; | ||
| const schema = this._schema(this.condition.entity_id); | ||
|
|
||
| return html` | ||
| <ha-entity-picker | ||
| .value=${entity_id} | ||
| .name=${"entity_id"} | ||
| @value-changed=${this._valueChanged} | ||
| <ha-form | ||
| .hass=${this.hass} | ||
| allow-custom-entity | ||
| ></ha-entity-picker> | ||
| <ha-entity-attribute-picker | ||
| .hass=${this.hass} | ||
| .entityId=${entity_id} | ||
| .value=${attribute} | ||
| .name=${"attribute"} | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.state.attribute" | ||
| )} | ||
| @value-changed=${this._valueChanged} | ||
| allow-custom-value | ||
| ></ha-entity-attribute-picker> | ||
| <paper-input | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.conditions.type.numeric_state.above" | ||
| )} | ||
| name="above" | ||
| .value=${above} | ||
| .data=${this.condition} | ||
| .schema=${schema} | ||
| @value-changed=${this._valueChanged} | ||
| ></paper-input> | ||
| <paper-input | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.conditions.type.numeric_state.below" | ||
| )} | ||
| name="below" | ||
| .value=${below} | ||
| @value-changed=${this._valueChanged} | ||
| ></paper-input> | ||
| <paper-textarea | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.conditions.type.numeric_state.value_template" | ||
| )} | ||
| name="value_template" | ||
| .value=${value_template} | ||
| @value-changed=${this._valueChanged} | ||
| dir="ltr" | ||
| ></paper-textarea> | ||
| .computeLabel=${this._computeLabelCallback} | ||
| ></ha-form> | ||
| `; | ||
| } | ||
|
|
||
| private _valueChanged(ev: CustomEvent): void { | ||
| handleChangeEvent(this, ev); | ||
| ev.stopPropagation(); | ||
| const newTrigger = ev.detail.value; | ||
| fireEvent(this, "value-changed", { value: newTrigger }); | ||
| } | ||
|
|
||
| private _computeLabelCallback = (schema: HaFormSchema): string => { | ||
| switch (schema.name) { | ||
| case "entity_id": | ||
| return this.hass.localize("ui.components.entity.entity-picker.entity"); | ||
| case "attribute": | ||
| return this.hass.localize( | ||
| "ui.components.entity.entity-attribute-picker.attribute" | ||
| ); | ||
| default: | ||
| return this.hass.localize( | ||
| `ui.panel.config.automation.editor.triggers.type.numeric_state.${schema.name}` | ||
| ); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| declare global { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.