From 96c442349f10e7d9b4823d684c127a3ef5a41d0e Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 8 Dec 2022 20:06:02 +0100 Subject: [PATCH] Introduce unit enums for sound pressure (#83450) * Introduce unit enums for sound pressure * Adjust based on architecture comment * Adjust --- homeassistant/components/sensor/recorder.py | 2 ++ homeassistant/const.py | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index 605030cdf35..e35a7254d5a 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -27,6 +27,7 @@ from homeassistant.const import ( ATTR_UNIT_OF_MEASUREMENT, REVOLUTIONS_PER_MINUTE, UnitOfIrradiance, + UnitOfSoundPressure, UnitOfVolume, ) from homeassistant.core import HomeAssistant, State, callback, split_entity_id @@ -55,6 +56,7 @@ DEFAULT_STATISTICS = { EQUIVALENT_UNITS = { "BTU/(h×ft²)": UnitOfIrradiance.BTUS_PER_HOUR_SQUARE_FOOT, + "dBa": UnitOfSoundPressure.WEIGHTED_DECIBEL_A, "RPM": REVOLUTIONS_PER_MINUTE, "ft3": UnitOfVolume.CUBIC_FEET, "m3": UnitOfVolume.CUBIC_METERS, diff --git a/homeassistant/const.py b/homeassistant/const.py index 63f09186995..02b4681f3d8 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -702,9 +702,19 @@ PRESSURE_INHG: Final = "inHg" PRESSURE_PSI: Final = "psi" """Deprecated: please use UnitOfPressure.PSI""" + # Sound pressure units +class UnitOfSoundPressure(StrEnum): + """Sound pressure units.""" + + DECIBEL = "dB" + WEIGHTED_DECIBEL_A = "dBA" + + SOUND_PRESSURE_DB: Final = "dB" +"""Deprecated: please use UnitOfSoundPressure.DECIBEL""" SOUND_PRESSURE_WEIGHTED_DBA: Final = "dBa" +"""Deprecated: please use UnitOfSoundPressure.WEIGHTED_DECIBEL_A""" # Volume units