Skip to content

Commit

Permalink
Merge pull request #250 from mlamberts78/develop
Browse files Browse the repository at this point in the history
Fix entity selection in card editor
  • Loading branch information
mlamberts78 authored Oct 3, 2024
2 parents 3f68632 + 88b5243 commit 71be08f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 64 deletions.
56 changes: 24 additions & 32 deletions dist/weather-chart-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,7 @@ class WeatherChartCardEditor extends s {
this.hass.states[config.entity].attributes &&
this.hass.states[config.entity].attributes.description !== undefined
) || config.description !== undefined;
this.fetchEntities();
this.requestUpdate();
}

Expand All @@ -952,10 +953,19 @@ class WeatherChartCardEditor extends s {

fetchEntities() {
if (this.hass) {
this.entities = Object.keys(this.hass.states).filter((e) =>
e.startsWith('weather.')
);
this.entities = Object.keys(this.hass.states).filter((e) => e.startsWith('weather.'));
this.requestUpdate();
}
}

_EntityChanged(event, key) {
if (!this._config) {
return;
}
const newConfig = { ...this._config };
newConfig.entity = event.target.value;
this._entity = event.target.value;
this.configChanged(newConfig);
}

configChanged(newConfig) {
Expand All @@ -967,22 +977,6 @@ class WeatherChartCardEditor extends s {
this.dispatchEvent(event);
}

_EntityChanged(event, key) {
if (!this._config) {
return;
}

const newConfig = { ...this._config };

if (key === 'entity') {
newConfig.entity = event.target.value;
this._entity = event.target.value;
}

this.configChanged(newConfig);
this.requestUpdate();
}

_valueChanged(event, key) {
if (!this._config) {
return;
Expand Down Expand Up @@ -1146,19 +1140,17 @@ class WeatherChartCardEditor extends s {
</style>
<div>
<div class="textfield-container">
<ha-select
naturalMenuWidth
fixedMenuPosition
label="Entity"
.configValue=${'entity'}
.value=${this._entity}
@change=${(e) => this._EntityChanged(e, 'entity')}
@closed=${(ev) => ev.stopPropagation()}
>
${this.entities.map((entity) => {
return x`<ha-list-item .value=${entity}>${entity}</ha-list-item>`;
})}
</ha-select>
<ha-select
naturalMenuWidth
fixedMenuPosition
label="Entity"
.configValue=${'entity'}
.value=${this._entity}
@change=${(e) => this._EntityChanged(e, 'entity')}
@closed=${(ev) => ev.stopPropagation()}
>
${this.entities.map((entity) => x`<ha-list-item .value=${entity}>${entity}</ha-list-item>`)}
</ha-select>
<ha-textfield
label="Title"
.value="${this._config.title || ''}"
Expand Down
56 changes: 24 additions & 32 deletions src/weather-chart-card-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class WeatherChartCardEditor extends LitElement {
this.hass.states[config.entity].attributes &&
this.hass.states[config.entity].attributes.description !== undefined
) || config.description !== undefined;
this.fetchEntities();
this.requestUpdate();
}

Expand All @@ -87,12 +88,21 @@ class WeatherChartCardEditor extends LitElement {

fetchEntities() {
if (this.hass) {
this.entities = Object.keys(this.hass.states).filter((e) =>
e.startsWith('weather.')
);
this.entities = Object.keys(this.hass.states).filter((e) => e.startsWith('weather.'));
this.requestUpdate();
}
}

_EntityChanged(event, key) {
if (!this._config) {
return;
}
const newConfig = { ...this._config };
newConfig.entity = event.target.value;
this._entity = event.target.value;
this.configChanged(newConfig);
}

configChanged(newConfig) {
const event = new Event("config-changed", {
bubbles: true,
Expand All @@ -102,22 +112,6 @@ class WeatherChartCardEditor extends LitElement {
this.dispatchEvent(event);
}

_EntityChanged(event, key) {
if (!this._config) {
return;
}

const newConfig = { ...this._config };

if (key === 'entity') {
newConfig.entity = event.target.value;
this._entity = event.target.value;
}

this.configChanged(newConfig);
this.requestUpdate();
}

_valueChanged(event, key) {
if (!this._config) {
return;
Expand Down Expand Up @@ -281,19 +275,17 @@ class WeatherChartCardEditor extends LitElement {
</style>
<div>
<div class="textfield-container">
<ha-select
naturalMenuWidth
fixedMenuPosition
label="Entity"
.configValue=${'entity'}
.value=${this._entity}
@change=${(e) => this._EntityChanged(e, 'entity')}
@closed=${(ev) => ev.stopPropagation()}
>
${this.entities.map((entity) => {
return html`<ha-list-item .value=${entity}>${entity}</ha-list-item>`;
})}
</ha-select>
<ha-select
naturalMenuWidth
fixedMenuPosition
label="Entity"
.configValue=${'entity'}
.value=${this._entity}
@change=${(e) => this._EntityChanged(e, 'entity')}
@closed=${(ev) => ev.stopPropagation()}
>
${this.entities.map((entity) => html`<ha-list-item .value=${entity}>${entity}</ha-list-item>`)}
</ha-select>
<ha-textfield
label="Title"
.value="${this._config.title || ''}"
Expand Down

0 comments on commit 71be08f

Please sign in to comment.