From 49e3c740cced2f4752c8c50ed58379c5d969e92c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 8 Jan 2024 21:51:35 -1000 Subject: [PATCH] Small cleanups to temperature helper (#107625) --- homeassistant/helpers/temperature.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/homeassistant/helpers/temperature.py b/homeassistant/helpers/temperature.py index 5a35f1bee13..15d38063f63 100644 --- a/homeassistant/helpers/temperature.py +++ b/homeassistant/helpers/temperature.py @@ -24,17 +24,14 @@ def display_temp( raise TypeError(f"Temperature is not a number: {temperature}") if temperature_unit != ha_unit: - temperature = TemperatureConverter.convert( - temperature, temperature_unit, ha_unit + temperature = TemperatureConverter.converter_factory(temperature_unit, ha_unit)( + temperature ) # Round in the units appropriate if precision == PRECISION_HALVES: - temperature = round(temperature * 2) / 2.0 - elif precision == PRECISION_TENTHS: - temperature = round(temperature, 1) + return round(temperature * 2) / 2.0 + if precision == PRECISION_TENTHS: + return round(temperature, 1) # Integer as a fall back (PRECISION_WHOLE) - else: - temperature = round(temperature) - - return temperature + return round(temperature)