Skip to content

Commit 87be2ba

Browse files
epenetemontnemery
andauthored
Use compat UOM in _is_valid_suggested_unit (home-assistant#152350)
Co-authored-by: Erik Montnemery <[email protected]>
1 parent 51c35eb commit 87be2ba

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

homeassistant/components/number/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,11 @@ def native_unit_of_measurement(self) -> str | None:
371371
@final
372372
@property
373373
def __native_unit_of_measurement_compat(self) -> str | None:
374-
"""Process ambiguous units."""
374+
"""Handle wrong character coding in unit provided by integrations.
375+
376+
NumberEntity should read the number's native unit through this property instead
377+
of through native_unit_of_measurement.
378+
"""
375379
native_unit_of_measurement = self.native_unit_of_measurement
376380
return AMBIGUOUS_UNITS.get(
377381
native_unit_of_measurement, native_unit_of_measurement

homeassistant/components/sensor/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ def _is_valid_suggested_unit(self, suggested_unit_of_measurement: str) -> bool:
366366
because a unit converter supports both.
367367
"""
368368
# No need to check the unit converter if the units are the same
369-
if self.native_unit_of_measurement == suggested_unit_of_measurement:
369+
if self.__native_unit_of_measurement_compat == suggested_unit_of_measurement:
370370
return True
371371

372372
# Make sure there is a unit converter and it supports both units
@@ -478,7 +478,11 @@ def native_unit_of_measurement(self) -> str | None:
478478
@final
479479
@property
480480
def __native_unit_of_measurement_compat(self) -> str | None:
481-
"""Process ambiguous units."""
481+
"""Handle wrong character coding in unit provided by integrations.
482+
483+
SensorEntity should read the sensor's native unit through this property instead
484+
of through native_unit_of_measurement.
485+
"""
482486
native_unit_of_measurement = self.native_unit_of_measurement
483487
return AMBIGUOUS_UNITS.get(
484488
native_unit_of_measurement,

0 commit comments

Comments
 (0)