Add WS API for removing statistics for a list of statistic_ids (#55078)
* Add WS API for removing statistics for a list of statistic_ids * Refactor according to code review, enable foreign keys support for sqlite * Adjust tests * Move clear_statistics WS API to recorder * Adjust tests after rebase * Update docstring * Update homeassistant/components/recorder/websocket_api.py Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io> * Adjust tests after rebase Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
0653693dff
commit
5976f898da
6 changed files with 188 additions and 2 deletions
|
@ -458,6 +458,14 @@ def _configured_unit(unit: str, units: UnitSystem) -> str:
|
|||
return unit
|
||||
|
||||
|
||||
def clear_statistics(instance: Recorder, statistic_ids: list[str]) -> None:
|
||||
"""Clear statistics for a list of statistic_ids."""
|
||||
with session_scope(session=instance.get_session()) as session: # type: ignore
|
||||
session.query(StatisticsMeta).filter(
|
||||
StatisticsMeta.statistic_id.in_(statistic_ids)
|
||||
).delete(synchronize_session=False)
|
||||
|
||||
|
||||
def list_statistic_ids(
|
||||
hass: HomeAssistant,
|
||||
statistic_type: Literal["mean"] | Literal["sum"] | None = None,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue