From 3405b2549bd73c08451867f1ededdb2e97a7df87 Mon Sep 17 00:00:00 2001 From: Michael <35783820+mib1185@users.noreply.github.com> Date: Fri, 25 Apr 2025 00:17:47 +0200 Subject: [PATCH] =?UTF-8?q?Add=20new=20units=20L/h=20,=20L/s=20and=20m?= =?UTF-8?q?=C2=B3/s=20to=20volume=20flow=20rate=20sensor=20device=20class?= =?UTF-8?q?=20(#143625)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit add new units L/h , L/s and m³/s --- homeassistant/const.py | 3 +++ homeassistant/util/unit_conversion.py | 6 ++++++ tests/util/test_unit_conversion.py | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/homeassistant/const.py b/homeassistant/const.py index a7ace52a0da..64faf019567 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -766,8 +766,11 @@ class UnitOfVolumeFlowRate(StrEnum): """Volume flow rate units.""" CUBIC_METERS_PER_HOUR = "m³/h" + CUBIC_METERS_PER_SECOND = "m³/s" CUBIC_FEET_PER_MINUTE = "ft³/min" + LITERS_PER_HOUR = "L/h" LITERS_PER_MINUTE = "L/min" + LITERS_PER_SECOND = "L/s" GALLONS_PER_MINUTE = "gal/min" MILLILITERS_PER_SECOND = "mL/s" diff --git a/homeassistant/util/unit_conversion.py b/homeassistant/util/unit_conversion.py index f2619c5dd61..f559512c1a7 100644 --- a/homeassistant/util/unit_conversion.py +++ b/homeassistant/util/unit_conversion.py @@ -705,10 +705,13 @@ class VolumeFlowRateConverter(BaseUnitConverter): # Units in terms of m³/h _UNIT_CONVERSION: dict[str | None, float] = { UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR: 1, + UnitOfVolumeFlowRate.CUBIC_METERS_PER_SECOND: 1 / _HRS_TO_SECS, UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE: 1 / (_HRS_TO_MINUTES * _CUBIC_FOOT_TO_CUBIC_METER), + UnitOfVolumeFlowRate.LITERS_PER_HOUR: 1 / _L_TO_CUBIC_METER, UnitOfVolumeFlowRate.LITERS_PER_MINUTE: 1 / (_HRS_TO_MINUTES * _L_TO_CUBIC_METER), + UnitOfVolumeFlowRate.LITERS_PER_SECOND: 1 / (_HRS_TO_SECS * _L_TO_CUBIC_METER), UnitOfVolumeFlowRate.GALLONS_PER_MINUTE: 1 / (_HRS_TO_MINUTES * _GALLON_TO_CUBIC_METER), UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND: 1 @@ -717,7 +720,10 @@ class VolumeFlowRateConverter(BaseUnitConverter): VALID_UNITS = { UnitOfVolumeFlowRate.CUBIC_FEET_PER_MINUTE, UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR, + UnitOfVolumeFlowRate.CUBIC_METERS_PER_SECOND, + UnitOfVolumeFlowRate.LITERS_PER_HOUR, UnitOfVolumeFlowRate.LITERS_PER_MINUTE, + UnitOfVolumeFlowRate.LITERS_PER_SECOND, UnitOfVolumeFlowRate.GALLONS_PER_MINUTE, UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND, } diff --git a/tests/util/test_unit_conversion.py b/tests/util/test_unit_conversion.py index 3f55ceef242..883b17c733c 100644 --- a/tests/util/test_unit_conversion.py +++ b/tests/util/test_unit_conversion.py @@ -806,12 +806,30 @@ _CONVERTED_VALUE: dict[ 2500, UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND, ), + ( + 1, + UnitOfVolumeFlowRate.CUBIC_METERS_PER_SECOND, + 3600, + UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR, + ), + ( + 1, + UnitOfVolumeFlowRate.CUBIC_METERS_PER_SECOND, + 3600000, + UnitOfVolumeFlowRate.LITERS_PER_HOUR, + ), ( 3, UnitOfVolumeFlowRate.LITERS_PER_MINUTE, 50, UnitOfVolumeFlowRate.MILLILITERS_PER_SECOND, ), + ( + 3.6, + UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR, + 1, + UnitOfVolumeFlowRate.LITERS_PER_SECOND, + ), ], }