Skip to content

Commit

Permalink
Added precipitation type sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
briis committed Dec 23, 2023
1 parent 41f1ced commit d345faa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
7 changes: 7 additions & 0 deletions custom_components/weatherflow_forecast/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 18 additions & 2 deletions custom_components/weatherflow_forecast/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
DOMAIN,
MANUFACTURER,
MODEL,
PRECIPITATION_TYPE_DESCRIPTION,
TIMESTAMP_SENSORS,
)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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",
),
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d345faa

Please sign in to comment.