From 3c0a24db507f3025574e371956d418f8093790b9 Mon Sep 17 00:00:00 2001 From: Fabian Zimmermann Date: Mon, 28 Jun 2021 11:35:33 +0200 Subject: [PATCH] Convert openweathermap dewpoint from kelvin to celcius (#51893) Co-authored-by: Martin Hjelmare Co-authored-by: Franck Nijhof --- .../openweathermap/weather_update_coordinator.py | 7 ++++--- tests/components/openweathermap/test_config_flow.py | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/openweathermap/weather_update_coordinator.py b/homeassistant/components/openweathermap/weather_update_coordinator.py index 4518e3b6bda..98f39290d22 100644 --- a/homeassistant/components/openweathermap/weather_update_coordinator.py +++ b/homeassistant/components/openweathermap/weather_update_coordinator.py @@ -18,6 +18,7 @@ from homeassistant.components.weather import ( ATTR_FORECAST_WIND_BEARING, ATTR_FORECAST_WIND_SPEED, ) +from homeassistant.const import TEMP_CELSIUS from homeassistant.helpers import sun from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from homeassistant.util import dt @@ -179,10 +180,10 @@ class WeatherUpdateCoordinator(DataUpdateCoordinator): return forecast - @staticmethod - def _fmt_dewpoint(dewpoint): + def _fmt_dewpoint(self, dewpoint): if dewpoint is not None: - return round(dewpoint / 100, 1) + dewpoint = dewpoint - 273.15 + return round(self.hass.config.units.temperature(dewpoint, TEMP_CELSIUS), 1) return None @staticmethod diff --git a/tests/components/openweathermap/test_config_flow.py b/tests/components/openweathermap/test_config_flow.py index ba1be4afb4c..5225aad83cd 100644 --- a/tests/components/openweathermap/test_config_flow.py +++ b/tests/components/openweathermap/test_config_flow.py @@ -187,6 +187,7 @@ def _create_mocked_owm(is_api_online: bool): weather.snow.return_value = [] weather.detailed_status.return_value = "status" weather.weather_code = 803 + weather.dewpoint = 10 mocked_owm.weather_at_coords.return_value.weather = weather