diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 9b0a3b5e3d4..f21f57d9d36 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -583,11 +583,11 @@ class SensorEntity(Entity): numerical_value = float(value) # type:ignore[arg-type] except (TypeError, ValueError) as err: raise ValueError( - f"Sensor {self.entity_id} has device class {device_class}, " - f"state class {state_class} unit {unit_of_measurement} and " - f"suggested precision {suggested_precision} thus indicating it " + f"Sensor {self.entity_id} has device class '{device_class}', " + f"state class '{state_class}' unit '{unit_of_measurement}' and " + f"suggested precision '{suggested_precision}' thus indicating it " f"has a numeric value; however, it has the non-numeric value: " - f"{value} ({type(value)})" + f"'{value}' ({type(value)})" ) from err else: numerical_value = value diff --git a/tests/components/sensor/test_init.py b/tests/components/sensor/test_init.py index 7c637b0a6f2..adcbb8084b7 100644 --- a/tests/components/sensor/test_init.py +++ b/tests/components/sensor/test_init.py @@ -1842,7 +1842,7 @@ async def test_non_numeric_validation_error( assert ( "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