Use converter factory in sensor platform (#106508)

This is a bit faster than calling .covert
This commit is contained in:
J. Nick Koston 2023-12-27 13:06:36 -10:00 committed by GitHub
parent f59e2b0eec
commit 178e4f9e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -671,11 +671,10 @@ class SensorEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
converter := UNIT_CONVERTERS.get(device_class) converter := UNIT_CONVERTERS.get(device_class)
): ):
# Unit conversion needed # Unit conversion needed
converted_numerical_value = converter.convert( converted_numerical_value = converter.converter_factory(
float(numerical_value),
native_unit_of_measurement, native_unit_of_measurement,
unit_of_measurement, unit_of_measurement,
) )(float(numerical_value))
# If unit conversion is happening, and there's no rounding for display, # If unit conversion is happening, and there's no rounding for display,
# do a best effort rounding here. # do a best effort rounding here.