From 8bd33d77da5bd4691798d7a93df1fb50e1d84ccb Mon Sep 17 00:00:00 2001
From: avee87 <6134677+avee87@users.noreply.github.com>
Date: Wed, 6 Jul 2022 22:34:45 +0100
Subject: [PATCH] Refactored items a bit
---
dist/weather-card.js | 73 ++++++++++++++++++++++++++------------------
1 file changed, 43 insertions(+), 30 deletions(-)
diff --git a/dist/weather-card.js b/dist/weather-card.js
index f66b4aec..5be38169 100644
--- a/dist/weather-card.js
+++ b/dist/weather-card.js
@@ -191,39 +191,48 @@ class WeatherCard extends LitElement {
const items = [];
if (stateObj.attributes.humidity != null) {
- items.push(html`
-
- ${stateObj.attributes.humidity} %
- `);
+ items.push(
+ this.renderItem(
+ "mdi:water-percent",
+ stateObj.attributes.humidity,
+ this.getUnit("humidity"),
+ ),
+ );
}
if (stateObj.attributes.wind_speed != null) {
const windBearing = stateObj.attributes.wind_bearing;
+ const windDirection = windBearing != null
+ ? this.getWindDirection(windBearing)
+ : "";
- items.push(html`
-
- ${windBearing != null
- ? this.getWindDirection(windBearing)
- : ""}
- ${stateObj.attributes.wind_speed}
- ${this.getUnit("wind_speed")}
-
- `);
+ items.push(
+ this.renderItem(
+ "mdi:weather-windy",
+ windDirection + " " + stateObj.attributes.wind_speed,
+ this.getUnit("wind_speed"),
+ ),
+ );
}
if (stateObj.attributes.pressure != null) {
- items.push(html`
-
- ${stateObj.attributes.pressure}
- ${this.getUnit("air_pressure")}
- `);
+ items.push(
+ this.renderItem(
+ "mdi:gauge",
+ stateObj.attributes.pressure,
+ this.getUnit("air_pressure"),
+ ),
+ );
}
if (stateObj.attributes.visibility != null) {
- items.push(html`
- ${stateObj.attributes
- .visibility} ${this.getUnit("visibility")}
- `);
+ items.push(
+ this.renderItem(
+ "mdi:weather-fog",
+ stateObj.attributes.visibility,
+ this.getUnit("visibility"),
+ ),
+ );
}
const sun = this.hass.states['sun.sun'];
@@ -241,14 +250,8 @@ class WeatherCard extends LitElement {
items.push(html`
`);
}
- items.push(html`
-
- ${next_rising}
- `);
- items.push(html`
-
- ${next_setting}
- `);
+ items.push(this.renderItem("mdi:weather-sunset-up", next_rising));
+ items.push(this.renderItem("mdi:weather-sunset-down", next_setting));
}
const listItems = items.map(item => html`${item}`);
@@ -260,6 +263,14 @@ class WeatherCard extends LitElement {
`;
}
+ renderItem(icon, value, unit) {
+ return html`
+
+ ${value}
+ ${unit != null ? html` ${unit} ` : ""}
+ `;
+ }
+
renderForecast(forecast, lang) {
if (!forecast || forecast.length === 0) {
return html``;
@@ -356,6 +367,8 @@ class WeatherCard extends LitElement {
switch (measure) {
case "air_pressure":
return attributes.pressure_unit ?? (lengthUnit === "km" ? "hPa" : "inHg");
+ case "humidity":
+ return "%";
case "precipitation":
return attributes.precipitation_unit ?? (lengthUnit === "km" ? "mm" : "in");
case "precipitation_probability":