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.pull/49044/head
parent
71a410c742
commit
e38fce98c4
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue