Use unit enums in mold indicator (#84350)

This commit is contained in:
epenet 2022-12-21 11:14:07 +01:00 committed by GitHub
parent af7a487706
commit ecbcb9496d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,8 +14,7 @@ from homeassistant.const import (
EVENT_HOMEASSISTANT_START, EVENT_HOMEASSISTANT_START,
PERCENTAGE, PERCENTAGE,
STATE_UNKNOWN, STATE_UNKNOWN,
TEMP_CELSIUS, UnitOfTemperature,
TEMP_FAHRENHEIT,
) )
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
@ -219,16 +218,18 @@ class MoldIndicator(SensorEntity):
return None return None
# convert to celsius if necessary # convert to celsius if necessary
if unit == TEMP_FAHRENHEIT: if unit == UnitOfTemperature.FAHRENHEIT:
return TemperatureConverter.convert(temp, TEMP_FAHRENHEIT, TEMP_CELSIUS) return TemperatureConverter.convert(
if unit == TEMP_CELSIUS: temp, UnitOfTemperature.FAHRENHEIT, UnitOfTemperature.CELSIUS
)
if unit == UnitOfTemperature.CELSIUS:
return temp return temp
_LOGGER.error( _LOGGER.error(
"Temp sensor %s has unsupported unit: %s (allowed: %s, %s)", "Temp sensor %s has unsupported unit: %s (allowed: %s, %s)",
state.entity_id, state.entity_id,
unit, unit,
TEMP_CELSIUS, UnitOfTemperature.CELSIUS,
TEMP_FAHRENHEIT, UnitOfTemperature.FAHRENHEIT,
) )
return None return None
@ -309,7 +310,7 @@ class MoldIndicator(SensorEntity):
* (alpha + math.log(self._indoor_hum / 100.0)) * (alpha + math.log(self._indoor_hum / 100.0))
/ (beta - math.log(self._indoor_hum / 100.0)) / (beta - math.log(self._indoor_hum / 100.0))
) )
_LOGGER.debug("Dewpoint: %f %s", self._dewpoint, TEMP_CELSIUS) _LOGGER.debug("Dewpoint: %f %s", self._dewpoint, UnitOfTemperature.CELSIUS)
def _calc_moldindicator(self): def _calc_moldindicator(self):
"""Calculate the humidity at the (cold) calibration point.""" """Calculate the humidity at the (cold) calibration point."""
@ -332,7 +333,9 @@ class MoldIndicator(SensorEntity):
) )
_LOGGER.debug( _LOGGER.debug(
"Estimated Critical Temperature: %f %s", self._crit_temp, TEMP_CELSIUS "Estimated Critical Temperature: %f %s",
self._crit_temp,
UnitOfTemperature.CELSIUS,
) )
# Then calculate the humidity at this point # Then calculate the humidity at this point
@ -387,13 +390,17 @@ class MoldIndicator(SensorEntity):
} }
dewpoint = ( dewpoint = (
TemperatureConverter.convert(self._dewpoint, TEMP_CELSIUS, TEMP_FAHRENHEIT) TemperatureConverter.convert(
self._dewpoint, UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT
)
if self._dewpoint is not None if self._dewpoint is not None
else None else None
) )
crit_temp = ( crit_temp = (
TemperatureConverter.convert(self._crit_temp, TEMP_CELSIUS, TEMP_FAHRENHEIT) TemperatureConverter.convert(
self._crit_temp, UnitOfTemperature.CELSIUS, UnitOfTemperature.FAHRENHEIT
)
if self._crit_temp is not None if self._crit_temp is not None
else None else None
) )