Use compat UOM in _is_valid_suggested_unit (#152350)

Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
epenet
2025-09-18 08:38:15 +02:00
committed by GitHub
co-authored by Erik Montnemery
parent 51c35eb631
commit 87be2ba823
2 changed files with 11 additions and 3 deletions
+5 -1
View File
@@ -371,7 +371,11 @@ class NumberEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
@final
@property
def __native_unit_of_measurement_compat(self) -> str | None:
"""Process ambiguous units."""
"""Handle wrong character coding in unit provided by integrations.
NumberEntity should read the number's native unit through this property instead
of through native_unit_of_measurement.
"""
native_unit_of_measurement = self.native_unit_of_measurement
return AMBIGUOUS_UNITS.get(
native_unit_of_measurement, native_unit_of_measurement
+6 -2
View File
@@ -366,7 +366,7 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
because a unit converter supports both.
"""
# No need to check the unit converter if the units are the same
if self.native_unit_of_measurement == suggested_unit_of_measurement:
if self.__native_unit_of_measurement_compat == suggested_unit_of_measurement:
return True
# Make sure there is a unit converter and it supports both units
@@ -478,7 +478,11 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
@final
@property
def __native_unit_of_measurement_compat(self) -> str | None:
"""Process ambiguous units."""
"""Handle wrong character coding in unit provided by integrations.
SensorEntity should read the sensor's native unit through this property instead
of through native_unit_of_measurement.
"""
native_unit_of_measurement = self.native_unit_of_measurement
return AMBIGUOUS_UNITS.get(
native_unit_of_measurement,