Improve statistics issue title (#126851)

pull/126782/head
Erik Montnemery 2024-09-27 18:32:20 +02:00 committed by Franck Nijhof
parent e8636670d4
commit a4ff292231
No known key found for this signature in database
GPG Key ID: D62583BA8AB11CA3
3 changed files with 13 additions and 20 deletions

View File

@ -693,15 +693,12 @@ def _update_issues(
if state_class is None:
# Sensor no longer has a valid state class
report_issue(
"unsupported_state_class",
"state_class_removed",
entity_id,
{
"statistic_id": entity_id,
"state_class": state_class,
},
{"statistic_id": entity_id},
)
else:
clear_issue("unsupported_state_class", entity_id)
clear_issue("state_class_removed", entity_id)
metadata_unit = metadata[1]["unit_of_measurement"]
converter = statistics.STATISTIC_UNIT_TO_UNIT_CONVERTER.get(metadata_unit)

View File

@ -289,13 +289,13 @@
}
},
"issues": {
"state_class_removed": {
"title": "{statistic_id} no longer has a state class",
"description": ""
},
"units_changed": {
"title": "The unit of {statistic_id} has changed",
"description": ""
},
"unsupported_state_class": {
"title": "The state class of {statistic_id} is not supported",
"description": ""
}
}
}

View File

@ -4580,7 +4580,7 @@ async def test_validate_statistics_unit_change_no_device_class(
(US_CUSTOMARY_SYSTEM, POWER_SENSOR_ATTRIBUTES, "W"),
],
)
async def test_validate_statistics_unsupported_state_class(
async def test_validate_statistics_state_class_removed(
hass: HomeAssistant,
hass_ws_client: WebSocketGenerator,
units,
@ -4620,15 +4620,12 @@ async def test_validate_statistics_unsupported_state_class(
expected = {
"sensor.test": [
{
"data": {
"state_class": None,
"statistic_id": "sensor.test",
},
"type": "unsupported_state_class",
"data": {"statistic_id": "sensor.test"},
"type": "state_class_removed",
}
],
}
await assert_validation_result(hass, client, expected, {"unsupported_state_class"})
await assert_validation_result(hass, client, expected, {"state_class_removed"})
@pytest.mark.parametrize(
@ -5130,9 +5127,8 @@ async def test_update_statistics_issues(
# Let statistics run for one hour, expect issue
now = await one_hour_stats(now)
expected = {
"unsupported_state_class_sensor.test": {
"issue_type": "unsupported_state_class",
"state_class": None,
"state_class_removed_sensor.test": {
"issue_type": "state_class_removed",
"statistic_id": "sensor.test",
}
}