From 87be2ba823b5618546f0dca90b8680693bfcf737 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Thu, 18 Sep 2025 08:38:15 +0200 Subject: [PATCH] Use compat UOM in _is_valid_suggested_unit (#152350) Co-authored-by: Erik Montnemery --- homeassistant/components/number/__init__.py | 6 +++++- homeassistant/components/sensor/__init__.py | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/number/__init__.py b/homeassistant/components/number/__init__.py index 6bcdac284763..b30c9425b0a2 100644 --- a/homeassistant/components/number/__init__.py +++ b/homeassistant/components/number/__init__.py @@ -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 diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 419c4df4f84d..9997c992cd7c 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -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,