Skip to content

Commit

Permalink
Allow rounding two decimal places for Flume usage sensors (#95219)
Browse files Browse the repository at this point in the history
  • Loading branch information
danlindow committed Jun 26, 2023
1 parent a31e899 commit 45ff9d8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions homeassistant/components/flume/sensor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Sensor for displaying the number of result from Flume."""
from numbers import Number

from pyflume import FlumeData

Expand Down Expand Up @@ -35,44 +34,51 @@
SensorEntityDescription(
key="current_interval",
name="Current",
suggested_display_precision=2,
native_unit_of_measurement=f"{UnitOfVolume.GALLONS}/m",
),
SensorEntityDescription(
key="month_to_date",
name="Current Month",
suggested_display_precision=2,
native_unit_of_measurement=UnitOfVolume.GALLONS,
device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="week_to_date",
name="Current Week",
suggested_display_precision=2,
native_unit_of_measurement=UnitOfVolume.GALLONS,
device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="today",
name="Current Day",
suggested_display_precision=2,
native_unit_of_measurement=UnitOfVolume.GALLONS,
device_class=SensorDeviceClass.WATER,
state_class=SensorStateClass.TOTAL_INCREASING,
),
SensorEntityDescription(
key="last_60_min",
name="60 Minutes",
suggested_display_precision=2,
native_unit_of_measurement=f"{UnitOfVolume.GALLONS}/h",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="last_24_hrs",
name="24 Hours",
suggested_display_precision=2,
native_unit_of_measurement=f"{UnitOfVolume.GALLONS}/d",
state_class=SensorStateClass.MEASUREMENT,
),
SensorEntityDescription(
key="last_30_days",
name="30 Days",
suggested_display_precision=2,
native_unit_of_measurement=f"{UnitOfVolume.GALLONS}/mo",
state_class=SensorStateClass.MEASUREMENT,
),
Expand Down Expand Up @@ -139,8 +145,4 @@ def native_value(self):
if sensor_key not in self.coordinator.flume_device.values:
return None

return _format_state_value(self.coordinator.flume_device.values[sensor_key])


def _format_state_value(value):
return round(value, 1) if isinstance(value, Number) else None
return self.coordinator.flume_device.values[sensor_key]

0 comments on commit 45ff9d8

Please sign in to comment.