Add support for total and total_increasing sensor state classes (#54523)

* Add support for amount and meter sensor state classes

* Ignore last_reset for STATE_CLASS_METER sensors

* Update tests

* Rename STATE_CLASS_METER to STATE_CLASS_AMOUNT_INCREASING

* Rename STATE_CLASS_AMOUNT to STATE_CLASS_TOTAL

* Fix typo

* Log warning if last_reset set together with state_class measurement

* Fix warning message
This commit is contained in:
Erik Montnemery 2021-08-13 12:35:23 +02:00 committed by GitHub
parent 821b93b0d0
commit 029873a088
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 296 additions and 28 deletions

View file

@ -1,6 +1,7 @@
"""The test for sensor device automation."""
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT, TEMP_CELSIUS, TEMP_FAHRENHEIT
from homeassistant.setup import async_setup_component
from homeassistant.util import dt as dt_util
async def test_deprecated_temperature_conversion(
@ -28,3 +29,24 @@ async def test_deprecated_temperature_conversion(
"your configuration if device_class is manually configured, otherwise report it "
"to the custom component author."
) in caplog.text
async def test_deprecated_last_reset(hass, caplog, enable_custom_integrations):
"""Test warning on deprecated last reset."""
platform = getattr(hass.components, "test.sensor")
platform.init(empty=True)
platform.ENTITIES["0"] = platform.MockSensor(
name="Test", state_class="measurement", last_reset=dt_util.utc_from_timestamp(0)
)
assert await async_setup_component(hass, "sensor", {"sensor": {"platform": "test"}})
await hass.async_block_till_done()
assert (
"Entity sensor.test (<class 'custom_components.test.sensor.MockSensor'>) "
"with state_class measurement has set last_reset. Setting last_reset for "
"entities with state_class other than 'total' is deprecated and will be "
"removed from Home Assistant Core 2021.10. Please update your configuration if "
"state_class is manually configured, otherwise report it to the custom "
"component author."
) in caplog.text