Small cleanups to temperature helper (#107625)

pull/107642/head
J. Nick Koston 2024-01-08 21:51:35 -10:00 committed by GitHub
parent 9ca09bd6f0
commit 49e3c740cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 9 deletions

View File

@ -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)