-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add Attribute Picker as a selector - add to state trigger #11641
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
166110e
Add Attribute Picker as a selector - add trigger
zsarnett a6b3d2b
Fix margin in ha-form to be consistent
zsarnett fd0796f
add gallery and types
zsarnett fd16b84
Go ahead and do duration too
zsarnett 3b5bf8a
add to ha-form as well
zsarnett ee63d19
Update src/components/ha-form/ha-form.ts
zsarnett File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import "../entity/ha-entity-attribute-picker"; | ||
zsarnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { html, LitElement } from "lit"; | ||
import { customElement, property } from "lit/decorators"; | ||
import { AttributeSelector } from "../../data/selector"; | ||
import { SubscribeMixin } from "../../mixins/subscribe-mixin"; | ||
import { HomeAssistant } from "../../types"; | ||
|
||
@customElement("ha-selector-attribute") | ||
export class HaSelectorAttribute extends SubscribeMixin(LitElement) { | ||
@property() public hass!: HomeAssistant; | ||
|
||
@property() public selector!: AttributeSelector; | ||
|
||
@property() public value?: any; | ||
|
||
@property() public label?: string; | ||
|
||
@property({ type: Boolean }) public disabled = false; | ||
|
||
protected render() { | ||
return html` | ||
<ha-entity-attribute-picker | ||
.hass=${this.hass} | ||
.entityId=${this.selector.attribute.entity_id} | ||
.value=${this.value} | ||
.label=${this.label} | ||
.disabled=${this.disabled} | ||
allow-custom-value | ||
></ha-entity-attribute-picker> | ||
`; | ||
} | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ha-selector-attribute": HaSelectorAttribute; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { | |
string, | ||
union, | ||
} from "superstruct"; | ||
import memoizeOne from "memoize-one"; | ||
import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
import { hasTemplate } from "../../../../../common/string/has-template"; | ||
import { StateTrigger } from "../../../../../data/automation"; | ||
|
@@ -33,6 +34,7 @@ const stateTriggerStruct = assign( | |
|
||
const SCHEMA = [ | ||
{ name: "entity_id", selector: { entity: {} } }, | ||
{ name: "attribute", selector: { attribute: { entity_id: "" } } }, | ||
{ name: "from", required: false, selector: { text: {} } }, | ||
{ name: "to", required: false, selector: { text: {} } }, | ||
{ name: "for", required: false, selector: { duration: {} } }, | ||
|
@@ -48,6 +50,15 @@ export class HaStateTrigger extends LitElement implements TriggerElement { | |
return { entity_id: "" }; | ||
} | ||
|
||
private _schema = memoizeOne((entityId) => { | ||
const schema = [...SCHEMA]; | ||
schema[1] = { | ||
name: "attribute", | ||
selector: { attribute: { entity_id: entityId } }, | ||
}; | ||
return schema; | ||
}); | ||
|
||
public shouldUpdate(changedProperties: PropertyValues) { | ||
if (!changedProperties.has("trigger")) { | ||
return true; | ||
|
@@ -81,12 +92,13 @@ export class HaStateTrigger extends LitElement implements TriggerElement { | |
const trgFor = createDurationData(this.trigger.for); | ||
|
||
const data = { ...this.trigger, ...{ for: trgFor } }; | ||
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. { ...this.trigger, for: trgFor } |
||
const schema = this._schema(this.trigger.entity_id); | ||
|
||
return html` | ||
<ha-form | ||
.hass=${this.hass} | ||
.data=${data} | ||
.schema=${SCHEMA} | ||
.schema=${schema} | ||
@value-changed=${this._valueChanged} | ||
.computeLabel=${this._computeLabelCallback} | ||
></ha-form> | ||
|
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.
Why is this necessary? The
selector
value is the schema in this case.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.
Adding features outside of the
selector
definition will break compatibility when selectors are used inservices.yaml
or blueprints.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.
This is needed for the value changed event
I removed it and now all selectors are broken
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.
All selectors work here https://design.home-assistant.io/#components/ha-form
Why does it fix it?
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.
When the value is changed and sent to the ha-form. Ha-form uses schema to find the name of the value
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.
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.
Then how does the selectors card on https://design.home-assistant.io/#components/ha-form work?
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.
Is it the latest dev?
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.
I broke it today