diff --git a/homeassistant/const.py b/homeassistant/const.py index 02b4681f3d8..dfdab178d76 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -767,6 +767,7 @@ class UnitOfMass(StrEnum): MICROGRAMS = "µg" OUNCES = "oz" POUNDS = "lb" + STONES = "st" MASS_GRAMS: Final = "g" diff --git a/homeassistant/util/unit_conversion.py b/homeassistant/util/unit_conversion.py index 70d2474fd95..a1c41172ed9 100644 --- a/homeassistant/util/unit_conversion.py +++ b/homeassistant/util/unit_conversion.py @@ -33,7 +33,8 @@ _DAYS_TO_SECS = 24 * _HRS_TO_SECS # 1 day = 24 hours = 86400 seconds # Mass conversion constants _POUND_TO_G = 453.59237 -_OUNCE_TO_G = _POUND_TO_G / 16 +_OUNCE_TO_G = _POUND_TO_G / 16 # 16 ounces to a pound +_STONE_TO_G = _POUND_TO_G * 14 # 14 pounds to a stone # Pressure conversion constants _STANDARD_GRAVITY = 9.80665 @@ -143,6 +144,7 @@ class MassConverter(BaseUnitConverter): UnitOfMass.KILOGRAMS: 1 / 1000, UnitOfMass.OUNCES: 1 / _OUNCE_TO_G, UnitOfMass.POUNDS: 1 / _POUND_TO_G, + UnitOfMass.STONES: 1 / _STONE_TO_G, } VALID_UNITS = { UnitOfMass.GRAMS, @@ -151,6 +153,7 @@ class MassConverter(BaseUnitConverter): UnitOfMass.MICROGRAMS, UnitOfMass.OUNCES, UnitOfMass.POUNDS, + UnitOfMass.STONES, } diff --git a/tests/util/test_unit_conversion.py b/tests/util/test_unit_conversion.py index b2b99d6f8c0..fdd187905d3 100644 --- a/tests/util/test_unit_conversion.py +++ b/tests/util/test_unit_conversion.py @@ -345,6 +345,11 @@ def test_energy_convert( (16, UnitOfMass.OUNCES, 453592.37, UnitOfMass.MILLIGRAMS), (16, UnitOfMass.OUNCES, 453592370, UnitOfMass.MICROGRAMS), (16, UnitOfMass.OUNCES, 1, UnitOfMass.POUNDS), + (1, UnitOfMass.STONES, pytest.approx(6.350293), UnitOfMass.KILOGRAMS), + (1, UnitOfMass.STONES, pytest.approx(6350.293), UnitOfMass.GRAMS), + (1, UnitOfMass.STONES, pytest.approx(6350293), UnitOfMass.MILLIGRAMS), + (1, UnitOfMass.STONES, pytest.approx(14), UnitOfMass.POUNDS), + (1, UnitOfMass.STONES, pytest.approx(224), UnitOfMass.OUNCES), ], ) def test_mass_convert(