Generate statistics for all sensors with a supported state_class (#54882)

* Generate statistics for all sensors

* Fix bugs, add tests

* Address review comments

* Cleanup warnings

* Simplify tests

* Simplify selection of statistics

* Fix tests
This commit is contained in:
Erik Montnemery 2021-08-25 13:00:35 +02:00 committed by GitHub
parent 0d654fa6b3
commit ffbd2d79c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 272 additions and 62 deletions

View file

@ -227,6 +227,19 @@ def _get_metadata(
return metadata
def get_metadata(
hass: HomeAssistant,
statistic_id: str,
) -> dict[str, str] | None:
"""Return metadata for a statistic_id."""
statistic_ids = [statistic_id]
with session_scope(hass=hass) as session:
metadata_ids = _get_metadata_ids(hass, session, [statistic_id])
if not metadata_ids:
return None
return _get_metadata(hass, session, statistic_ids, None).get(metadata_ids[0])
def _configured_unit(unit: str, units: UnitSystem) -> str:
"""Return the pressure and temperature units configured by the user."""
if unit == PRESSURE_PA: