ollo69 / ha_tuya_custom

Tuya Custom Component for testing
Apache License 2.0
39 stars 18 forks source link

Regression in climate device - impossible to turn off #32

Closed maforshaw closed 3 years ago

maforshaw commented 3 years ago

I switched from the official Tuya integration to this custom integration to fix the various well known issues seen in the logs. That fixed the log errors but introduced a new problem - climate devices now cannot be switched off.

There are two ways to turn off a climate device, either set "hvac_mode" to "off" via service climate.set_hvac_mode or use service "climate.turn_off". Both of those fail. What actually happens is the device turns off and then back on.

I have tracked it down to a missing ELSE in the file "climate.py". See below.

    def set_hvac_mode(self, hvac_mode):
        """Set new target operation mode."""
        if hvac_mode == HVAC_MODE_OFF:
            self._tuya.turn_off()

        if not self._tuya.state():
            self._tuya.turn_on()

        if self._has_operation:
            self._tuya.set_operation_mode(HA_STATE_TO_TUYA.get(hvac_mode))

Notice how it turns if off and then back on! The fix is as follows:

    def set_hvac_mode(self, hvac_mode):
        """Set new target operation mode."""
        if hvac_mode == HVAC_MODE_OFF:
            self._tuya.turn_off()
        elif not self._tuya.state():
            self._tuya.turn_on()

        if self._has_operation:
            self._tuya.set_operation_mode(HA_STATE_TO_TUYA.get(hvac_mode))

The above fix means it now can be turned off using either service climate.set_hvac_mode or climate.turn_off.

ollo69 commented 3 years ago

Yes, that's a bug, due to the state update done in the Tuya library, This piece of code is indentical to original version, but in original version both conditions could never be true! It will be fixed with next realese.

ollo69 commented 3 years ago

Can you confirm that with last release issue is solved?

maforshaw commented 3 years ago

Hi, I just updated and can confirm it works perfectly, thank you.