From d345faada8168a7cb1804b4184b4d118560564a8 Mon Sep 17 00:00:00 2001 From: Bjarne Riis Date: Sat, 23 Dec 2023 07:19:38 +0000 Subject: [PATCH] Added precipitation type sensor --- .../weatherflow_forecast/const.py | 7 +++++++ .../weatherflow_forecast/sensor.py | 20 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/custom_components/weatherflow_forecast/const.py b/custom_components/weatherflow_forecast/const.py index d549a86..737123c 100644 --- a/custom_components/weatherflow_forecast/const.py +++ b/custom_components/weatherflow_forecast/const.py @@ -30,6 +30,13 @@ MANUFACTURER = "WeatherFlow" MODEL = "Rest API" +PRECIPITATION_TYPE_DESCRIPTION = [ + "No Precipitation", + "Rain", + "Hail", + "Rain + Hail", +] + TIMESTAMP_SENSORS = [ "lightning_strike_last_epoch", "timestamp", diff --git a/custom_components/weatherflow_forecast/sensor.py b/custom_components/weatherflow_forecast/sensor.py index 33bb09a..a153971 100644 --- a/custom_components/weatherflow_forecast/sensor.py +++ b/custom_components/weatherflow_forecast/sensor.py @@ -57,6 +57,7 @@ DOMAIN, MANUFACTURER, MODEL, + PRECIPITATION_TYPE_DESCRIPTION, TIMESTAMP_SENSORS, ) @@ -207,7 +208,7 @@ class WeatherFlowSensorEntityDescription(SensorEntityDescription): ), WeatherFlowSensorEntityDescription( key="precip_rate", - name="Precipitation Rate", + name="Precipitation rate", native_unit_of_measurement=UnitOfVolumetricFlux.MILLIMETERS_PER_HOUR, device_class=SensorDeviceClass.PRECIPITATION_INTENSITY, state_class=SensorStateClass.MEASUREMENT, @@ -239,7 +240,7 @@ class WeatherFlowSensorEntityDescription(SensorEntityDescription): ), WeatherFlowSensorEntityDescription( key="precip_intensity", - name="Precipitation Intensity", + name="Precipitation intensity", icon="mdi:weather-rainy", translation_key="precip_intensity", ), @@ -288,6 +289,12 @@ class WeatherFlowSensorEntityDescription(SensorEntityDescription): device_class=SensorDeviceClass.DURATION, state_class=SensorStateClass.MEASUREMENT, ), + WeatherFlowSensorEntityDescription( + key="precip_type", + name="Precipitation type", + icon="mdi:format-list-bulleted-type", + state_class=SensorStateClass.MEASUREMENT, + ), WeatherFlowSensorEntityDescription( key="pressure_trend", name="Pressure Trend", @@ -508,6 +515,15 @@ def extra_state_attributes(self) -> None: return { ATTR_DESCRIPTION: BATTERY_MODE_DESCRIPTION[sensor_value], } + + if self.entity_description.key == "precip_type": + sensor_value = getattr(self.coordinator.data.sensor_data, + self.entity_description.key) if self.coordinator.data.sensor_data else None + if sensor_value is not None: + return { + ATTR_DESCRIPTION: PRECIPITATION_TYPE_DESCRIPTION[sensor_value], + } + if self.entity_description.key == "station_name": sensor_value = getattr(self.coordinator.data.sensor_data, self.entity_description.key) if self.coordinator.data.sensor_data else None