Only validate sensors in sensor.recorder.validate_statistics (#79749)
parent
96a8beb29f
commit
aa5575ba65
|
@ -24,7 +24,7 @@ from homeassistant.components.recorder.models import (
|
|||
StatisticResult,
|
||||
)
|
||||
from homeassistant.const import ATTR_UNIT_OF_MEASUREMENT
|
||||
from homeassistant.core import HomeAssistant, State
|
||||
from homeassistant.core import HomeAssistant, State, split_entity_id
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.helpers.entity import entity_sources
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
@ -689,6 +689,8 @@ def validate_statistics(
|
|||
)
|
||||
|
||||
for statistic_id in sensor_statistic_ids - sensor_entity_ids:
|
||||
if split_entity_id(statistic_id)[0] != DOMAIN:
|
||||
continue
|
||||
# There is no sensor matching the statistics_id
|
||||
validation_result[statistic_id].append(
|
||||
statistics.ValidationIssue(
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
"""The tests for sensor recorder platform."""
|
||||
# pylint: disable=protected-access,invalid-name
|
||||
from datetime import timedelta
|
||||
from datetime import datetime, timedelta
|
||||
import math
|
||||
from statistics import mean
|
||||
from unittest.mock import patch
|
||||
|
@ -9,10 +9,15 @@ import pytest
|
|||
from pytest import approx
|
||||
|
||||
from homeassistant import loader
|
||||
from homeassistant.components.recorder import history
|
||||
from homeassistant.components.recorder import DOMAIN as RECORDER_DOMAIN, history
|
||||
from homeassistant.components.recorder.db_schema import StatisticsMeta
|
||||
from homeassistant.components.recorder.models import process_timestamp_to_utc_isoformat
|
||||
from homeassistant.components.recorder.models import (
|
||||
StatisticData,
|
||||
StatisticMetaData,
|
||||
process_timestamp_to_utc_isoformat,
|
||||
)
|
||||
from homeassistant.components.recorder.statistics import (
|
||||
async_import_statistics,
|
||||
get_metadata,
|
||||
list_statistic_ids,
|
||||
statistics_during_period,
|
||||
|
@ -3756,6 +3761,52 @@ async def test_validate_statistics_unit_change_no_conversion(
|
|||
await assert_validation_result(client, expected)
|
||||
|
||||
|
||||
async def test_validate_statistics_other_domain(hass, hass_ws_client, recorder_mock):
|
||||
"""Test sensor does not raise issues for statistics for other domains."""
|
||||
id = 1
|
||||
|
||||
def next_id():
|
||||
nonlocal id
|
||||
id += 1
|
||||
return id
|
||||
|
||||
async def assert_validation_result(client, expected_result):
|
||||
await client.send_json(
|
||||
{"id": next_id(), "type": "recorder/validate_statistics"}
|
||||
)
|
||||
response = await client.receive_json()
|
||||
assert response["success"]
|
||||
assert response["result"] == expected_result
|
||||
|
||||
await async_setup_component(hass, "sensor", {})
|
||||
await async_recorder_block_till_done(hass)
|
||||
client = await hass_ws_client()
|
||||
|
||||
# Create statistics for another domain
|
||||
metadata: StatisticMetaData = {
|
||||
"has_mean": True,
|
||||
"has_sum": True,
|
||||
"name": None,
|
||||
"source": RECORDER_DOMAIN,
|
||||
"statistic_id": "number.test",
|
||||
"unit_of_measurement": None,
|
||||
}
|
||||
statistics: StatisticData = {
|
||||
"last_reset": None,
|
||||
"max": None,
|
||||
"mean": None,
|
||||
"min": None,
|
||||
"start": datetime(2020, 10, 6, tzinfo=dt_util.UTC),
|
||||
"state": None,
|
||||
"sum": None,
|
||||
}
|
||||
async_import_statistics(hass, metadata, (statistics,))
|
||||
await async_recorder_block_till_done(hass)
|
||||
|
||||
# We should not get complains about the missing number entity
|
||||
await assert_validation_result(client, {})
|
||||
|
||||
|
||||
def record_meter_states(hass, zero, entity_id, _attributes, seq):
|
||||
"""Record some test states.
|
||||
|
||||
|
|
Loading…
Reference in New Issue