Skip to content

Commit

Permalink
Add is_on property to check the state of device.
Browse files Browse the repository at this point in the history
- This is related to #496 where if the on/off are string and usef if not both will return true, implement is_on to handle these cases as well
  • Loading branch information
xZetsubou committed Jan 19, 2025
1 parent 430f62d commit 928ed3c
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions custom_components/localtuya/climate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
"""Platform to locally control Tuya-based climate devices.
# PRESETS and HVAC_MODE Needs to be handle in better way.
"""
"""Platform to locally control Tuya-based climate devices."""

import asyncio
import logging
Expand Down Expand Up @@ -258,6 +256,11 @@ def __init__(
set_temp_unit = config_unit(config_temp_unit)
self._temperature_unit = set_temp_unit

@property
def _is_on(self):
"""Return if the device is on."""
return self._state and self._state != self._state_off

@property
def supported_features(self):
"""Flag supported features."""
Expand Down Expand Up @@ -299,7 +302,7 @@ def max_temp(self):
@property
def hvac_mode(self):
"""Return current operation ie. heat, cool, idle."""
if not self._state:
if not self._is_on:
return HVACMode.OFF
if not self._hvac_mode_dp:
return HVACMode.HEAT
Expand All @@ -321,7 +324,7 @@ def hvac_modes(self):
@property
def hvac_action(self):
"""Return the current running hvac operation if supported."""
if not self._state:
if not self._is_on:
return HVACAction.OFF

if not self._conf_hvac_action_dp:
Expand Down Expand Up @@ -419,15 +422,15 @@ async def async_set_temperature(self, **kwargs):

async def async_set_fan_mode(self, fan_mode):
"""Set new target fan mode."""
if not self._state:
if not self._is_on:
await self._device.set_dp(self._state_on, self._dp_id)

await self._device.set_dp(fan_mode, self._fan_speed_dp)

async def async_set_hvac_mode(self, hvac_mode: HVACMode):
"""Set new target operation mode."""
new_states = {}
if not self._state:
if not self._is_on:
new_states[self._dp_id] = self._state_on
elif hvac_mode == HVACMode.OFF and HVACMode.OFF not in self._hvac_mode_set:
new_states[self._dp_id] = self._state_off
Expand Down Expand Up @@ -501,7 +504,7 @@ def status_updated(self):
self._preset_mode = PRESET_NONE

# If device is off there is no needs to check the states.
if not self._state:
if not self._is_on:
return

# Update the HVAC Mode
Expand Down

0 comments on commit 928ed3c

Please sign in to comment.