Skip to content

Commit

Permalink
Merge pull request #22 from rbak69/master
Browse files Browse the repository at this point in the history
Improved Vacation state (eco preset)
  • Loading branch information
cyberjunky authored Jan 20, 2021
2 parents bb08111 + 93fb482 commit c329aee
Showing 1 changed file with 48 additions and 19 deletions.
67 changes: 48 additions & 19 deletions custom_components/toon_climate/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CURRENT_HVAC_IDLE,
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
HVAC_MODE_OFF,
PRESET_AWAY,
PRESET_COMFORT,
PRESET_ECO,
Expand Down Expand Up @@ -135,6 +136,7 @@ def __init__(self, session, config) -> None:
self._current_temperature = None
self._ot_comm_error = None
self._program_state = None
self._hvac_mode = None

@staticmethod
async def do_api_request(session, url):
Expand Down Expand Up @@ -191,7 +193,16 @@ async def async_update(self) -> None:
self._current_temperature = int(self._data["currentTemp"]) / 100
self._ot_comm_error = int(self._data["otCommError"])
self._program_state = int(self._data["programState"])


if (self._active_state == 4):
self._hvac_mode = HVAC_MODE_OFF
elif (self._program_state == 0):
self._hvac_mode = HVAC_MODE_HEAT
elif (self._program_state == 1) or (self._program_state == 2):
self._hvac_mode = HVAC_MODE_AUTO
else:
self._hvac_mode = None

@property
def supported_features(self) -> int:
"""
Expand Down Expand Up @@ -380,21 +391,9 @@ def hvac_modes(self) -> List[str]:
def hvac_mode(self) -> str:
"""
Return the current operation mode
Toon programState values
- 0: Programm mode is off (not automatically changing presets)
- 1: Programm mode is on (automatically changing presets)
- 2: Programm mode is on but setpoint/preset is changed until
the next preset is automatically activated
- 8: No official programm mode as according to the Toon API doc
this would be state 4. This only seems to works when we
we use an 8. It will return the programm state to it's
original state when another preset is selected.
"""
if (self._program_state == 1) or (self._program_state == 2):
return HVAC_MODE_AUTO

return HVAC_MODE_HEAT
return self._hvac_mode


async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""
Expand All @@ -403,23 +402,53 @@ async def async_set_hvac_mode(self, hvac_mode: str) -> None:
Support modes:
- HVAC_MODE_HEAT: Heat to a target temperature (schedule off)
- HVAC_MODE_AUTO: Follow the configured schedule
- HVAC_MODE_OFF: Vacation mode (heat to a target architecture)
"""
_LOGGER.debug("Set Toon hvac mode to %s", str(hvac_mode))

if hvac_mode == HVAC_MODE_HEAT:
if (hvac_mode == HVAC_MODE_HEAT) and (self._active_state == 4):
""" Set preset to home when returning from vacation """
self._data = await self.do_api_request(
self._session,
BASE_URL.format(
self._host, self._port,
"/happ_thermstat?action=changeSchemeState"
"&state=0"
"&temperatureState=1",
),
)
elif (hvac_mode == HVAC_MODE_HEAT):
""" No preset needs to be defined """
self._data = await self.do_api_request(
self._session,
BASE_URL.format(
self._host, self._port,
"/happ_thermstat?action=changeSchemeState"
"&state=0",
),
)
elif (hvac_mode == HVAC_MODE_AUTO):
""" No preset needs to be defined """
self._data = await self.do_api_request(
self._session,
BASE_URL.format(
self._host, self._port,
"/happ_thermstat?action=changeSchemeState&state=0",
"/happ_thermstat?action=changeSchemeState"
"&state=1",
),
)
elif hvac_mode == HVAC_MODE_AUTO:
elif (hvac_mode == HVAC_MODE_OFF):
"""
For vacation mode the state needs to be set to 8
and the temperature preset needs to be set to 4
"""
self._data = await self.do_api_request(
self._session,
BASE_URL.format(
self._host, self._port,
"/happ_thermstat?action=changeSchemeState&state=1",
"/happ_thermstat?action=changeSchemeState"
"&state=8"
"&temperatureState=4",
),
)

Expand Down

0 comments on commit c329aee

Please sign in to comment.