Skip to content

Commit

Permalink
Improve statistics issue title (#126851)
Browse files Browse the repository at this point in the history
  • Loading branch information
emontnemery authored Sep 27, 2024
1 parent cba2daf commit 495faf5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
9 changes: 3 additions & 6 deletions homeassistant/components/sensor/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions homeassistant/components/sensor/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": ""
}
}
Expand Down
16 changes: 6 additions & 10 deletions tests/components/sensor/test_recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -5130,9 +5127,8 @@ async def one_hour_stats(start: datetime) -> datetime:
# 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",
}
}
Expand Down

0 comments on commit 495faf5

Please sign in to comment.