Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions homeassistant/components/recorder/statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,8 @@ def list_statistic_ids(

result = {
meta["statistic_id"]: {
"has_mean": meta["has_mean"],
"has_sum": meta["has_sum"],
"name": meta["name"],
"source": meta["source"],
"unit_of_measurement": meta["unit_of_measurement"],
Expand Down Expand Up @@ -772,6 +774,8 @@ def list_statistic_ids(
return [
{
"statistic_id": _id,
"has_mean": info["has_mean"],
"has_sum": info["has_sum"],
"name": info.get("name"),
"source": info["source"],
"unit_of_measurement": info["unit_of_measurement"],
Expand Down
4 changes: 4 additions & 0 deletions homeassistant/components/sensor/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ def list_statistic_ids(

if device_class not in UNIT_CONVERSIONS:
result[state.entity_id] = {
"has_mean": "mean" in provided_statistics,
"has_sum": "sum" in provided_statistics,
"source": RECORDER_DOMAIN,
"unit_of_measurement": native_unit,
}
Expand All @@ -637,6 +639,8 @@ def list_statistic_ids(

statistics_unit = DEVICE_CLASS_UNITS[device_class]
result[state.entity_id] = {
"has_mean": "mean" in provided_statistics,
"has_sum": "sum" in provided_statistics,
"source": RECORDER_DOMAIN,
"unit_of_measurement": statistics_unit,
}
Expand Down
2 changes: 2 additions & 0 deletions tests/components/recorder/test_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,8 @@ def test_external_statistics(hass_recorder, caplog):
statistic_ids = list_statistic_ids(hass)
assert statistic_ids == [
{
"has_mean": False,
"has_sum": True,
"statistic_id": "test:total_energy_import",
"name": "Total imported energy",
"source": "test",
Expand Down
8 changes: 8 additions & 0 deletions tests/components/recorder/test_websocket_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ async def test_update_statistics_metadata(hass, hass_ws_client, new_unit):
assert response["result"] == [
{
"statistic_id": "sensor.test",
"has_mean": True,
"has_sum": False,
"name": None,
"source": "recorder",
"unit_of_measurement": "W",
Expand All @@ -254,6 +256,8 @@ async def test_update_statistics_metadata(hass, hass_ws_client, new_unit):
assert response["result"] == [
{
"statistic_id": "sensor.test",
"has_mean": True,
"has_sum": False,
"name": None,
"source": "recorder",
"unit_of_measurement": new_unit,
Expand Down Expand Up @@ -525,6 +529,8 @@ async def test_get_statistics_metadata(hass, hass_ws_client, units, attributes,
assert response["result"] == [
{
"statistic_id": "sensor.test",
"has_mean": False,
"has_sum": True,
"name": None,
"source": "recorder",
"unit_of_measurement": unit,
Expand All @@ -549,6 +555,8 @@ async def test_get_statistics_metadata(hass, hass_ws_client, units, attributes,
assert response["result"] == [
{
"statistic_id": "sensor.test",
"has_mean": False,
"has_sum": True,
"name": None,
"source": "recorder",
"unit_of_measurement": unit,
Expand Down