mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 08:47:57 +00:00
Fix kitchen_sink statistic issues (#139228)
This commit is contained in:
parent
212c42ca77
commit
24bb13e0d1
@ -296,7 +296,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
metadata = {
|
||||
"source": RECORDER_DOMAIN,
|
||||
"name": None,
|
||||
"statistic_id": "sensor.statistics_issue_1",
|
||||
"statistic_id": "sensor.statistics_issues_issue_1",
|
||||
"unit_of_measurement": UnitOfVolume.CUBIC_METERS,
|
||||
"has_mean": True,
|
||||
"has_sum": False,
|
||||
@ -308,7 +308,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
metadata = {
|
||||
"source": RECORDER_DOMAIN,
|
||||
"name": None,
|
||||
"statistic_id": "sensor.statistics_issue_2",
|
||||
"statistic_id": "sensor.statistics_issues_issue_2",
|
||||
"unit_of_measurement": "cats",
|
||||
"has_mean": True,
|
||||
"has_sum": False,
|
||||
@ -320,7 +320,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
metadata = {
|
||||
"source": RECORDER_DOMAIN,
|
||||
"name": None,
|
||||
"statistic_id": "sensor.statistics_issue_3",
|
||||
"statistic_id": "sensor.statistics_issues_issue_3",
|
||||
"unit_of_measurement": UnitOfVolume.CUBIC_METERS,
|
||||
"has_mean": True,
|
||||
"has_sum": False,
|
||||
@ -332,7 +332,7 @@ async def _insert_statistics(hass: HomeAssistant) -> None:
|
||||
metadata = {
|
||||
"source": RECORDER_DOMAIN,
|
||||
"name": None,
|
||||
"statistic_id": "sensor.statistics_issue_4",
|
||||
"statistic_id": "sensor.statistics_issues_issue_4",
|
||||
"unit_of_measurement": UnitOfVolume.CUBIC_METERS,
|
||||
"has_mean": True,
|
||||
"has_sum": False,
|
||||
|
52
tests/components/kitchen_sink/snapshots/test_init.ambr
Normal file
52
tests/components/kitchen_sink/snapshots/test_init.ambr
Normal file
@ -0,0 +1,52 @@
|
||||
# serializer version: 1
|
||||
# name: test_statistics_issues
|
||||
dict({
|
||||
'sensor.statistics_issues_issue_1': list([
|
||||
dict({
|
||||
'data': dict({
|
||||
'metadata_unit': 'm³',
|
||||
'state_unit': 'W',
|
||||
'statistic_id': 'sensor.statistics_issues_issue_1',
|
||||
'supported_unit': 'CCF, L, fl. oz., ft³, gal, mL, m³',
|
||||
}),
|
||||
'type': 'units_changed',
|
||||
}),
|
||||
]),
|
||||
'sensor.statistics_issues_issue_2': list([
|
||||
dict({
|
||||
'data': dict({
|
||||
'metadata_unit': 'cats',
|
||||
'state_unit': 'dogs',
|
||||
'statistic_id': 'sensor.statistics_issues_issue_2',
|
||||
'supported_unit': 'cats',
|
||||
}),
|
||||
'type': 'units_changed',
|
||||
}),
|
||||
]),
|
||||
'sensor.statistics_issues_issue_3': list([
|
||||
dict({
|
||||
'data': dict({
|
||||
'statistic_id': 'sensor.statistics_issues_issue_3',
|
||||
}),
|
||||
'type': 'state_class_removed',
|
||||
}),
|
||||
dict({
|
||||
'data': dict({
|
||||
'metadata_unit': 'm³',
|
||||
'state_unit': 'W',
|
||||
'statistic_id': 'sensor.statistics_issues_issue_3',
|
||||
'supported_unit': 'CCF, L, fl. oz., ft³, gal, mL, m³',
|
||||
}),
|
||||
'type': 'units_changed',
|
||||
}),
|
||||
]),
|
||||
'sensor.statistics_issues_issue_4': list([
|
||||
dict({
|
||||
'data': dict({
|
||||
'statistic_id': 'sensor.statistics_issues_issue_4',
|
||||
}),
|
||||
'type': 'no_state',
|
||||
}),
|
||||
]),
|
||||
})
|
||||
# ---
|
@ -5,6 +5,7 @@ from http import HTTPStatus
|
||||
from unittest.mock import ANY
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.kitchen_sink import DOMAIN
|
||||
@ -102,6 +103,25 @@ async def test_demo_statistics_growth(hass: HomeAssistant) -> None:
|
||||
assert statistics[statistic_id][0]["sum"] <= (2**20 + 24)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("recorder_mock", "mock_history")
|
||||
async def test_statistics_issues(
|
||||
hass: HomeAssistant,
|
||||
hass_ws_client: WebSocketGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test that the kitchen sink sum statistics causes statistics issues."""
|
||||
assert await async_setup_component(hass, DOMAIN, {DOMAIN: {}})
|
||||
await hass.async_block_till_done()
|
||||
await hass.async_start()
|
||||
await async_wait_recording_done(hass)
|
||||
|
||||
ws_client = await hass_ws_client(hass)
|
||||
await ws_client.send_json_auto_id({"type": "recorder/validate_statistics"})
|
||||
response = await ws_client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == snapshot
|
||||
|
||||
|
||||
@pytest.mark.freeze_time("2023-10-21")
|
||||
@pytest.mark.usefixtures("mock_history")
|
||||
async def test_issues_created(
|
||||
|
Loading…
x
Reference in New Issue
Block a user