mirror of
https://github.com/home-assistant/core.git
synced 2025-08-31 02:11:32 +02:00
Refactor native UOM compatibility helpers for sensor and number entity platform to not lookup None
key
This commit is contained in:
@@ -373,7 +373,8 @@ class NumberEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
@property
|
@property
|
||||||
def __native_unit_of_measurement_compat(self) -> str | None:
|
def __native_unit_of_measurement_compat(self) -> str | None:
|
||||||
"""Process ambiguous units."""
|
"""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(
|
return AMBIGUOUS_UNITS.get(
|
||||||
native_unit_of_measurement, native_unit_of_measurement
|
native_unit_of_measurement, native_unit_of_measurement
|
||||||
)
|
)
|
||||||
|
@@ -560,7 +560,7 @@ UNIT_CONVERTERS: dict[NumberDeviceClass, type[BaseUnitConverter]] = {
|
|||||||
|
|
||||||
# We translate units that were using using the legacy coding of μ \u00b5
|
# We translate units that were using using the legacy coding of μ \u00b5
|
||||||
# to units using recommended coding of μ \u03bc
|
# 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
|
"\u00b5Sv/h": "μSv/h", # aranet: radiation rate
|
||||||
"\u00b5S/cm": UnitOfConductivity.MICROSIEMENS_PER_CM,
|
"\u00b5S/cm": UnitOfConductivity.MICROSIEMENS_PER_CM,
|
||||||
"\u00b5V": UnitOfElectricPotential.MICROVOLT,
|
"\u00b5V": UnitOfElectricPotential.MICROVOLT,
|
||||||
|
@@ -474,7 +474,8 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
@property
|
@property
|
||||||
def __native_unit_of_measurement_compat(self) -> str | None:
|
def __native_unit_of_measurement_compat(self) -> str | None:
|
||||||
"""Process ambiguous units."""
|
"""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(
|
return AMBIGUOUS_UNITS.get(
|
||||||
native_unit_of_measurement,
|
native_unit_of_measurement,
|
||||||
native_unit_of_measurement,
|
native_unit_of_measurement,
|
||||||
|
@@ -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
|
# We translate units that were using using the legacy coding of μ \u00b5
|
||||||
# to units using recommended coding of μ \u03bc
|
# 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
|
"\u00b5Sv/h": "μSv/h", # aranet: radiation rate
|
||||||
"\u00b5S/cm": UnitOfConductivity.MICROSIEMENS_PER_CM,
|
"\u00b5S/cm": UnitOfConductivity.MICROSIEMENS_PER_CM,
|
||||||
"\u00b5V": UnitOfElectricPotential.MICROVOLT,
|
"\u00b5V": UnitOfElectricPotential.MICROVOLT,
|
||||||
|
Reference in New Issue
Block a user