diff --git a/homeassistant/components/number/__init__.py b/homeassistant/components/number/__init__.py index 1ebd35711ac..3c7f7d2ca52 100644 --- a/homeassistant/components/number/__init__.py +++ b/homeassistant/components/number/__init__.py @@ -373,7 +373,8 @@ class NumberEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @property def __native_unit_of_measurement_compat(self) -> str | None: """Process ambiguous units.""" - native_unit_of_measurement = self.native_unit_of_measurement + if (native_unit_of_measurement := self.native_unit_of_measurement) is None: + return None return AMBIGUOUS_UNITS.get( native_unit_of_measurement, native_unit_of_measurement ) diff --git a/homeassistant/components/number/const.py b/homeassistant/components/number/const.py index 76af35adeba..ba460736455 100644 --- a/homeassistant/components/number/const.py +++ b/homeassistant/components/number/const.py @@ -560,7 +560,7 @@ UNIT_CONVERTERS: dict[NumberDeviceClass, type[BaseUnitConverter]] = { # We translate units that were using using the legacy coding of μ \u00b5 # to units using recommended coding of μ \u03bc -AMBIGUOUS_UNITS: dict[str | None, str] = { +AMBIGUOUS_UNITS: dict[str, str] = { "\u00b5Sv/h": "μSv/h", # aranet: radiation rate "\u00b5S/cm": UnitOfConductivity.MICROSIEMENS_PER_CM, "\u00b5V": UnitOfElectricPotential.MICROVOLT, diff --git a/homeassistant/components/sensor/__init__.py b/homeassistant/components/sensor/__init__.py index 56171707338..acc0a476219 100644 --- a/homeassistant/components/sensor/__init__.py +++ b/homeassistant/components/sensor/__init__.py @@ -474,7 +474,8 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): @property def __native_unit_of_measurement_compat(self) -> str | None: """Process ambiguous units.""" - native_unit_of_measurement = self.native_unit_of_measurement + if (native_unit_of_measurement := self.native_unit_of_measurement) is None: + return None return AMBIGUOUS_UNITS.get( native_unit_of_measurement, native_unit_of_measurement, diff --git a/homeassistant/components/sensor/const.py b/homeassistant/components/sensor/const.py index e09923ad940..6550450b27b 100644 --- a/homeassistant/components/sensor/const.py +++ b/homeassistant/components/sensor/const.py @@ -792,7 +792,7 @@ STATE_CLASS_UNITS: dict[SensorStateClass | str, set[type[StrEnum] | str | None]] # We translate units that were using using the legacy coding of μ \u00b5 # to units using recommended coding of μ \u03bc -AMBIGUOUS_UNITS: dict[str | None, str] = { +AMBIGUOUS_UNITS: dict[str, str] = { "\u00b5Sv/h": "μSv/h", # aranet: radiation rate "\u00b5S/cm": UnitOfConductivity.MICROSIEMENS_PER_CM, "\u00b5V": UnitOfElectricPotential.MICROVOLT,