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:
parent
0d654fa6b3
commit
ffbd2d79c8
3 changed files with 272 additions and 62 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue