36
36
)
37
37
from homeassistant .components .recorder .util import get_instance , session_scope
38
38
from homeassistant .components .sensor import ATTR_OPTIONS , DOMAIN , SensorDeviceClass
39
+ from homeassistant .components .sensor .recorder import (
40
+ STATE_CLASS_REMOVED_ISSUE ,
41
+ UNITS_CHANGED_ISSUE ,
42
+ )
39
43
from homeassistant .const import ATTR_FRIENDLY_NAME , STATE_UNAVAILABLE
40
44
from homeassistant .core import HomeAssistant , State
41
45
from homeassistant .helpers import issue_registry as ir
@@ -4428,11 +4432,11 @@ async def test_validate_unit_change_convertible(
4428
4432
"statistic_id" : "sensor.test" ,
4429
4433
"supported_unit" : supported_unit ,
4430
4434
},
4431
- "type" : "units_changed" ,
4435
+ "type" : UNITS_CHANGED_ISSUE ,
4432
4436
}
4433
4437
],
4434
4438
}
4435
- await assert_validation_result (hass , client , expected , {"units_changed" })
4439
+ await assert_validation_result (hass , client , expected , {UNITS_CHANGED_ISSUE })
4436
4440
4437
4441
# Unavailable state - empty response
4438
4442
hass .states .async_set (
@@ -4653,11 +4657,11 @@ async def test_validate_statistics_unit_change_no_device_class(
4653
4657
"statistic_id" : "sensor.test" ,
4654
4658
"supported_unit" : supported_unit ,
4655
4659
},
4656
- "type" : "units_changed" ,
4660
+ "type" : UNITS_CHANGED_ISSUE ,
4657
4661
}
4658
4662
],
4659
4663
}
4660
- await assert_validation_result (hass , client , expected , {"units_changed" })
4664
+ await assert_validation_result (hass , client , expected , {UNITS_CHANGED_ISSUE })
4661
4665
4662
4666
# Unavailable state - empty response
4663
4667
hass .states .async_set (
@@ -4769,11 +4773,11 @@ async def test_validate_statistics_state_class_removed(
4769
4773
"sensor.test" : [
4770
4774
{
4771
4775
"data" : {"statistic_id" : "sensor.test" },
4772
- "type" : "state_class_removed" ,
4776
+ "type" : STATE_CLASS_REMOVED_ISSUE ,
4773
4777
}
4774
4778
],
4775
4779
}
4776
- await assert_validation_result (hass , client , expected , {"state_class_removed" })
4780
+ await assert_validation_result (hass , client , expected , {STATE_CLASS_REMOVED_ISSUE })
4777
4781
4778
4782
# Unavailable state - empty response
4779
4783
hass .states .async_set (
@@ -4837,11 +4841,11 @@ async def test_validate_statistics_state_class_removed_issue_cleaned_up(
4837
4841
"sensor.test" : [
4838
4842
{
4839
4843
"data" : {"statistic_id" : "sensor.test" },
4840
- "type" : "state_class_removed" ,
4844
+ "type" : STATE_CLASS_REMOVED_ISSUE ,
4841
4845
}
4842
4846
],
4843
4847
}
4844
- await assert_validation_result (hass , client , expected , {"state_class_removed" })
4848
+ await assert_validation_result (hass , client , expected , {STATE_CLASS_REMOVED_ISSUE })
4845
4849
4846
4850
# Remove the statistics - empty response
4847
4851
get_instance (hass ).async_clear_statistics (["sensor.test" ])
@@ -5086,11 +5090,11 @@ async def test_validate_statistics_unit_change_no_conversion(
5086
5090
"statistic_id" : "sensor.test" ,
5087
5091
"supported_unit" : unit1 ,
5088
5092
},
5089
- "type" : "units_changed" ,
5093
+ "type" : UNITS_CHANGED_ISSUE ,
5090
5094
}
5091
5095
],
5092
5096
}
5093
- await assert_validation_result (hass , client , expected , {"units_changed" })
5097
+ await assert_validation_result (hass , client , expected , {UNITS_CHANGED_ISSUE })
5094
5098
5095
5099
# Unavailable state - empty response
5096
5100
hass .states .async_set (
@@ -5267,11 +5271,11 @@ async def test_validate_statistics_unit_change_equivalent_units_2(
5267
5271
"statistic_id" : "sensor.test" ,
5268
5272
"supported_unit" : supported_unit ,
5269
5273
},
5270
- "type" : "units_changed" ,
5274
+ "type" : UNITS_CHANGED_ISSUE ,
5271
5275
}
5272
5276
],
5273
5277
}
5274
- await assert_validation_result (hass , client , expected , {"units_changed" })
5278
+ await assert_validation_result (hass , client , expected , {UNITS_CHANGED_ISSUE })
5275
5279
5276
5280
# Run statistics one hour later, metadata will not be updated
5277
5281
await async_recorder_block_till_done (hass )
@@ -5280,7 +5284,7 @@ async def test_validate_statistics_unit_change_equivalent_units_2(
5280
5284
await assert_statistic_ids (
5281
5285
hass , [{"statistic_id" : "sensor.test" , "unit_of_measurement" : unit1 }]
5282
5286
)
5283
- await assert_validation_result (hass , client , expected , {"units_changed" })
5287
+ await assert_validation_result (hass , client , expected , {UNITS_CHANGED_ISSUE })
5284
5288
5285
5289
5286
5290
async def test_validate_statistics_other_domain (
@@ -5369,7 +5373,7 @@ async def one_hour_stats(start: datetime) -> datetime:
5369
5373
now = await one_hour_stats (now )
5370
5374
expected = {
5371
5375
"state_class_removed_sensor.test" : {
5372
- "issue_type" : "state_class_removed" ,
5376
+ "issue_type" : STATE_CLASS_REMOVED_ISSUE ,
5373
5377
"statistic_id" : "sensor.test" ,
5374
5378
}
5375
5379
}
@@ -5573,8 +5577,8 @@ def create_issue(domain: str, issue_id: str, data: dict | None) -> None:
5573
5577
create_issue ("test" , "test_issue" , None )
5574
5578
create_issue (DOMAIN , "test_issue_1" , None )
5575
5579
create_issue (DOMAIN , "test_issue_2" , {"issue_type" : "another_issue" })
5576
- create_issue (DOMAIN , "test_issue_3" , {"issue_type" : "state_class_removed" })
5577
- create_issue (DOMAIN , "test_issue_4" , {"issue_type" : "units_changed" })
5580
+ create_issue (DOMAIN , "test_issue_3" , {"issue_type" : STATE_CLASS_REMOVED_ISSUE })
5581
+ create_issue (DOMAIN , "test_issue_4" , {"issue_type" : UNITS_CHANGED_ISSUE })
5578
5582
5579
5583
# Check the issues
5580
5584
assert set (issue_registry .issues ) == {
0 commit comments