plmilord / Hass.io-custom-component-spaclient

Home Assistant integration - Spa Client
48 stars 16 forks source link

Rounding min max temp values #31

Closed 0R2YPsALXTVed6y closed 1 year ago

0R2YPsALXTVed6y commented 1 year ago

Hi there,

Thanks for all your hard work!

Can you please fix a rounding issue for min max temps?

In you file climate.py you have the following code:

@property
    def current_temperature(self):
        """Return the current temperature."""
        if self._spaclient.get_current_temp() != None:
            if self.hass.config.units.temperature_unit == TEMP_CELSIUS and self._spaclient.temp_scale == "Fahrenheit":
                return round(TemperatureConverter.convert(self._spaclient.get_current_temp(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
            if self.hass.config.units.temperature_unit == TEMP_CELSIUS and self._spaclient.temp_scale == "Celsius":
                return self._spaclient.get_current_temp() / 2
            if self.hass.config.units.temperature_unit == TEMP_FAHRENHEIT and self._spaclient.temp_scale == "Celsius":
                return round(TemperatureConverter.convert(self._spaclient.get_current_temp() / 2, TEMP_CELSIUS, TEMP_FAHRENHEIT) * 2) / 2
            return self._spaclient.get_current_temp()
        return None

This i working fine, so can you add this to:

@property
    def min_temp(self):
        """Return the minimum temperature."""
        if self._spaclient.get_temp_range() == "High":
            return round(TemperatureConverter.convert(self._spaclient.get_high_range_min(), TEMP_FAHRENHEIT, self.temperature_unit) * 2) / 2
        return TemperatureConverter.convert(self._spaclient.get_low_range_min(), TEMP_FAHRENHEIT, self.temperature_unit)

    @property
    def max_temp(self):
        """Return the maximum temperature."""
        if self._spaclient.get_temp_range() == "High":
            return TemperatureConverter.convert(self._spaclient.get_high_range_max(), TEMP_FAHRENHEIT, self.temperature_unit)
        return TemperatureConverter.convert(self._spaclient.get_low_range_max(), TEMP_FAHRENHEIT, self.temperature_unit)
0R2YPsALXTVed6y commented 1 year ago

Hi, After some debugging i think this should be changed code:

    @property
    def min_temp(self):
        """Return the minimum temperature."""
        if self._spaclient.get_temp_range() == "High":
            if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
                return round(TemperatureConverter.convert(self._spaclient.get_high_range_min(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
            return TemperatureConverter.convert(self._spaclient.get_high_range_min(), TEMP_FAHRENHEIT, self.temperature_unit)
        if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
            return round(TemperatureConverter.convert(self._spaclient.get_low_range_min(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
        return TemperatureConverter.convert(self._spaclient.get_low_range_min(), TEMP_FAHRENHEIT, self.temperature_unit)

    @property
    def max_temp(self):
        """Return the maximum temperature."""
        if self._spaclient.get_temp_range() == "High":
            if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
                return round(TemperatureConverter.convert(self._spaclient.get_high_range_max(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
            return TemperatureConverter.convert(self._spaclient.get_high_range_max(), TEMP_FAHRENHEIT, self.temperature_unit)
        if self.hass.config.units.temperature_unit == TEMP_CELSIUS:
            return round(TemperatureConverter.convert(self._spaclient.get_low_range_max(), TEMP_FAHRENHEIT, TEMP_CELSIUS) * 2) / 2
        return TemperatureConverter.convert(self._spaclient.get_low_range_max(), TEMP_FAHRENHEIT, self.temperature_unit)
plmilord commented 1 year ago

Integrated in "Spa Client v2.6c" version!

Thanks for your help!