mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Do not validate device classes when entity state is unknown (#84860)
This commit is contained in:
parent
7a7f986444
commit
f8fa676ac8
@ -968,6 +968,7 @@ class SensorEntity(Entity):
|
|||||||
# Validate unit of measurement used for sensors with a device class
|
# Validate unit of measurement used for sensors with a device class
|
||||||
if (
|
if (
|
||||||
not self._invalid_unit_of_measurement_reported
|
not self._invalid_unit_of_measurement_reported
|
||||||
|
and value is not None
|
||||||
and device_class
|
and device_class
|
||||||
and (units := DEVICE_CLASS_UNITS.get(device_class)) is not None
|
and (units := DEVICE_CLASS_UNITS.get(device_class)) is not None
|
||||||
and native_unit_of_measurement not in units
|
and native_unit_of_measurement not in units
|
||||||
|
@ -1144,7 +1144,7 @@ async def test_device_classes_with_invalid_unit_of_measurement(
|
|||||||
platform.init(empty=True)
|
platform.init(empty=True)
|
||||||
platform.ENTITIES["0"] = platform.MockSensor(
|
platform.ENTITIES["0"] = platform.MockSensor(
|
||||||
name="Test",
|
name="Test",
|
||||||
native_value=None,
|
native_value="1.0",
|
||||||
device_class=device_class,
|
device_class=device_class,
|
||||||
native_unit_of_measurement="INVALID!",
|
native_unit_of_measurement="INVALID!",
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user