mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 02:07:09 +00:00
Add missing device class to sensor.DEVICE_CLASS_UNITS (#101256)
This commit is contained in:
parent
41cb8526d1
commit
d0dc4d0963
@ -542,6 +542,7 @@ DEVICE_CLASS_UNITS: dict[SensorDeviceClass, set[type[StrEnum] | str | None]] = {
|
|||||||
},
|
},
|
||||||
SensorDeviceClass.VOLTAGE: set(UnitOfElectricPotential),
|
SensorDeviceClass.VOLTAGE: set(UnitOfElectricPotential),
|
||||||
SensorDeviceClass.VOLUME: set(UnitOfVolume),
|
SensorDeviceClass.VOLUME: set(UnitOfVolume),
|
||||||
|
SensorDeviceClass.VOLUME_STORAGE: set(UnitOfVolume),
|
||||||
SensorDeviceClass.WATER: {
|
SensorDeviceClass.WATER: {
|
||||||
UnitOfVolume.CENTUM_CUBIC_FEET,
|
UnitOfVolume.CENTUM_CUBIC_FEET,
|
||||||
UnitOfVolume.CUBIC_FEET,
|
UnitOfVolume.CUBIC_FEET,
|
||||||
|
@ -901,3 +901,13 @@ async def test_name(hass: HomeAssistant) -> None:
|
|||||||
"mode": NumberMode.AUTO,
|
"mode": NumberMode.AUTO,
|
||||||
"step": 1.0,
|
"step": 1.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_device_class_units(hass: HomeAssistant) -> None:
|
||||||
|
"""Test all numeric device classes have unit."""
|
||||||
|
# DEVICE_CLASS_UNITS should include all device classes except:
|
||||||
|
# - NumberDeviceClass.MONETARY
|
||||||
|
# - Device classes enumerated in NON_NUMERIC_DEVICE_CLASSES
|
||||||
|
assert set(NUMBER_DEVICE_CLASS_UNITS) == set(
|
||||||
|
NumberDeviceClass
|
||||||
|
) - NON_NUMERIC_DEVICE_CLASSES - {NumberDeviceClass.MONETARY}
|
||||||
|
@ -13,6 +13,7 @@ from homeassistant.components.sensor import (
|
|||||||
DEVICE_CLASS_STATE_CLASSES,
|
DEVICE_CLASS_STATE_CLASSES,
|
||||||
DEVICE_CLASS_UNITS,
|
DEVICE_CLASS_UNITS,
|
||||||
DOMAIN as SENSOR_DOMAIN,
|
DOMAIN as SENSOR_DOMAIN,
|
||||||
|
NON_NUMERIC_DEVICE_CLASSES,
|
||||||
SensorDeviceClass,
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
@ -2483,3 +2484,15 @@ def test_async_rounded_state_registered_entity_with_display_precision(
|
|||||||
hass.states.async_set(entity_id, "-0.0")
|
hass.states.async_set(entity_id, "-0.0")
|
||||||
state = hass.states.get(entity_id)
|
state = hass.states.get(entity_id)
|
||||||
assert async_rounded_state(hass, entity_id, state) == "0.0000"
|
assert async_rounded_state(hass, entity_id, state) == "0.0000"
|
||||||
|
|
||||||
|
|
||||||
|
def test_device_class_units_state_classes(hass: HomeAssistant) -> None:
|
||||||
|
"""Test all numeric device classes have unit and state class."""
|
||||||
|
# DEVICE_CLASS_UNITS should include all device classes except:
|
||||||
|
# - SensorDeviceClass.MONETARY
|
||||||
|
# - Device classes enumerated in NON_NUMERIC_DEVICE_CLASSES
|
||||||
|
assert set(DEVICE_CLASS_UNITS) == set(
|
||||||
|
SensorDeviceClass
|
||||||
|
) - NON_NUMERIC_DEVICE_CLASSES - {SensorDeviceClass.MONETARY}
|
||||||
|
# DEVICE_CLASS_STATE_CLASSES should include all device classes
|
||||||
|
assert set(DEVICE_CLASS_STATE_CLASSES) == set(SensorDeviceClass)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user