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
pull/109744/head
Jan Bouwhuis 2024-02-05 18:01:06 +01:00 committed by GitHub
parent be6399410e
commit 5dfffb0818
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -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},
}

View File

@ -988,6 +988,7 @@ async def test_compile_hourly_sum_statistics_amount(
("monetary", "SEK", "SEK", "SEK", None, 1),
("gas", "", "", "", "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", "", "", "", "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", "", "", "", "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],