mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Cleanup sensor unit conversion code (#97074)
This commit is contained in:
parent
095146b163
commit
61532475f9
@ -602,14 +602,11 @@ class SensorEntity(Entity):
|
|||||||
else:
|
else:
|
||||||
numerical_value = value
|
numerical_value = value
|
||||||
|
|
||||||
if (
|
if native_unit_of_measurement != unit_of_measurement and (
|
||||||
native_unit_of_measurement != unit_of_measurement
|
converter := UNIT_CONVERTERS.get(device_class)
|
||||||
and device_class in UNIT_CONVERTERS
|
|
||||||
):
|
):
|
||||||
# Unit conversion needed
|
# Unit conversion needed
|
||||||
converter = UNIT_CONVERTERS[device_class]
|
converted_numerical_value = converter.convert(
|
||||||
|
|
||||||
converted_numerical_value = UNIT_CONVERTERS[device_class].convert(
|
|
||||||
float(numerical_value),
|
float(numerical_value),
|
||||||
native_unit_of_measurement,
|
native_unit_of_measurement,
|
||||||
unit_of_measurement,
|
unit_of_measurement,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user