Fix Met.no forecast precipitation (#44106)

This commit is contained in:
Brian Rogers 2020-12-11 10:53:21 -05:00 committed by GitHub
parent ce3f6c368a
commit e33405a8b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,8 +21,10 @@ from homeassistant.const import (
CONF_LATITUDE,
CONF_LONGITUDE,
CONF_NAME,
LENGTH_INCHES,
LENGTH_KILOMETERS,
LENGTH_MILES,
LENGTH_MILLIMETERS,
PRESSURE_HPA,
PRESSURE_INHG,
TEMP_CELSIUS,
@ -32,7 +34,14 @@ from homeassistant.helpers.update_coordinator import CoordinatorEntity
from homeassistant.util.distance import convert as convert_distance
from homeassistant.util.pressure import convert as convert_pressure
from .const import ATTR_MAP, CONDITIONS_MAP, CONF_TRACK_HOME, DOMAIN, FORECAST_MAP
from .const import (
ATTR_FORECAST_PRECIPITATION,
ATTR_MAP,
CONDITIONS_MAP,
CONF_TRACK_HOME,
DOMAIN,
FORECAST_MAP,
)
_LOGGER = logging.getLogger(__name__)
@ -221,6 +230,14 @@ class MetWeather(CoordinatorEntity, WeatherEntity):
for k, v in FORECAST_MAP.items()
if met_item.get(v) is not None
}
if not self._is_metric:
if ATTR_FORECAST_PRECIPITATION in ha_item:
precip_inches = convert_distance(
ha_item[ATTR_FORECAST_PRECIPITATION],
LENGTH_MILLIMETERS,
LENGTH_INCHES,
)
ha_item[ATTR_FORECAST_PRECIPITATION] = round(precip_inches, 2)
if ha_item.get(ATTR_FORECAST_CONDITION):
ha_item[ATTR_FORECAST_CONDITION] = format_condition(
ha_item[ATTR_FORECAST_CONDITION]