Add new climate feature flags to tuya (#109434)

This commit is contained in:
G Johansson 2024-02-04 05:40:37 -05:00 committed by GitHub
parent 37f3fcbdaf
commit 6e5a085413
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -127,6 +127,7 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
_set_temperature: IntegerTypeData | None = None
entity_description: TuyaClimateEntityDescription
_attr_name = None
_enable_turn_on_off_backwards_compatibility = False
def __init__(
self,
@ -277,6 +278,11 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
if self.find_dpcode(DPCode.SWITCH_VERTICAL, prefer_function=True):
self._attr_swing_modes.append(SWING_VERTICAL)
if DPCode.SWITCH in self.device.function:
self._attr_supported_features |= (
ClimateEntityFeature.TURN_OFF | ClimateEntityFeature.TURN_ON
)
async def async_added_to_hass(self) -> None:
"""Call when entity is added to hass."""
await super().async_added_to_hass()
@ -476,23 +482,8 @@ class TuyaClimateEntity(TuyaEntity, ClimateEntity):
def turn_on(self) -> None:
"""Turn the device on, retaining current HVAC (if supported)."""
if DPCode.SWITCH in self.device.function:
self._send_command([{"code": DPCode.SWITCH, "value": True}])
return
# Fake turn on
for mode in (HVACMode.HEAT_COOL, HVACMode.HEAT, HVACMode.COOL):
if mode not in self.hvac_modes:
continue
self.set_hvac_mode(mode)
break
self._send_command([{"code": DPCode.SWITCH, "value": True}])
def turn_off(self) -> None:
"""Turn the device on, retaining current HVAC (if supported)."""
if DPCode.SWITCH in self.device.function:
self._send_command([{"code": DPCode.SWITCH, "value": False}])
return
# Fake turn off
if HVACMode.OFF in self.hvac_modes:
self.set_hvac_mode(HVACMode.OFF)
self._send_command([{"code": DPCode.SWITCH, "value": False}])