SMHI component: Bugfix - calc precipitation (#20745)
* Bugfix - calc precipitation * Feedback: better way to skip first forecast * Even less messy way * lint error
This commit is contained in:
1 parent
e581d41ded
commit
208ea6eae4
5 files changed
+26
-25
No files matched your search
@@ -11,7 +11,7 @@ from homeassistant.core import Config, HomeAssistant
|
||||
from .config_flow import smhi_locations # noqa: F401
|
||||
from .const import DOMAIN # noqa: F401
|
||||
|
||||
REQUIREMENTS = ['smhi-pkg==1.0.5']
|
||||
REQUIREMENTS = ['smhi-pkg==1.0.8']
|
||||
|
||||
DEFAULT_NAME = 'smhi'
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ from homeassistant.const import (
|
||||
CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import aiohttp_client
|
||||
from homeassistant.util import Throttle, dt, slugify
|
||||
from homeassistant.util import Throttle, slugify
|
||||
|
||||
DEPENDENCIES = ['smhi']
|
||||
|
||||
@@ -208,25 +208,24 @@ class SmhiWeather(WeatherEntity):
|
||||
@property
|
||||
def forecast(self) -> List:
|
||||
"""Return the forecast."""
|
||||
if self._forecasts is None:
|
||||
if self._forecasts is None or len(self._forecasts) < 2:
|
||||
return None
|
||||
|
||||
data = []
|
||||
for forecast in self._forecasts:
|
||||
|
||||
for forecast in self._forecasts[1:]:
|
||||
condition = next((
|
||||
k for k, v in CONDITION_CLASSES.items()
|
||||
if forecast.symbol in v), None)
|
||||
|
||||
# Only get mid day forecasts
|
||||
if forecast.valid_time.hour == 12:
|
||||
data.append({
|
||||
ATTR_FORECAST_TIME: dt.as_local(forecast.valid_time),
|
||||
ATTR_FORECAST_TEMP: forecast.temperature_max,
|
||||
ATTR_FORECAST_TEMP_LOW: forecast.temperature_min,
|
||||
ATTR_FORECAST_PRECIPITATION:
|
||||
round(forecast.mean_precipitation*24),
|
||||
ATTR_FORECAST_CONDITION: condition,
|
||||
})
|
||||
data.append({
|
||||
ATTR_FORECAST_TIME: forecast.valid_time.isoformat(),
|
||||
ATTR_FORECAST_TEMP: forecast.temperature_max,
|
||||
ATTR_FORECAST_TEMP_LOW: forecast.temperature_min,
|
||||
ATTR_FORECAST_PRECIPITATION:
|
||||
round(forecast.total_precipitation),
|
||||
ATTR_FORECAST_CONDITION: condition,
|
||||
})
|
||||
|
||||
return data
|
||||
|
||||
|
||||
Reference in new issue
Block a user