1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-27 14:31:13 +00:00

Add volume to SensorDeviceClass (#77960)

* Add volume to SensorDeviceClass

* Adjust recorder

* Adjust tests

* Adjust sensor UNIT_CONVERTERS

* Adjust recorder

* Update strings.json
This commit is contained in:
epenet
2022-09-27 18:37:52 +01:00
committed by GitHub
parent d8a15f3dda
commit 12e4d18038
10 changed files with 113 additions and 23 deletions

View File

@@ -23,6 +23,10 @@ from homeassistant.const import (
STATE_UNKNOWN,
TEMP_CELSIUS,
TEMP_FAHRENHEIT,
VOLUME_CUBIC_FEET,
VOLUME_CUBIC_METERS,
VOLUME_FLUID_OUNCE,
VOLUME_LITERS,
)
from homeassistant.core import State
from homeassistant.helpers import entity_registry as er
@@ -549,6 +553,31 @@ async def test_custom_unit(
100,
SensorDeviceClass.SPEED,
),
# Volume
(
VOLUME_CUBIC_METERS,
VOLUME_CUBIC_FEET,
VOLUME_CUBIC_FEET,
100,
3531,
SensorDeviceClass.VOLUME,
),
(
VOLUME_FLUID_OUNCE,
VOLUME_LITERS,
VOLUME_LITERS,
78,
2.3,
SensorDeviceClass.VOLUME,
),
(
VOLUME_CUBIC_METERS,
"peer_distance",
VOLUME_CUBIC_METERS,
100,
100,
SensorDeviceClass.VOLUME,
),
],
)
async def test_custom_unit_change(

View File

@@ -98,6 +98,8 @@ def set_time_zone():
("speed", "mph", "mph", "m/s", "speed", 13.050847, -10, 30),
("temperature", "°C", "°C", "°C", "temperature", 13.050847, -10, 30),
("temperature", "°F", "°F", "°C", "temperature", 13.050847, -10, 30),
("volume", "", "", "", "volume", 13.050847, -10, 30),
("volume", "ft³", "ft³", "", "volume", 13.050847, -10, 30),
],
)
def test_compile_hourly_statistics(
@@ -359,18 +361,22 @@ def test_compile_hourly_statistics_unsupported(hass_recorder, caplog, attributes
(IMPERIAL_SYSTEM, "distance", "mi", "mi", "m", "distance", 1),
(IMPERIAL_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1),
(IMPERIAL_SYSTEM, "energy", "Wh", "Wh", "kWh", "energy", 1),
(IMPERIAL_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1),
(IMPERIAL_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1),
(IMPERIAL_SYSTEM, "gas", "", "", "", "volume", 1),
(IMPERIAL_SYSTEM, "gas", "ft³", "ft³", "", "volume", 1),
(IMPERIAL_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1),
(IMPERIAL_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1),
(IMPERIAL_SYSTEM, "volume", "", "", "", "volume", 1),
(IMPERIAL_SYSTEM, "volume", "ft³", "ft³", "", "volume", 1),
(METRIC_SYSTEM, "distance", "m", "m", "m", "distance", 1),
(METRIC_SYSTEM, "distance", "mi", "mi", "m", "distance", 1),
(METRIC_SYSTEM, "energy", "kWh", "kWh", "kWh", "energy", 1),
(METRIC_SYSTEM, "energy", "Wh", "Wh", "kWh", "energy", 1),
(METRIC_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1),
(METRIC_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1),
(METRIC_SYSTEM, "gas", "", "", "", "volume", 1),
(METRIC_SYSTEM, "gas", "ft³", "ft³", "", "volume", 1),
(METRIC_SYSTEM, "monetary", "EUR", "EUR", "EUR", None, 1),
(METRIC_SYSTEM, "monetary", "SEK", "SEK", "SEK", None, 1),
(METRIC_SYSTEM, "volume", "", "", "", "volume", 1),
(METRIC_SYSTEM, "volume", "ft³", "ft³", "", "volume", 1),
],
)
async def test_compile_hourly_sum_statistics_amount(
@@ -1569,6 +1575,8 @@ def test_compile_hourly_energy_statistics_multiple(hass_recorder, caplog):
("speed", "mph", 30),
("temperature", "°C", 30),
("temperature", "°F", 30),
("volume", "", 30),
("volume", "ft³", 30),
],
)
def test_compile_hourly_statistics_unchanged(
@@ -1660,6 +1668,8 @@ def test_compile_hourly_statistics_partially_unavailable(hass_recorder, caplog):
("speed", "mph", 30),
("temperature", "°C", 30),
("temperature", "°F", 30),
("volume", "", 30),
("volume", "ft³", 30),
],
)
def test_compile_hourly_statistics_unavailable(
@@ -1751,6 +1761,10 @@ def test_compile_hourly_statistics_fails(hass_recorder, caplog):
("measurement", "speed", "mph", "mph", "m/s", "speed", "mean"),
("measurement", "temperature", "°C", "°C", "°C", "temperature", "mean"),
("measurement", "temperature", "°F", "°F", "°C", "temperature", "mean"),
("measurement", "volume", "", "", "", "volume", "mean"),
("measurement", "volume", "ft³", "ft³", "", "volume", "mean"),
("total", "volume", "", "", "", "volume", "sum"),
("total", "volume", "ft³", "ft³", "", "volume", "sum"),
],
)
def test_list_statistic_ids(