Cleanup sensor unit conversion code (#97074)

This commit is contained in:
J. Nick Koston 2023-07-23 03:49:45 -05:00 committed by GitHub
parent 095146b163
commit 61532475f9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -602,14 +602,11 @@ class SensorEntity(Entity):
else:
numerical_value = value
if (
native_unit_of_measurement != unit_of_measurement
and device_class in UNIT_CONVERTERS
if native_unit_of_measurement != unit_of_measurement and (
converter := UNIT_CONVERTERS.get(device_class)
):
# Unit conversion needed
converter = UNIT_CONVERTERS[device_class]
converted_numerical_value = UNIT_CONVERTERS[device_class].convert(
converted_numerical_value = converter.convert(
float(numerical_value),
native_unit_of_measurement,
unit_of_measurement,