Improve error message for sensors with a non-numeric value (#93399)
* Improve error message for sensors with a non-numeric value * Address review comment
This commit is contained in:
parent
f8f83906f8
commit
d62cdf3d65
2 changed files with 5 additions and 5 deletions
|
@ -583,11 +583,11 @@ class SensorEntity(Entity):
|
||||||
numerical_value = float(value) # type:ignore[arg-type]
|
numerical_value = float(value) # type:ignore[arg-type]
|
||||||
except (TypeError, ValueError) as err:
|
except (TypeError, ValueError) as err:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"Sensor {self.entity_id} has device class {device_class}, "
|
f"Sensor {self.entity_id} has device class '{device_class}', "
|
||||||
f"state class {state_class} unit {unit_of_measurement} and "
|
f"state class '{state_class}' unit '{unit_of_measurement}' and "
|
||||||
f"suggested precision {suggested_precision} thus indicating it "
|
f"suggested precision '{suggested_precision}' thus indicating it "
|
||||||
f"has a numeric value; however, it has the non-numeric value: "
|
f"has a numeric value; however, it has the non-numeric value: "
|
||||||
f"{value} ({type(value)})"
|
f"'{value}' ({type(value)})"
|
||||||
) from err
|
) from err
|
||||||
else:
|
else:
|
||||||
numerical_value = value
|
numerical_value = value
|
||||||
|
|
|
@ -1842,7 +1842,7 @@ async def test_non_numeric_validation_error(
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
"thus indicating it has a numeric value; "
|
"thus indicating it has a numeric value; "
|
||||||
f"however, it has the non-numeric value: {native_value}"
|
f"however, it has the non-numeric value: '{native_value}'"
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue