1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Add support for gallons per day as a unit of volume flow rate (#157394)

This commit is contained in:
StaleLoafOfBread
2025-11-27 14:42:16 -05:00
committed by GitHub
parent 5f522e5afa
commit f1ee0e4ac9
5 changed files with 13 additions and 3 deletions

View File

@@ -432,7 +432,7 @@ class NumberDeviceClass(StrEnum):
Unit of measurement: UnitOfVolumeFlowRate
- SI / metric: `m³/h`, `m³/min`, `m³/s`, `L/h`, `L/min`, `L/s`, `mL/s`
- USCS / imperial: `ft³/min`, `gal/min`
- USCS / imperial: `ft³/min`, `gal/min`, `gal/d`
"""
WATER = "water"

View File

@@ -468,7 +468,7 @@ class SensorDeviceClass(StrEnum):
Unit of measurement: UnitOfVolumeFlowRate
- SI / metric: `m³/h`, `m³/min`, `m³/s`, `L/h`, `L/min`, `L/s`, `mL/s`
- USCS / imperial: `ft³/min`, `gal/min`
- USCS / imperial: `ft³/min`, `gal/min`, `gal/d`
"""
WATER = "water"

View File

@@ -653,6 +653,7 @@ class UnitOfVolumeFlowRate(StrEnum):
LITERS_PER_SECOND = "L/s"
GALLONS_PER_HOUR = "gal/h"
GALLONS_PER_MINUTE = "gal/min"
GALLONS_PER_DAY = "gal/d"
MILLILITERS_PER_SECOND = "mL/s"

View File

@@ -69,7 +69,8 @@ _HECTARE_TO_M2 = 100 * 100 # 1 hectare = 10,000 m²
_MIN_TO_SEC = 60 # 1 min = 60 seconds
_HRS_TO_MINUTES = 60 # 1 hr = 60 minutes
_HRS_TO_SECS = _HRS_TO_MINUTES * _MIN_TO_SEC # 1 hr = 60 minutes = 3600 seconds
_DAYS_TO_SECS = 24 * _HRS_TO_SECS # 1 day = 24 hours = 86400 seconds
_DAYS_TO_HRS = 24 # 1 day = 24 hours
_DAYS_TO_SECS = _DAYS_TO_HRS * _HRS_TO_SECS # 1 day = 24 hours = 86400 seconds
# Energy conversion constants
_WH_TO_J = 3600 # 1 Wh = 3600 J
@@ -852,6 +853,7 @@ class VolumeFlowRateConverter(BaseUnitConverter):
UnitOfVolumeFlowRate.GALLONS_PER_HOUR: 1 / _GALLON_TO_CUBIC_METER,
UnitOfVolumeFlowRate.GALLONS_PER_MINUTE: 1
/ (_HRS_TO_MINUTES * _GALLON_TO_CUBIC_METER),
UnitOfVolumeFlowRate.GALLONS_PER_DAY: _DAYS_TO_HRS / _GALLON_TO_CUBIC_METER,
UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND: 1
/ (_HRS_TO_SECS * _ML_TO_CUBIC_METER),
}
@@ -865,6 +867,7 @@ class VolumeFlowRateConverter(BaseUnitConverter):
UnitOfVolumeFlowRate.LITERS_PER_SECOND,
UnitOfVolumeFlowRate.GALLONS_PER_HOUR,
UnitOfVolumeFlowRate.GALLONS_PER_MINUTE,
UnitOfVolumeFlowRate.GALLONS_PER_DAY,
UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND,
}

View File

@@ -1054,6 +1054,12 @@ _CONVERTED_VALUE: dict[
10,
UnitOfVolumeFlowRate.LITERS_PER_SECOND,
),
(
24,
UnitOfVolumeFlowRate.GALLONS_PER_DAY,
1,
UnitOfVolumeFlowRate.GALLONS_PER_HOUR,
),
],
}