Skip to content

Commit a49fbed

Browse files
authored
[weather] better null value handling for weather type (#3892)
As mentioned [here](#3878 (comment)) our weather module needs a bit better handling for null values in the type field. This pr adds this and cleans up the layout a little.
1 parent 777b49c commit a49fbed

File tree

5 files changed

+16
-10
lines changed

5 files changed

+16
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Thanks to: @dathbe.
4747
- [calendar] Update defaultSymbol name and also the link to the icon search site (#3879)
4848
- [core] Update dependencies including electron to v38 as well as github actions (#3831, #3849, #3857, #3858, #3872, #3876, #3882, #3891)
4949
- [weather] Update feels_like temperature calculation formula (#3869)
50+
- [weather] Update null value handling for weather type (#3892)
5051

5152
### Fixed
5253

modules/default/weather/current.njk

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
{% endif %}
4444
</div>
4545
{% endif %}
46-
<div class="large">
46+
<div class="large type-temp">
4747
{% if config.showIndoorTemperature and indoor.temperature or config.showIndoorHumidity and indoor.humidity %}
4848
<span class="medium fas fa-home"></span>
4949
<span style="display: inline-block">
@@ -59,7 +59,9 @@
5959
{% endif %}
6060
</span>
6161
{% endif %}
62-
<span class="light wi weathericon wi-{{ current.weatherType }}"></span>
62+
{% if current.weatherType %}
63+
<span class="light wi weathericon wi-{{ current.weatherType }}"></span>
64+
{% endif %}
6365
<span class="light bright">{{ current.temperature | roundValue | unit("temperature") | decimalSymbol }}</span>
6466
{% if config.showHumidity === "temp" %}
6567
<span class="medium bright">{{ humidity() }}</span>

modules/default/weather/weather.css

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
.weather .weathericon,
22
.weather .fa-home {
33
font-size: 75%;
4-
line-height: 65px;
5-
display: inline-block;
6-
transform: translate(0, -3px);
74
}
85

96
.weather .humidity-icon {
@@ -37,14 +34,16 @@
3734
padding-right: 0;
3835
}
3936

40-
.weather tr .weathericon {
41-
line-height: 25px;
42-
}
43-
4437
.weather tr.colored .min-temp {
4538
color: #bcddff;
4639
}
4740

4841
.weather tr.colored .max-temp {
4942
color: #ff8e99;
5043
}
44+
45+
.weather .type-temp {
46+
display: flex;
47+
align-items: center;
48+
gap: 10px;
49+
}

modules/default/weather/weather.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ Module.register("weather", {
168168
this.scheduleUpdate();
169169

170170
if (this.weatherProvider.currentWeather()) {
171-
this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType.replace("-", "_") });
171+
this.sendNotification("CURRENTWEATHER_TYPE", { type: this.weatherProvider.currentWeather().weatherType?.replace("-", "_") });
172172
}
173173

174174
const notificationPayload = {

tests/e2e/modules/weather_current_spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ describe("Weather module", () => {
1818

1919
it("should render temperature with icon", async () => {
2020
await expect(weatherFunc.getText(".weather .large span.light.bright", "1.5°")).resolves.toBe(true);
21+
22+
const elem = await helpers.waitForElement(".weather .large span.weathericon");
23+
expect(elem).not.toBeNull();
2124
});
2225

2326
it("should render feels like temperature", async () => {
2427
// Template contains &nbsp; which renders as \xa0
2528
await expect(weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "93.7\xa0 Feels like -5.6°")).resolves.toBe(true);
2629
});
30+
2731
it("should render humidity next to feels-like", async () => {
2832
await expect(weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed .humidity", "93.7")).resolves.toBe(true);
2933
});

0 commit comments

Comments
 (0)