Ensure recorder api aligns with sensor converters (#87257)

This commit is contained in:
epenet 2023-02-04 21:28:47 +01:00 committed by GitHub
parent bcc1aa03b4
commit 19e27f4f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,8 @@ from homeassistant.components.recorder.statistics import (
get_metadata,
list_statistic_ids,
)
from homeassistant.components.recorder.websocket_api import UNIT_SCHEMA
from homeassistant.components.sensor import UNIT_CONVERTERS
from homeassistant.helpers import recorder as recorder_helper
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@ -124,6 +126,15 @@ VOLUME_SENSOR_M3_ATTRIBUTES_TOTAL = {
}
def test_converters_align_with_sensor():
"""Ensure UNIT_SCHEMA is aligned with sensor UNIT_CONVERTERS."""
for converter in UNIT_CONVERTERS.values():
assert converter.UNIT_CLASS in UNIT_SCHEMA.schema
for unit_class in UNIT_SCHEMA.schema:
assert any(c for c in UNIT_CONVERTERS.values() if unit_class == c.UNIT_CLASS)
async def test_statistics_during_period(recorder_mock, hass, hass_ws_client):
"""Test statistics_during_period."""
now = dt_util.utcnow()