def _convert_temperature(state: str, attr: dict) -> str:
    from homeassistant.components.sensor import SensorEntity
    unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
    units = self.hass.config.units
    if ((unit_of_measure == units.temperature_unit) or (unit_of_measure not in (TEMP_CELSIUS, TEMP_FAHRENHEIT))):
        return state
    domain = split_entity_id(self.entity_id)[0]
    if (domain != 'sensor'):
        if (not self._temperature_reported):
            self._temperature_reported = True
            report_issue = self._suggest_report_issue()
            _LOGGER.warning('Entity %s (%s) relies on automatic temperature conversion, this will be unsupported in Home Assistant Core 2022.7. Please %s', self.entity_id, type(self), report_issue)
    elif (not isinstance(self, SensorEntity)):
        if (not self._temperature_reported):
            self._temperature_reported = True
            report_issue = self._suggest_report_issue()
            _LOGGER.warning('Temperature sensor %s (%s) does not inherit SensorEntity, this will be unsupported in Home Assistant Core 2022.7.Please %s', self.entity_id, type(self), report_issue)
    else:
        return state
    try:
        prec = (((len(state) - state.index('.')) - 1) if ('.' in state) else 0)
        temp = units.temperature(float(state), unit_of_measure)
        state = str((round(temp) if (prec == 0) else round(temp, prec)))
        attr[ATTR_UNIT_OF_MEASUREMENT] = units.temperature_unit
    except ValueError:
        pass
    return state
def _convert_temperature(state: str, attr: dict) -> str:
    from homeassistant.components.sensor import SensorEntity
    unit_of_measure = attr.get(ATTR_UNIT_OF_MEASUREMENT)
    units = self.hass.config.units
    if ((unit_of_measure == units.temperature_unit) or (unit_of_measure not in (TEMP_CELSIUS, TEMP_FAHRENHEIT))):
        return state
    domain = split_entity_id(self.entity_id)[0]
    if (domain != 'sensor'):
        if (not self._temperature_reported):
            self._temperature_reported = True
            report_issue = self._suggest_report_issue()
            _LOGGER.warning('Entity %s (%s) relies on automatic temperature conversion, this will be unsupported in Home Assistant Core 2022.7. Please %s', self.entity_id, type(self), report_issue)
    elif (not isinstance(self, SensorEntity)):
        if (not self._temperature_reported):
            self._temperature_reported = True
            report_issue = self._suggest_report_issue()
            _LOGGER.warning('Temperature sensor %s (%s) does not inherit SensorEntity, this will be unsupported in Home Assistant Core 2022.7.Please %s', self.entity_id, type(self), report_issue)
    else:
        return state
    try:
        prec = (((len(state) - state.index('.')) - 1) if ('.' in state) else 0)
        temp = units.temperature(float(state), unit_of_measure)
        state = str((round(temp) if (prec == 0) else round(temp, prec)))
        attr[ATTR_UNIT_OF_MEASUREMENT] = units.temperature_unit
    except ValueError:
        pass
    return state