Do not validate device classes when entity state is unknown (#84860)

This commit is contained in:
Franck Nijhof 2022-12-30 19:07:49 +01:00 committed by GitHub
parent 7a7f986444
commit f8fa676ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 1 deletions

View File

@ -968,6 +968,7 @@ class SensorEntity(Entity):
# Validate unit of measurement used for sensors with a device class
if (
not self._invalid_unit_of_measurement_reported
and value is not None
and device_class
and (units := DEVICE_CLASS_UNITS.get(device_class)) is not None
and native_unit_of_measurement not in units

View File

@ -1144,7 +1144,7 @@ async def test_device_classes_with_invalid_unit_of_measurement(
platform.init(empty=True)
platform.ENTITIES["0"] = platform.MockSensor(
name="Test",
native_value=None,
native_value="1.0",
device_class=device_class,
native_unit_of_measurement="INVALID!",
)