Remove deprecated temperature conversion of non temperature sensors (#69069)
This commit is contained in:
parent
04dd7c3f7c
commit
e830032b33
4 changed files with 34 additions and 48 deletions
|
@ -367,7 +367,10 @@ class SensorEntity(Entity):
|
|||
|
||||
native_unit_of_measurement = self.native_unit_of_measurement
|
||||
|
||||
if native_unit_of_measurement in (TEMP_CELSIUS, TEMP_FAHRENHEIT):
|
||||
if (
|
||||
self.device_class == DEVICE_CLASS_TEMPERATURE
|
||||
and native_unit_of_measurement in (TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
):
|
||||
return self.hass.config.units.temperature_unit
|
||||
|
||||
return native_unit_of_measurement
|
||||
|
@ -450,37 +453,6 @@ class SensorEntity(Entity):
|
|||
# Round to the wanted precision
|
||||
value = round(value_f_new) if prec == 0 else round(value_f_new, prec)
|
||||
|
||||
elif (
|
||||
value is not None
|
||||
and self.device_class != DEVICE_CLASS_TEMPERATURE
|
||||
and native_unit_of_measurement != self.hass.config.units.temperature_unit
|
||||
and native_unit_of_measurement in (TEMP_CELSIUS, TEMP_FAHRENHEIT)
|
||||
):
|
||||
units = self.hass.config.units
|
||||
if not self._temperature_conversion_reported:
|
||||
self._temperature_conversion_reported = True
|
||||
report_issue = self._suggest_report_issue()
|
||||
_LOGGER.warning(
|
||||
"Entity %s (%s) with device_class %s reports a temperature in "
|
||||
"%s which will be converted to %s. Temperature conversion for "
|
||||
"entities without correct device_class is deprecated and will"
|
||||
" be removed from Home Assistant Core 2022.3. Please update "
|
||||
"your configuration if device_class is manually configured, "
|
||||
"otherwise %s",
|
||||
self.entity_id,
|
||||
type(self),
|
||||
self.device_class,
|
||||
native_unit_of_measurement,
|
||||
units.temperature_unit,
|
||||
report_issue,
|
||||
)
|
||||
value_s = str(value)
|
||||
prec = len(value_s) - value_s.index(".") - 1 if "." in value_s else 0
|
||||
# Suppress ValueError (Could not convert sensor_value to float)
|
||||
with suppress(ValueError):
|
||||
temp = units.temperature(float(value), native_unit_of_measurement) # type: ignore[arg-type]
|
||||
value = round(temp) if prec == 0 else round(temp, prec)
|
||||
|
||||
return value
|
||||
|
||||
def __repr__(self) -> str:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue