From e9f76dd016259d42add9bb88140d1d46e92acefd Mon Sep 17 00:00:00 2001 From: Bluetooth Devices Bot Date: Mon, 22 Jun 2026 23:11:40 +0000 Subject: [PATCH] feat: add weather/environmental sensor device classes Add five Home Assistant SensorDeviceClass members that are missing from this mirror: ATMOSPHERIC_PRESSURE, IRRADIANCE, PRECIPITATION, PRECIPITATION_INTENSITY, and WIND_SPEED. These map to common BLE weather-station readings and were absent here while present upstream. Additive only; string values pinned with tests as the HA interop contract. --- src/sensor_state_data/sensor/device_class.py | 15 ++++++++++++ tests/test_sensor_device_class_weather.py | 24 ++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/test_sensor_device_class_weather.py diff --git a/src/sensor_state_data/sensor/device_class.py b/src/sensor_state_data/sensor/device_class.py index f7cb870..7e97e6c 100644 --- a/src/sensor_state_data/sensor/device_class.py +++ b/src/sensor_state_data/sensor/device_class.py @@ -15,6 +15,9 @@ class SensorDeviceClass(BaseDeviceClass): # Air Quality Index AQI = "aqi" + # atmospheric pressure (hPa, mbar); weather-station station pressure + ATMOSPHERIC_PRESSURE = "atmospheric_pressure" + # % of battery that is left BATTERY = "battery" @@ -72,6 +75,9 @@ class SensorDeviceClass(BaseDeviceClass): # impedance (Ohm) IMPEDANCE = "impedance" + # irradiance (W/m², BTU/(h·ft²)) + IRRADIANCE = "irradiance" + # keg size (L) KEG_SIZE = "keg_size" @@ -132,6 +138,12 @@ class SensorDeviceClass(BaseDeviceClass): # power (W/kW) POWER = "power" + # accumulated precipitation (mm, in) + PRECIPITATION = "precipitation" + + # precipitation intensity (mm/d, mm/h, in/d, in/h) + PRECIPITATION_INTENSITY = "precipitation_intensity" + # pressure (hPa/mbar) PRESSURE = "pressure" @@ -182,3 +194,6 @@ class SensorDeviceClass(BaseDeviceClass): # Water (L) WATER = "water" + + # wind speed (m/s, km/h, mph, ft/s, kn) + WIND_SPEED = "wind_speed" diff --git a/tests/test_sensor_device_class_weather.py b/tests/test_sensor_device_class_weather.py new file mode 100644 index 0000000..dec3448 --- /dev/null +++ b/tests/test_sensor_device_class_weather.py @@ -0,0 +1,24 @@ +"""Pin the string values of the weather/environmental sensor device classes. + +These strings are the Home Assistant interop contract — changing them silently +breaks consumers that compare device classes by value, so they are pinned here. +""" + +from sensor_state_data import SensorDeviceClass + + +def test_weather_device_class_values(): + assert SensorDeviceClass.ATMOSPHERIC_PRESSURE == "atmospheric_pressure" + assert SensorDeviceClass.IRRADIANCE == "irradiance" + assert SensorDeviceClass.PRECIPITATION == "precipitation" + assert SensorDeviceClass.PRECIPITATION_INTENSITY == "precipitation_intensity" + assert SensorDeviceClass.WIND_SPEED == "wind_speed" + + +def test_weather_device_class_str(): + # StrEnum: str() returns the value, not "SensorDeviceClass.WIND_SPEED" + assert str(SensorDeviceClass.WIND_SPEED) == "wind_speed" # type: ignore[unreachable] + + +def test_atmospheric_pressure_distinct_from_pressure(): + assert SensorDeviceClass.ATMOSPHERIC_PRESSURE != SensorDeviceClass.PRESSURE