From 5dfffb0818ea2842ba606921cf47ae745a1a7420 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Mon, 5 Feb 2024 18:01:06 +0100 Subject: [PATCH] Allow weight to be used as total_increasing state_class for sensors (#108505) * Allow weight to be used as total_increasing state_class for sensors * Add SensorStateClass.TOTAL --- homeassistant/components/sensor/const.py | 6 +++++- tests/components/sensor/test_recorder.py | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/sensor/const.py b/homeassistant/components/sensor/const.py index aad882821d6..3dc8f878791 100644 --- a/homeassistant/components/sensor/const.py +++ b/homeassistant/components/sensor/const.py @@ -640,7 +640,11 @@ DEVICE_CLASS_STATE_CLASSES: dict[SensorDeviceClass, set[SensorStateClass]] = { SensorStateClass.TOTAL, SensorStateClass.TOTAL_INCREASING, }, - SensorDeviceClass.WEIGHT: {SensorStateClass.MEASUREMENT}, + SensorDeviceClass.WEIGHT: { + SensorStateClass.MEASUREMENT, + SensorStateClass.TOTAL, + SensorStateClass.TOTAL_INCREASING, + }, SensorDeviceClass.WIND_SPEED: {SensorStateClass.MEASUREMENT}, } diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py index 2dcc873ca8b..b4b535473c1 100644 --- a/tests/components/sensor/test_recorder.py +++ b/tests/components/sensor/test_recorder.py @@ -988,6 +988,7 @@ async def test_compile_hourly_sum_statistics_amount( ("monetary", "SEK", "SEK", "SEK", None, 1), ("gas", "m³", "m³", "m³", "volume", 1), ("gas", "ft³", "ft³", "ft³", "volume", 1), + ("weight", "kg", "kg", "kg", "mass", 1), ], ) def test_compile_hourly_sum_statistics_amount_reset_every_state_change( @@ -1457,6 +1458,7 @@ def test_compile_hourly_sum_statistics_negative_state( ("monetary", "SEK", "SEK", "SEK", None, 1), ("gas", "m³", "m³", "m³", "volume", 1), ("gas", "ft³", "ft³", "ft³", "volume", 1), + ("weight", "kg", "kg", "kg", "mass", 1), ], ) def test_compile_hourly_sum_statistics_total_no_reset( @@ -1569,6 +1571,7 @@ def test_compile_hourly_sum_statistics_total_no_reset( ("energy", "Wh", "Wh", "Wh", "energy", 1), ("gas", "m³", "m³", "m³", "volume", 1), ("gas", "ft³", "ft³", "ft³", "volume", 1), + ("weight", "kg", "kg", "kg", "mass", 1), ], ) def test_compile_hourly_sum_statistics_total_increasing( @@ -1679,7 +1682,10 @@ def test_compile_hourly_sum_statistics_total_increasing( "unit_class", "factor", ), - [("energy", "kWh", "kWh", "kWh", "energy", 1)], + [ + ("energy", "kWh", "kWh", "kWh", "energy", 1), + ("weight", "kg", "kg", "kg", "mass", 1), + ], ) def test_compile_hourly_sum_statistics_total_increasing_small_dip( hass_recorder: Callable[..., HomeAssistant],