Skip to content

Commit

Permalink
refactor: set K_AC_RUNNING to 1 only once
Browse files Browse the repository at this point in the history
- seperate OFF case with all other modes
  • Loading branch information
rxwen committed Nov 4, 2023
1 parent 0731075 commit 0f55c59
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions custom_components/terncy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,24 +139,22 @@ async def async_set_hvac_mode(self, hvac_mode: HVACMode) -> None:
if hvac_mode == HVACMode.OFF:
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_RUNNING, 0)
elif hvac_mode == HVACMode.COOL:
await self.api.set_attribute(self.eid, K_AC_RUNNING, 1)
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 1)
elif hvac_mode == HVACMode.DRY:
await self.api.set_attribute(self.eid, K_AC_RUNNING, 1)
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 2)
elif hvac_mode == HVACMode.FAN_ONLY:
await self.api.set_attribute(self.eid, K_AC_RUNNING, 1)
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 4)
elif hvac_mode == HVACMode.HEAT:
await self.api.set_attribute(self.eid, K_AC_RUNNING, 1)
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 8)
else:
_LOGGER.warning("Unsupported hvac_mode: %s", hvac_mode)
await self.api.set_attribute(self.eid, K_AC_RUNNING, 1)
if hvac_mode == HVACMode.COOL:
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 1)
elif hvac_mode == HVACMode.DRY:
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 2)
elif hvac_mode == HVACMode.FAN_ONLY:
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 4)
elif hvac_mode == HVACMode.HEAT:
self._attr_hvac_mode = hvac_mode
await self.api.set_attribute(self.eid, K_AC_MODE, 8)
else:
_LOGGER.warning("Unsupported hvac_mode: %s", hvac_mode)
self.async_write_ha_state()

async def async_turn_on(self) -> None:
Expand Down

0 comments on commit 0f55c59

Please sign in to comment.