Skip to content

Commit

Permalink
Merge pull request #89 from nao-pon/swing_off
Browse files Browse the repository at this point in the history
Set previous vane position when swing to off
  • Loading branch information
hristo-atanasov authored Aug 30, 2022
2 parents 63fa78c + e0c2998 commit 67d7012
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
46 changes: 30 additions & 16 deletions custom_components/tasmota_irhvac/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@ def __init__(
self._sub_state = None
self._keep_mode = config[CONF_KEEP_MODE]
self._last_on_mode = None
self._swingv = config.get(CONF_SWINGV)
self._swingh = config.get(CONF_SWINGH)
self._swingv = config.get(CONF_SWINGV).lower() if config.get(CONF_SWINGV) is not None else None
self._swingh = config.get(CONF_SWINGH).lower() if config.get(CONF_SWINGH) is not None else None
self._fix_swingv = None
self._fix_swingh = None

availability_topic = config.get(CONF_AVAILABILITY_TOPIC)
if (availability_topic) is None:
Expand Down Expand Up @@ -522,6 +524,10 @@ async def async_added_to_hass(self):
self._enabled = self._hvac_mode != HVAC_MODE_OFF
if self._enabled:
self._last_on_mode = self._hvac_mode
if self._swingv != "auto":
self._fix_swingv = self._swingv
if self._swingh != "auto":
self._fix_swingh = self._swingh
else:
# No previous state, try and restore defaults
if self._target_temp is None:
Expand Down Expand Up @@ -608,8 +614,12 @@ async def state_message_received(msg):
self._sleep = payload["Sleep"]
if "SwingV" in payload:
self._swingv = payload["SwingV"].lower()
if self._swingv != "auto":
self._fix_swingv = self._swingv
if "SwingH" in payload:
self._swingh = payload["SwingH"].lower()
if self._swingh != "auto":
self._fix_swingh = self._swingh
if (
"SwingV" in payload
and payload["SwingV"].lower() == STATE_AUTO
Expand Down Expand Up @@ -668,6 +678,7 @@ async def state_message_received(msg):

# Update HA UI and State
await self.async_update_ha_state()
#self.async_schedule_update_ha_state()

# Check power sensor state
if self._power_sensor and prev_power is not None and prev_power != self.power_mode:
Expand Down Expand Up @@ -910,6 +921,7 @@ async def async_set_swing_mode(self, swing_mode):
_LOGGER.error(self._swing_list)
return
self._swing_mode = swing_mode
# note: set _swingv and _swingh in send_ir() later
if not self._hvac_mode == HVAC_MODE_OFF:
self.power_mode = STATE_ON
await self.async_send_cmd()
Expand Down Expand Up @@ -971,11 +983,15 @@ async def async_set_sleep(self, sleep):
async def async_set_swingv(self, swingv):
"""Set new target swingv."""
self._swingv = swingv.lower()
if self._swingv != "auto":
self._fix_swingv = self._swingv
await self.async_send_cmd()

async def async_set_swingh(self, swingh):
"""Set new target swingh."""
self._swingh = swingh.lower()
if self._swingh != "auto":
self._fix_swingh = self._swingh
await self.async_send_cmd()

async def _async_power_sensor_changed(self, entity_id, old_state, new_state):
Expand Down Expand Up @@ -1103,20 +1119,18 @@ async def send_ir(self):
if self.fan_mode == HVAC_FAN_MAX:
fan_speed = HVAC_FAN_AUTO


# Set the swing mode - default off
if self._swingv is None or SWING_BOTH in self._swing_list or SWING_VERTICAL in self._swing_list:
swing_v = STATE_OFF
if self.swing_mode == SWING_BOTH or self.swing_mode == SWING_VERTICAL:
swing_v = STATE_AUTO
else:
swing_v = self._swingv
self._swingv = STATE_OFF if self._fix_swingv is None else self._fix_swingv
self._swingh = STATE_OFF if self._fix_swingh is None else self._fix_swingh

if self._swingh is None or SWING_BOTH in self._swing_list or SWING_HORIZONTAL in self._swing_list:
swing_h = STATE_OFF
if self.swing_mode == SWING_BOTH or self.swing_mode == SWING_HORIZONTAL:
swing_h = STATE_AUTO
else:
swing_h = self._swingh
if SWING_BOTH in self._swing_list or SWING_VERTICAL in self._swing_list:
if self._swing_mode == SWING_BOTH or self._swing_mode == SWING_VERTICAL:
self._swingv = STATE_AUTO

if SWING_BOTH in self._swing_list or SWING_HORIZONTAL in self._swing_list:
if self._swing_mode == SWING_BOTH or self._swing_mode == SWING_HORIZONTAL:
self._swingh = STATE_AUTO

_dt = dt_util.now()
_min = _dt.hour * 60 + _dt.minute
Expand All @@ -1131,8 +1145,8 @@ async def send_ir(self):
"Celsius": self._celsius,
"Temp": self._target_temp,
"FanSpeed": fan_speed,
"SwingV": swing_v,
"SwingH": swing_h,
"SwingV": self._swingv,
"SwingH": self._swingh,
"Quiet": self._quiet,
"Turbo": self._turbo,
"Econo": self._econo,
Expand Down
4 changes: 4 additions & 0 deletions custom_components/tasmota_irhvac/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
ATTR_LAST_ON_MODE = 'last_on_mode'
ATTR_SWINGV = 'swingv'
ATTR_SWINGH = 'swingh'
ATTR_FIX_SWINGV = 'fix_swingv'
ATTR_FIX_SWINGH = 'fix_swingh'

SERVICE_ECONO_MODE = 'set_econo'
SERVICE_TURBO_MODE = 'set_turbo'
Expand All @@ -155,6 +157,8 @@
ATTR_LAST_ON_MODE: 'last_on_mode',
ATTR_SWINGV: 'swingv',
ATTR_SWINGH: 'swingh',
ATTR_FIX_SWINGV: 'fix_swingv',
ATTR_FIX_SWINGH: 'fix_swingh',
}

ON_OFF_LIST = [
Expand Down

0 comments on commit 67d7012

Please sign in to comment.