-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Geo Location Trigger to HA - Form #11644
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
+41
−77
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a5ad7e4
geolocation conversion
zsarnett baac1d8
Geo Location Converstion
zsarnett bb772c8
Update value changed
zsarnett 2fd0c19
Update src/panels/config/automation/trigger/types/ha-automation-trigg…
zsarnett a2df067
Moemoize
zsarnett 5a0cfc2
prettier
zsarnett 31b53e5
Update src/panels/config/automation/trigger/types/ha-automation-trigg…
zsarnett af2d20a
review
zsarnett aa6d595
Merge branch 'geo-location-ha-form' of https://github.com/home-assist…
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,19 @@ | ||
| import { css, html, LitElement } from "lit"; | ||
| import { customElement, property } from "lit/decorators"; | ||
| import "../../../../../components/ha-form/ha-form"; | ||
| import { html, LitElement } from "lit"; | ||
| import { customElement, property, state } from "lit/decorators"; | ||
| import { fireEvent } from "../../../../../common/dom/fire_event"; | ||
| import "../../../../../components/entity/ha-entity-picker"; | ||
| import type { HaRadio } from "../../../../../components/ha-radio"; | ||
| import { HaFormSchema } from "../../../../../components/ha-form/types"; | ||
| import type { GeoLocationTrigger } from "../../../../../data/automation"; | ||
| import type { HomeAssistant } from "../../../../../types"; | ||
| import { handleChangeEvent } from "../ha-automation-trigger-row"; | ||
|
|
||
| const includeDomains = ["zone"]; | ||
|
|
||
| @customElement("ha-automation-trigger-geo_location") | ||
| export class HaGeolocationTrigger extends LitElement { | ||
| @property({ attribute: false }) public hass!: HomeAssistant; | ||
|
|
||
| @property({ attribute: false }) public trigger!: GeoLocationTrigger; | ||
|
|
||
| @state() private _schema?: HaFormSchema[]; | ||
|
|
||
| public static get defaultConfig() { | ||
| return { | ||
| source: "", | ||
|
|
@@ -23,87 +22,63 @@ export class HaGeolocationTrigger extends LitElement { | |
| }; | ||
| } | ||
|
|
||
| protected firstUpdated(): void { | ||
| if (!this.hass) { | ||
| return; | ||
| } | ||
|
|
||
| this._schema = [ | ||
| { name: "source", selector: { text: {} } }, | ||
| { name: "zone", selector: { entity: { domain: "zone" } } }, | ||
| { | ||
| name: "event", | ||
| type: "select", | ||
| required: true, | ||
| options: [ | ||
| [ | ||
| "enter", | ||
| this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.enter" | ||
| ), | ||
| ], | ||
| [ | ||
| "leave", | ||
| this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.leave" | ||
| ), | ||
| ], | ||
| ], | ||
| }, | ||
| ]; | ||
| } | ||
|
|
||
| protected render() { | ||
| const { source, zone, event } = this.trigger; | ||
| if (!this._schema) { | ||
|
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. this is not possible |
||
| return html``; | ||
| } | ||
|
|
||
| return html` | ||
| <paper-input | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.source" | ||
| )} | ||
| name="source" | ||
| .value=${source} | ||
| @value-changed=${this._valueChanged} | ||
| ></paper-input> | ||
| <ha-entity-picker | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.zone" | ||
| )} | ||
| .value=${zone} | ||
| @value-changed=${this._zonePicked} | ||
| <ha-form | ||
| .schema=${this._schema} | ||
| .data=${this.trigger} | ||
| .hass=${this.hass} | ||
| allow-custom-entity | ||
| .includeDomains=${includeDomains} | ||
| ></ha-entity-picker> | ||
| <label> | ||
| ${this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.event" | ||
| )} | ||
| <ha-formfield | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.enter" | ||
| )} | ||
| > | ||
| <ha-radio | ||
| name="event" | ||
| value="enter" | ||
| .checked=${event === "enter"} | ||
| @change=${this._radioGroupPicked} | ||
| ></ha-radio> | ||
| </ha-formfield> | ||
| <ha-formfield | ||
| .label=${this.hass.localize( | ||
| "ui.panel.config.automation.editor.triggers.type.geo_location.leave" | ||
| )} | ||
| > | ||
| <ha-radio | ||
| name="event" | ||
| value="leave" | ||
| .checked=${event === "leave"} | ||
| @change=${this._radioGroupPicked} | ||
| ></ha-radio> | ||
| </ha-formfield> | ||
| </label> | ||
| .computeLabel=${this._computeLabelCallback} | ||
| @value-changed=${this._valueChanged} | ||
| ></ha-form> | ||
| `; | ||
| } | ||
|
|
||
| private _valueChanged(ev: CustomEvent): void { | ||
| handleChangeEvent(this, ev); | ||
| } | ||
|
|
||
| private _zonePicked(ev: CustomEvent) { | ||
| ev.stopPropagation(); | ||
| fireEvent(this, "value-changed", { | ||
| value: { ...this.trigger, zone: ev.detail.value }, | ||
| }); | ||
| const newTrigger = ev.detail.value; | ||
| fireEvent(this, "value-changed", { value: newTrigger }); | ||
| } | ||
|
|
||
| private _radioGroupPicked(ev: CustomEvent) { | ||
| ev.stopPropagation(); | ||
| fireEvent(this, "value-changed", { | ||
| value: { | ||
| ...this.trigger, | ||
| event: (ev.target as HaRadio).value, | ||
| }, | ||
| }); | ||
| private _computeLabelCallback(schema: HaFormSchema): string { | ||
|
zsarnett marked this conversation as resolved.
Outdated
|
||
| return this.hass.localize( | ||
| `ui.panel.config.automation.editor.triggers.type.geo_location.${schema.name}` | ||
| ); | ||
| } | ||
|
|
||
| static styles = css` | ||
| label { | ||
| display: flex; | ||
| align-items: center; | ||
| } | ||
| `; | ||
| } | ||
|
|
||
| declare global { | ||
|
|
||
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.
Generate schema using memoizeOne that takes
localize: LocalizeFunc. That way when translations update, the schema updates too.