Skip to content

Commit 3b37ec3

Browse files
authored
[FEATURE] Add entity picker and icon picker to visual editor
Resolves: #196
1 parent 93d6cd3 commit 3b37ec3

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/editor.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ import styles from './editor.styles';
44
export class WeekPlannerCardEditor extends LitElement {
55
static styles = styles;
66

7+
connectedCallback() {
8+
super.connectedCallback();
9+
this.loadCustomElements();
10+
}
11+
12+
async loadCustomElements() {
13+
if (!customElements.get("ha-entity-picker")) {
14+
await customElements.get("hui-entities-card").getConfigElement();
15+
}
16+
}
17+
718
static get properties() {
819
return {
920
hass: {},
@@ -31,10 +42,10 @@ export class WeekPlannerCardEditor extends LitElement {
3142
${this.addExpansionPanel(
3243
`Calendar: ${calendar.name ?? calendar.entity}`,
3344
html`
34-
${this.addTextField('calendars.' + index + '.entity', 'Entity')}
45+
${this.addEntityPickerField('calendars.' + index + '.entity', 'Entity', ['calendar'])}
3546
${this.addTextField('calendars.' + index + '.name', 'Name')}
3647
${this.addTextField('calendars.' + index + '.color', 'Color')}
37-
${this.addTextField('calendars.' + index + '.icon', 'Icon')}
48+
${this.addIconPickerField('calendars.' + index + '.icon', 'Icon')}
3849
${this.addTextField('calendars.' + index + '.filter', 'Filter events (regex)')}
3950
${this.addTextField('calendars.' + index + '.filterText', 'Filter event text (regex)')}
4051
${this.addBooleanField('calendars.' + index + '.hideInLegend', 'Hide in legend')}
@@ -125,7 +136,7 @@ export class WeekPlannerCardEditor extends LitElement {
125136
${this.addExpansionPanel(
126137
'Weather',
127138
html`
128-
${this.addTextField('weather.entity', 'Weather entity')}
139+
${this.addEntityPickerField('weather.entity', 'Weather entity', ['weather'])}
129140
${this.addBooleanField('weather.showCondition', 'Show condition icon')}
130141
${this.addBooleanField('weather.showTemperature', 'Show temperature')}
131142
${this.addBooleanField('weather.showLowTemperature', 'Show low temperature')}
@@ -181,6 +192,31 @@ export class WeekPlannerCardEditor extends LitElement {
181192
`;
182193
}
183194

195+
addEntityPickerField(name, label, includeDomains) {
196+
return html`
197+
<ha-entity-picker
198+
.hass="${this.hass}"
199+
name="${name}"
200+
label="${label ?? name}"
201+
value="${this.getConfigValue(name)}"
202+
.includeDomains="${includeDomains}"
203+
@change="${this._valueChanged}"
204+
/>
205+
`;
206+
}
207+
208+
addIconPickerField(name, label) {
209+
return html`
210+
<ha-icon-picker
211+
.hass="${this.hass}"
212+
name="${name}"
213+
label="${label ?? name}"
214+
value="${this.getConfigValue(name)}"
215+
@change="${this._valueChanged}"
216+
/>
217+
`;
218+
}
219+
184220
addSelectField(name, label, options, clearable) {
185221
return html`
186222
<ha-select

src/editor.styles.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export default css`
55
ha-select,
66
ha-formfield,
77
ha-expansion-panel,
8-
ha-button {
8+
ha-button,
9+
ha-entity-picker,
10+
ha-icon-picker {
911
margin: 8px 0;
1012
}
1113
`;

0 commit comments

Comments
 (0)