-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Automation editor tweaks #6713
Merged
Merged
Automation editor tweaks #6713
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2ede932
Automation editor tweaks
bramkragten 45973fc
Update ha-automation-trigger-row.ts
bramkragten 112e038
Update ha-entity-attribute-picker.ts
bramkragten 0464065
Update en.json
bramkragten 3f95cdc
Change time input layout
bramkragten 2f52918
Console
bramkragten 0cdaa76
fix dialog box
bramkragten 372d392
comments and more tweaks
bramkragten 181386e
Fix duplicate when dirty
bramkragten 1bcd0e0
Update src/panels/config/automation/action/types/ha-automation-action…
bramkragten 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 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 |
---|---|---|
@@ -0,0 +1,178 @@ | ||
import "@polymer/paper-input/paper-input"; | ||
import "@polymer/paper-item/paper-item"; | ||
import "@vaadin/vaadin-combo-box/theme/material/vaadin-combo-box-light"; | ||
import { HassEntity } from "home-assistant-js-websocket"; | ||
import { | ||
css, | ||
CSSResult, | ||
customElement, | ||
html, | ||
LitElement, | ||
property, | ||
PropertyValues, | ||
query, | ||
TemplateResult, | ||
} from "lit-element"; | ||
import { fireEvent } from "../../common/dom/fire_event"; | ||
import { PolymerChangedEvent } from "../../polymer-types"; | ||
import { HomeAssistant } from "../../types"; | ||
import "../ha-icon-button"; | ||
import "./state-badge"; | ||
|
||
export type HaEntityPickerEntityFilterFunc = (entityId: HassEntity) => boolean; | ||
|
||
const rowRenderer = (root: HTMLElement, _owner, model: { item: string }) => { | ||
if (!root.firstElementChild) { | ||
root.innerHTML = ` | ||
<style> | ||
paper-item { | ||
margin: -10px; | ||
padding: 0; | ||
} | ||
</style> | ||
<paper-item></paper-item> | ||
`; | ||
} | ||
root.querySelector("paper-item")!.textContent = model.item; | ||
}; | ||
|
||
@customElement("ha-entity-attribute-picker") | ||
class HaEntityAttributePicker extends LitElement { | ||
@property({ attribute: false }) public hass!: HomeAssistant; | ||
|
||
@property() public entityId?: string; | ||
|
||
@property({ type: Boolean }) public autofocus = false; | ||
|
||
@property({ type: Boolean }) public disabled = false; | ||
|
||
@property({ type: Boolean, attribute: "allow-custom-value" }) | ||
public allowCustomValue; | ||
|
||
@property() public label?: string; | ||
|
||
@property() public value?: string; | ||
|
||
@property({ type: Boolean }) private _opened = false; | ||
|
||
@query("vaadin-combo-box-light") private _comboBox!: HTMLElement; | ||
|
||
protected shouldUpdate(changedProps: PropertyValues) { | ||
return !(!changedProps.has("_opened") && this._opened); | ||
} | ||
|
||
protected updated(changedProps: PropertyValues) { | ||
if (changedProps.has("_opened") && this._opened) { | ||
const state = this.entityId ? this.hass.states[this.entityId] : undefined; | ||
(this._comboBox as any).items = state | ||
? Object.keys(state.attributes) | ||
: []; | ||
} | ||
} | ||
|
||
protected render(): TemplateResult { | ||
if (!this.hass) { | ||
return html``; | ||
} | ||
|
||
return html` | ||
<vaadin-combo-box-light | ||
.value=${this._value} | ||
.allowCustomValue=${this.allowCustomValue} | ||
.renderer=${rowRenderer} | ||
@opened-changed=${this._openedChanged} | ||
@value-changed=${this._valueChanged} | ||
> | ||
<paper-input | ||
.autofocus=${this.autofocus} | ||
.label=${this.label ?? | ||
this.hass.localize( | ||
"ui.components.entity.entity-attribute-picker.attribute" | ||
)} | ||
.value=${this._value} | ||
.disabled=${this.disabled || !this.entityId} | ||
class="input" | ||
autocapitalize="none" | ||
autocomplete="off" | ||
autocorrect="off" | ||
spellcheck="false" | ||
> | ||
${this.value | ||
? html` | ||
<ha-icon-button | ||
aria-label=${this.hass.localize( | ||
"ui.components.entity.entity-picker.clear" | ||
)} | ||
slot="suffix" | ||
class="clear-button" | ||
icon="hass:close" | ||
@click=${this._clearValue} | ||
no-ripple | ||
> | ||
Clear | ||
</ha-icon-button> | ||
` | ||
: ""} | ||
|
||
<ha-icon-button | ||
aria-label=${this.hass.localize( | ||
"ui.components.entity.entity-attribute-picker.show_attributes" | ||
)} | ||
slot="suffix" | ||
class="toggle-button" | ||
.icon=${this._opened ? "hass:menu-up" : "hass:menu-down"} | ||
> | ||
Toggle | ||
</ha-icon-button> | ||
</paper-input> | ||
</vaadin-combo-box-light> | ||
`; | ||
} | ||
|
||
private _clearValue(ev: Event) { | ||
ev.stopPropagation(); | ||
this._setValue(""); | ||
} | ||
|
||
private get _value() { | ||
return this.value || ""; | ||
} | ||
|
||
private _openedChanged(ev: PolymerChangedEvent<boolean>) { | ||
this._opened = ev.detail.value; | ||
} | ||
|
||
private _valueChanged(ev: PolymerChangedEvent<string>) { | ||
const newValue = ev.detail.value; | ||
if (newValue !== this._value) { | ||
this._setValue(newValue); | ||
} | ||
} | ||
|
||
private _setValue(value: string) { | ||
this.value = value; | ||
setTimeout(() => { | ||
fireEvent(this, "value-changed", { value }); | ||
fireEvent(this, "change"); | ||
}, 0); | ||
} | ||
|
||
static get styles(): CSSResult { | ||
return css` | ||
paper-input > ha-icon-button { | ||
--mdc-icon-button-size: 24px; | ||
padding: 0px 2px; | ||
color: var(--secondary-text-color); | ||
} | ||
[hidden] { | ||
display: none; | ||
} | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-entity-attribute-picker": HaEntityAttributePicker; | ||
} | ||
} |
This file contains 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 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 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 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did not know
??
existed, nice one!