From a4ff292231ddbdb55282d05f43b549344fe7a631 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Fri, 27 Sep 2024 18:32:20 +0200 Subject: [PATCH] Improve statistics issue title (#126851) --- homeassistant/components/sensor/recorder.py | 9 +++------ homeassistant/components/sensor/strings.json | 8 ++++---- tests/components/sensor/test_recorder.py | 16 ++++++---------- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/homeassistant/components/sensor/recorder.py b/homeassistant/components/sensor/recorder.py index f81c3308943..be0feb7fa52 100644 --- a/homeassistant/components/sensor/recorder.py +++ b/homeassistant/components/sensor/recorder.py @@ -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) diff --git a/homeassistant/components/sensor/strings.json b/homeassistant/components/sensor/strings.json index 4ef7dbc74f0..71bead342c4 100644 --- a/homeassistant/components/sensor/strings.json +++ b/homeassistant/components/sensor/strings.json @@ -289,12 +289,12 @@ } }, "issues": { - "units_changed": { - "title": "The unit of {statistic_id} has changed", + "state_class_removed": { + "title": "{statistic_id} no longer has a state class", "description": "" }, - "unsupported_state_class": { - "title": "The state class of {statistic_id} is not supported", + "units_changed": { + "title": "The unit of {statistic_id} has changed", "description": "" } } diff --git a/tests/components/sensor/test_recorder.py b/tests/components/sensor/test_recorder.py index 821c10e02d9..77bb6e17f68 100644 --- a/tests/components/sensor/test_recorder.py +++ b/tests/components/sensor/test_recorder.py @@ -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", } }