Meteo france "next_rain" attributes rework (#39092)

* Improve next_rain sensor attributes

* Add log message to identify missing condition

* Add a condtion

* Set the coordinator for 1 hour rain forecast in English

* Attribut dict keys shorten

* reverse transalate the API results for next rain

* Use f string for the keys in the dict

* Remove Logging from state property

* Remove other logging from state property
This commit is contained in:
Oncleben31 2020-08-27 21:08:39 +02:00 committed by GitHub
parent 4e39a00b3d
commit 90ac426a54
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View file

@ -24,6 +24,7 @@ FORECAST_MODE_DAILY = "daily"
FORECAST_MODE = [FORECAST_MODE_HOURLY, FORECAST_MODE_DAILY]
ATTR_NEXT_RAIN_1_HOUR_FORECAST = "1_hour_forecast"
ATTR_NEXT_RAIN_DT_REF = "forecast_time_ref"
ENTITY_NAME = "name"
ENTITY_UNIT = "unit"
@ -150,6 +151,7 @@ CONDITION_CLASSES = {
"Pluies éparses / Rares averses",
"Pluies éparses",
"Rares averses",
"Pluie modérée",
"Pluie / Averses",
"Averses",
"Pluie",

View file

@ -15,6 +15,7 @@ from homeassistant.util import dt as dt_util
from .const import (
ATTR_NEXT_RAIN_1_HOUR_FORECAST,
ATTR_NEXT_RAIN_DT_REF,
ATTRIBUTION,
COORDINATOR_ALERT,
COORDINATOR_FORECAST,
@ -185,11 +186,13 @@ class MeteoFranceRainSensor(MeteoFranceSensor):
@property
def device_state_attributes(self):
"""Return the state attributes."""
reference_dt = self.coordinator.data.forecast[0]["dt"]
return {
ATTR_NEXT_RAIN_1_HOUR_FORECAST: [
{dt_util.utc_from_timestamp(item["dt"]).isoformat(): item["desc"]}
ATTR_NEXT_RAIN_DT_REF: dt_util.utc_from_timestamp(reference_dt).isoformat(),
ATTR_NEXT_RAIN_1_HOUR_FORECAST: {
f"{int((item['dt'] - reference_dt) / 60)} min": item["desc"]
for item in self.coordinator.data.forecast
],
},
ATTR_ATTRIBUTION: ATTRIBUTION,
}

View file

@ -130,9 +130,6 @@ class MeteoFranceWeather(WeatherEntity):
for forecast in self.coordinator.data.forecast:
# Can have data in the past
if forecast["dt"] < today:
_LOGGER.debug(
"remove forecast in the past: %s %s", self._mode, forecast
)
continue
forecast_data.append(
{