From 90438edc1744ebf15d4e78e345e3470a9e9730d5 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 8 Dec 2022 18:41:38 +0100 Subject: [PATCH] Introduce unit enums for irradiance (#83414) --- homeassistant/components/sensor/recorder.py | 9 +++++---- homeassistant/const.py | 19 +++++++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index af27f67456f..605030cdf35 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -26,8 +26,8 @@ from homeassistant.components.recorder.models import ( from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, REVOLUTIONS_PER_MINUTE, - VOLUME_CUBIC_FEET, - VOLUME_CUBIC_METERS, + UnitOfIrradiance, + UnitOfVolume, ) from homeassistant.core import HomeAssistant, State, callback, split_entity_id from homeassistant.exceptions import HomeAssistantError @@ -54,9 +54,10 @@ DEFAULT_STATISTICS = { } EQUIVALENT_UNITS = { + "BTU/(h×ft²)": UnitOfIrradiance.BTUS_PER_HOUR_SQUARE_FOOT, "RPM": REVOLUTIONS_PER_MINUTE, - "ft3": VOLUME_CUBIC_FEET, - "m3": VOLUME_CUBIC_METERS, + "ft3": UnitOfVolume.CUBIC_FEET, + "m3": UnitOfVolume.CUBIC_METERS, } # Keep track of entities for which a warning about decreasing value has been logged diff --git a/homeassistant/const.py b/homeassistant/const.py index eef142812ba..63f09186995 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -787,9 +787,20 @@ PERCENTAGE: Final = "%" # Rotational speed units REVOLUTIONS_PER_MINUTE: Final = "rpm" + +# Irradiance units +class UnitOfIrradiance(StrEnum): + """Irradiance units.""" + + WATTS_PER_SQUARE_METER = "W/m²" + BTUS_PER_HOUR_SQUARE_FOOT = "BTU/(h⋅ft²)" + + # Irradiation units IRRADIATION_WATTS_PER_SQUARE_METER: Final = "W/m²" +"""Deprecated: please use UnitOfIrradiance.WATTS_PER_SQUARE_METER""" IRRADIATION_BTUS_PER_HOUR_SQUARE_FOOT: Final = "BTU/(h×ft²)" +"""Deprecated: please use UnitOfIrradiance.BTUS_PER_HOUR_SQUARE_FOOT""" class UnitOfVolumetricFlux(StrEnum): @@ -800,16 +811,16 @@ class UnitOfVolumetricFlux(StrEnum): """ INCHES_PER_DAY = "in/d" - """Derived from in³/(in².d)""" + """Derived from in³/(in²⋅d)""" INCHES_PER_HOUR = "in/h" - """Derived from in³/(in².h)""" + """Derived from in³/(in²⋅h)""" MILLIMETERS_PER_DAY = "mm/d" - """Derived from mm³/(mm².d)""" + """Derived from mm³/(mm²⋅d)""" MILLIMETERS_PER_HOUR = "mm/h" - """Derived from mm³/(mm².h)""" + """Derived from mm³/(mm²⋅h)""" class UnitOfPrecipitationDepth(StrEnum):