Skip to content

Commit f1ee0e4

Browse files
Add support for gallons per day as a unit of volume flow rate (home-assistant#157394)
1 parent 5f522e5 commit f1ee0e4

File tree

5 files changed

+13
-3
lines changed

5 files changed

+13
-3
lines changed

homeassistant/components/number/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ class NumberDeviceClass(StrEnum):
432432
433433
Unit of measurement: UnitOfVolumeFlowRate
434434
- SI / metric: `m³/h`, `m³/min`, `m³/s`, `L/h`, `L/min`, `L/s`, `mL/s`
435-
- USCS / imperial: `ft³/min`, `gal/min`
435+
- USCS / imperial: `ft³/min`, `gal/min`, `gal/d`
436436
"""
437437

438438
WATER = "water"

homeassistant/components/sensor/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class SensorDeviceClass(StrEnum):
468468
469469
Unit of measurement: UnitOfVolumeFlowRate
470470
- SI / metric: `m³/h`, `m³/min`, `m³/s`, `L/h`, `L/min`, `L/s`, `mL/s`
471-
- USCS / imperial: `ft³/min`, `gal/min`
471+
- USCS / imperial: `ft³/min`, `gal/min`, `gal/d`
472472
"""
473473

474474
WATER = "water"

homeassistant/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ class UnitOfVolumeFlowRate(StrEnum):
653653
LITERS_PER_SECOND = "L/s"
654654
GALLONS_PER_HOUR = "gal/h"
655655
GALLONS_PER_MINUTE = "gal/min"
656+
GALLONS_PER_DAY = "gal/d"
656657
MILLILITERS_PER_SECOND = "mL/s"
657658

658659

homeassistant/util/unit_conversion.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
_MIN_TO_SEC = 60 # 1 min = 60 seconds
7070
_HRS_TO_MINUTES = 60 # 1 hr = 60 minutes
7171
_HRS_TO_SECS = _HRS_TO_MINUTES * _MIN_TO_SEC # 1 hr = 60 minutes = 3600 seconds
72-
_DAYS_TO_SECS = 24 * _HRS_TO_SECS # 1 day = 24 hours = 86400 seconds
72+
_DAYS_TO_HRS = 24 # 1 day = 24 hours
73+
_DAYS_TO_SECS = _DAYS_TO_HRS * _HRS_TO_SECS # 1 day = 24 hours = 86400 seconds
7374

7475
# Energy conversion constants
7576
_WH_TO_J = 3600 # 1 Wh = 3600 J
@@ -852,6 +853,7 @@ class VolumeFlowRateConverter(BaseUnitConverter):
852853
UnitOfVolumeFlowRate.GALLONS_PER_HOUR: 1 / _GALLON_TO_CUBIC_METER,
853854
UnitOfVolumeFlowRate.GALLONS_PER_MINUTE: 1
854855
/ (_HRS_TO_MINUTES * _GALLON_TO_CUBIC_METER),
856+
UnitOfVolumeFlowRate.GALLONS_PER_DAY: _DAYS_TO_HRS / _GALLON_TO_CUBIC_METER,
855857
UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND: 1
856858
/ (_HRS_TO_SECS * _ML_TO_CUBIC_METER),
857859
}
@@ -865,6 +867,7 @@ class VolumeFlowRateConverter(BaseUnitConverter):
865867
UnitOfVolumeFlowRate.LITERS_PER_SECOND,
866868
UnitOfVolumeFlowRate.GALLONS_PER_HOUR,
867869
UnitOfVolumeFlowRate.GALLONS_PER_MINUTE,
870+
UnitOfVolumeFlowRate.GALLONS_PER_DAY,
868871
UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND,
869872
}
870873

tests/util/test_unit_conversion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,12 @@
10541054
10,
10551055
UnitOfVolumeFlowRate.LITERS_PER_SECOND,
10561056
),
1057+
(
1058+
24,
1059+
UnitOfVolumeFlowRate.GALLONS_PER_DAY,
1060+
1,
1061+
UnitOfVolumeFlowRate.GALLONS_PER_HOUR,
1062+
),
10571063
],
10581064
}
10591065

0 commit comments

Comments
 (0)