Add specific sensor device_class, state_class and unit_of_measurement (#137038)

Support additional units in the coil unit descriptions: min, s, Pa, kPa, bar,
l/m, m³/h and %RH.

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
This commit is contained in:
mbraem 2025-03-16 21:06:49 +01:00 committed by GitHub
parent b0db7b432e
commit 5351fe3f9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -13,14 +13,17 @@ from homeassistant.components.sensor import (
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ( from homeassistant.const import (
PERCENTAGE,
EntityCategory, EntityCategory,
UnitOfElectricCurrent, UnitOfElectricCurrent,
UnitOfElectricPotential, UnitOfElectricPotential,
UnitOfEnergy, UnitOfEnergy,
UnitOfFrequency, UnitOfFrequency,
UnitOfPower, UnitOfPower,
UnitOfPressure,
UnitOfTemperature, UnitOfTemperature,
UnitOfTime, UnitOfTime,
UnitOfVolumeFlowRate,
) )
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
@ -114,6 +117,20 @@ UNIT_DESCRIPTIONS = {
state_class=SensorStateClass.TOTAL_INCREASING, state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfTime.HOURS, native_unit_of_measurement=UnitOfTime.HOURS,
), ),
"min": SensorEntityDescription(
key="min",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.DURATION,
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfTime.MINUTES,
),
"s": SensorEntityDescription(
key="s",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.DURATION,
state_class=SensorStateClass.TOTAL_INCREASING,
native_unit_of_measurement=UnitOfTime.SECONDS,
),
"Hz": SensorEntityDescription( "Hz": SensorEntityDescription(
key="Hz", key="Hz",
entity_category=EntityCategory.DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
@ -121,6 +138,48 @@ UNIT_DESCRIPTIONS = {
state_class=SensorStateClass.MEASUREMENT, state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfFrequency.HERTZ, native_unit_of_measurement=UnitOfFrequency.HERTZ,
), ),
"Pa": SensorEntityDescription(
key="Pa",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPressure.PA,
),
"kPa": SensorEntityDescription(
key="kPa",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPressure.KPA,
),
"bar": SensorEntityDescription(
key="bar",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.PRESSURE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfPressure.BAR,
),
"l/m": SensorEntityDescription(
key="l/m",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfVolumeFlowRate.LITERS_PER_MINUTE,
),
"m³/h": SensorEntityDescription(
key="m³/h",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.VOLUME_FLOW_RATE,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfVolumeFlowRate.CUBIC_METERS_PER_HOUR,
),
"%RH": SensorEntityDescription(
key="%RH",
entity_category=EntityCategory.DIAGNOSTIC,
device_class=SensorDeviceClass.HUMIDITY,
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=PERCENTAGE,
),
} }