Skip to content

Commit 65e1eb5

Browse files
authored
Replace editor element with form (#165)
* Replace editor * Delete dist/weather-card-editor.js
1 parent 8773e03 commit 65e1eb5

File tree

2 files changed

+44
-237
lines changed

2 files changed

+44
-237
lines changed

dist/weather-card-editor.js

Lines changed: 0 additions & 216 deletions
This file was deleted.

dist/weather-card.js

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
const LitElement = customElements.get("ha-panel-lovelace") ? Object.getPrototypeOf(customElements.get("ha-panel-lovelace")) : Object.getPrototypeOf(customElements.get("hc-lovelace"));
1+
const LitElement = customElements.get("ha-panel-lovelace")
2+
? Object.getPrototypeOf(customElements.get("ha-panel-lovelace"))
3+
: Object.getPrototypeOf(customElements.get("hc-lovelace"));
24
const html = LitElement.prototype.html;
35
const css = LitElement.prototype.css;
46

@@ -96,9 +98,24 @@ class WeatherCard extends LitElement {
9698
};
9799
}
98100

99-
static async getConfigElement() {
100-
await import("./weather-card-editor.js");
101-
return document.createElement("weather-card-editor");
101+
static getConfigForm() {
102+
return {
103+
schema: [
104+
{
105+
name: "entity",
106+
required: true,
107+
selector: { entity: { domain: "weather" } },
108+
},
109+
{
110+
name: "name",
111+
selector: { text: {} },
112+
},
113+
{ name: "current", selector: { boolean: {} } },
114+
{ name: "details", selector: { boolean: {} } },
115+
{ name: "forecast", selector: { boolean: {} } },
116+
{ name: "hourly_forecast", selector: { boolean: {} } },
117+
],
118+
};
102119
}
103120

104121
static getStubConfig(hass, unusedEntities, allEntities) {
@@ -150,7 +167,9 @@ class WeatherCard extends LitElement {
150167
return html`
151168
<ha-card @click="${this._handleClick}">
152169
${this._config.current !== false ? this.renderCurrent(stateObj) : ""}
153-
${this._config.details !== false ? this.renderDetails(stateObj, lang) : ""}
170+
${this._config.details !== false
171+
? this.renderDetails(stateObj, lang)
172+
: ""}
154173
${this._config.forecast !== false
155174
? this.renderForecast(stateObj.attributes.forecast, lang)
156175
: ""}
@@ -190,14 +209,20 @@ class WeatherCard extends LitElement {
190209
let next_setting;
191210

192211
if (sun) {
193-
next_rising = new Date(sun.attributes.next_rising).toLocaleTimeString(lang, {
194-
hour: "2-digit",
195-
minute: "2-digit",
196-
});
197-
next_setting = new Date(sun.attributes.next_setting).toLocaleTimeString(lang, {
198-
hour: "2-digit",
199-
minute: "2-digit",
200-
});
212+
next_rising = new Date(sun.attributes.next_rising).toLocaleTimeString(
213+
lang,
214+
{
215+
hour: "2-digit",
216+
minute: "2-digit",
217+
}
218+
);
219+
next_setting = new Date(sun.attributes.next_setting).toLocaleTimeString(
220+
lang,
221+
{
222+
hour: "2-digit",
223+
minute: "2-digit",
224+
}
225+
);
201226
}
202227

203228
this.numberElements++;
@@ -219,15 +244,11 @@ class WeatherCard extends LitElement {
219244
<li>
220245
<ha-icon icon="mdi:gauge"></ha-icon>
221246
${stateObj.attributes.pressure}
222-
<span class="unit">
223-
${this.getUnit("air_pressure")}
224-
</span>
247+
<span class="unit"> ${this.getUnit("air_pressure")} </span>
225248
</li>
226249
<li>
227250
<ha-icon icon="mdi:weather-fog"></ha-icon> ${stateObj.attributes
228-
.visibility}<span class="unit">
229-
${this.getUnit("length")}
230-
</span>
251+
.visibility}<span class="unit"> ${this.getUnit("length")} </span>
231252
</li>
232253
${next_rising
233254
? html`
@@ -298,7 +319,8 @@ class WeatherCard extends LitElement {
298319
daily.precipitation !== null
299320
? html`
300321
<div class="precipitation">
301-
${Math.round(daily.precipitation*10)/10} ${this.getUnit("precipitation")}
322+
${Math.round(daily.precipitation * 10) / 10}
323+
${this.getUnit("precipitation")}
302324
</div>
303325
`
304326
: ""}
@@ -307,7 +329,8 @@ class WeatherCard extends LitElement {
307329
daily.precipitation_probability !== null
308330
? html`
309331
<div class="precipitation_probability">
310-
${Math.round(daily.precipitation_probability)} ${this.getUnit("precipitation_probability")}
332+
${Math.round(daily.precipitation_probability)}
333+
${this.getUnit("precipitation_probability")}
311334
</div>
312335
`
313336
: ""}

0 commit comments

Comments
 (0)