From 90ac426a54d2f617aeccdc261bbe6a878c88865c Mon Sep 17 00:00:00 2001 From: Oncleben31 Date: Thu, 27 Aug 2020 21:08:39 +0200 Subject: [PATCH] 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 --- homeassistant/components/meteo_france/const.py | 2 ++ homeassistant/components/meteo_france/sensor.py | 9 ++++++--- homeassistant/components/meteo_france/weather.py | 3 --- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/meteo_france/const.py b/homeassistant/components/meteo_france/const.py index 8e6c625e331..fb960b3b26a 100644 --- a/homeassistant/components/meteo_france/const.py +++ b/homeassistant/components/meteo_france/const.py @@ -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", diff --git a/homeassistant/components/meteo_france/sensor.py b/homeassistant/components/meteo_france/sensor.py index 178df5c992f..de767217cbf 100644 --- a/homeassistant/components/meteo_france/sensor.py +++ b/homeassistant/components/meteo_france/sensor.py @@ -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, } diff --git a/homeassistant/components/meteo_france/weather.py b/homeassistant/components/meteo_france/weather.py index 6f110dbcdeb..30f3a350299 100644 --- a/homeassistant/components/meteo_france/weather.py +++ b/homeassistant/components/meteo_france/weather.py @@ -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( {