Indicate in statistics issues when units can be converted (#79121)
This commit is contained in:
parent
2167cf540d
commit
5bcef1c7ce
2 changed files with 225 additions and 5 deletions
|
@ -670,11 +670,16 @@ def validate_statistics(
|
|||
|
||||
metadata_unit = metadata[1]["unit_of_measurement"]
|
||||
if device_class not in UNIT_CONVERTERS:
|
||||
issue_type = (
|
||||
"units_changed_can_convert"
|
||||
if statistics.can_convert_units(metadata_unit, state_unit)
|
||||
else "units_changed"
|
||||
)
|
||||
if state_unit != metadata_unit:
|
||||
# The unit has changed
|
||||
validation_result[entity_id].append(
|
||||
statistics.ValidationIssue(
|
||||
"units_changed",
|
||||
issue_type,
|
||||
{
|
||||
"statistic_id": entity_id,
|
||||
"state_unit": state_unit,
|
||||
|
@ -684,16 +689,20 @@ def validate_statistics(
|
|||
)
|
||||
elif metadata_unit != UNIT_CONVERTERS[device_class].NORMALIZED_UNIT:
|
||||
# The unit in metadata is not supported for this device class
|
||||
statistics_unit = UNIT_CONVERTERS[device_class].NORMALIZED_UNIT
|
||||
issue_type = (
|
||||
"unsupported_unit_metadata_can_convert"
|
||||
if statistics.can_convert_units(metadata_unit, statistics_unit)
|
||||
else "unsupported_unit_metadata"
|
||||
)
|
||||
validation_result[entity_id].append(
|
||||
statistics.ValidationIssue(
|
||||
"unsupported_unit_metadata",
|
||||
issue_type,
|
||||
{
|
||||
"statistic_id": entity_id,
|
||||
"device_class": device_class,
|
||||
"metadata_unit": metadata_unit,
|
||||
"supported_unit": UNIT_CONVERTERS[
|
||||
device_class
|
||||
].NORMALIZED_UNIT,
|
||||
"supported_unit": statistics_unit,
|
||||
},
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue