Improve statistics issue title (#126851)

This commit is contained in:
Erik Montnemery 2024-09-27 18:32:20 +02:00 committed by GitHub
parent cba2daf314
commit 495faf5033
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 20 deletions

View File

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

View File

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

View File

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