From e38fce98c4cfaf3eed0bb7fcadd9a55a49108b9e Mon Sep 17 00:00:00 2001 From: Phil Hollenback Date: Sun, 11 Apr 2021 02:13:07 -0700 Subject: [PATCH] Fix non-metric atmospheric pressure in Open Weather Map (#49030) The openweathermap component retrieves atmospheric pressure from the openweathermap api and passes it along without checking the units. The api returns pressure in metric (hPa). If you the use the weather forecast card on a non-metric home assistant install, you will then see the pressure reported as something like '1019 inHg', which is an incorrect combination of metric value and non-metric label. To fix this, check when retrieving the pressure if this is a metric system. If not, convert the value to non-metric inHg before sending it along. Weirdly, this isn't a problem for temperature, so I suspect temp is getting converted somewhere else. --- homeassistant/components/openweathermap/weather.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/openweathermap/weather.py b/homeassistant/components/openweathermap/weather.py index 7908beb61d6..63d63c30147 100644 --- a/homeassistant/components/openweathermap/weather.py +++ b/homeassistant/components/openweathermap/weather.py @@ -1,6 +1,7 @@ """Support for the OpenWeatherMap (OWM) service.""" from homeassistant.components.weather import WeatherEntity -from homeassistant.const import TEMP_CELSIUS +from homeassistant.const import PRESSURE_HPA, PRESSURE_INHG, TEMP_CELSIUS +from homeassistant.util.pressure import convert as pressure_convert from .const import ( ATTR_API_CONDITION, @@ -82,7 +83,12 @@ class OpenWeatherMapWeather(WeatherEntity): @property def pressure(self): """Return the pressure.""" - return self._weather_coordinator.data[ATTR_API_PRESSURE] + pressure = self._weather_coordinator.data[ATTR_API_PRESSURE] + # OpenWeatherMap returns pressure in hPA, so convert to + # inHg if we aren't using metric. + if not self.hass.config.units.is_metric and pressure: + return pressure_convert(pressure, PRESSURE_HPA, PRESSURE_INHG) + return pressure @property def humidity(self):