Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/sensor_state_data/sensor/device_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"

Expand Down Expand Up @@ -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"
24 changes: 24 additions & 0 deletions tests/test_sensor_device_class_weather.py
Original file line number Diff line number Diff line change
@@ -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
Loading