Skip to content

Commit

Permalink
[FEATURE] Add entity picker and icon picker to visual editor
Browse files Browse the repository at this point in the history
Resolves: #196
  • Loading branch information
FamousWolf authored Nov 21, 2024
1 parent 93d6cd3 commit 3b37ec3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
42 changes: 39 additions & 3 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ import styles from './editor.styles';
export class WeekPlannerCardEditor extends LitElement {
static styles = styles;

connectedCallback() {
super.connectedCallback();
this.loadCustomElements();
}

async loadCustomElements() {
if (!customElements.get("ha-entity-picker")) {
await customElements.get("hui-entities-card").getConfigElement();
}
}

static get properties() {
return {
hass: {},
Expand Down Expand Up @@ -31,10 +42,10 @@ export class WeekPlannerCardEditor extends LitElement {
${this.addExpansionPanel(
`Calendar: ${calendar.name ?? calendar.entity}`,
html`
${this.addTextField('calendars.' + index + '.entity', 'Entity')}
${this.addEntityPickerField('calendars.' + index + '.entity', 'Entity', ['calendar'])}
${this.addTextField('calendars.' + index + '.name', 'Name')}
${this.addTextField('calendars.' + index + '.color', 'Color')}
${this.addTextField('calendars.' + index + '.icon', 'Icon')}
${this.addIconPickerField('calendars.' + index + '.icon', 'Icon')}
${this.addTextField('calendars.' + index + '.filter', 'Filter events (regex)')}
${this.addTextField('calendars.' + index + '.filterText', 'Filter event text (regex)')}
${this.addBooleanField('calendars.' + index + '.hideInLegend', 'Hide in legend')}
Expand Down Expand Up @@ -125,7 +136,7 @@ export class WeekPlannerCardEditor extends LitElement {
${this.addExpansionPanel(
'Weather',
html`
${this.addTextField('weather.entity', 'Weather entity')}
${this.addEntityPickerField('weather.entity', 'Weather entity', ['weather'])}
${this.addBooleanField('weather.showCondition', 'Show condition icon')}
${this.addBooleanField('weather.showTemperature', 'Show temperature')}
${this.addBooleanField('weather.showLowTemperature', 'Show low temperature')}
Expand Down Expand Up @@ -181,6 +192,31 @@ export class WeekPlannerCardEditor extends LitElement {
`;
}

addEntityPickerField(name, label, includeDomains) {
return html`
<ha-entity-picker
.hass="${this.hass}"
name="${name}"
label="${label ?? name}"
value="${this.getConfigValue(name)}"
.includeDomains="${includeDomains}"
@change="${this._valueChanged}"
/>
`;
}

addIconPickerField(name, label) {
return html`
<ha-icon-picker
.hass="${this.hass}"
name="${name}"
label="${label ?? name}"
value="${this.getConfigValue(name)}"
@change="${this._valueChanged}"
/>
`;
}

addSelectField(name, label, options, clearable) {
return html`
<ha-select
Expand Down
4 changes: 3 additions & 1 deletion src/editor.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export default css`
ha-select,
ha-formfield,
ha-expansion-panel,
ha-button {
ha-button,
ha-entity-picker,
ha-icon-picker {
margin: 8px 0;
}
`;

0 comments on commit 3b37ec3

Please sign in to comment.