Skip to content

Commit

Permalink
Merge pull request #18 from simonengelhardt/add-set-preset-mode-and-h…
Browse files Browse the repository at this point in the history
…vac-action-support

Add support for setting preset mode and mapping `work_state` to `hvac_action`
  • Loading branch information
MTrab authored Apr 11, 2022
2 parents 2e9350c + 63809a4 commit eab2273
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
43 changes: 41 additions & 2 deletions custom_components/danfoss_ally/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
SUPPORT_TARGET_TEMPERATURE,
Expand Down Expand Up @@ -210,12 +211,36 @@ def preset_modes(self):
"""
return self._supported_preset_modes

def set_preset_mode(self, preset_mode):
"""Set new target preset mode."""

_LOGGER.debug(
"Setting preset mode to %s",
preset_mode
)

if preset_mode == PRESET_HOME:
mode = "at_home"
elif preset_mode == PRESET_AWAY:
mode = "leaving_home"
elif preset_mode == PRESET_PAUSE:
mode = "pause"

if mode is None:
return

self._ally.setMode(self._device_id, mode)

@property
def hvac_action(self):
"""Return the current running hvac operation if supported.
Need to be one of CURRENT_HVAC_*.
"""
return CURRENT_HVAC_HEAT
if 'work_state' in self._device:
if self._device['work_state'] == 'Heat':
return CURRENT_HVAC_HEAT
elif self._device['work_state'] == 'NoHeat':
return CURRENT_HVAC_IDLE

@property
def temperature_unit(self):
Expand Down Expand Up @@ -272,4 +297,18 @@ def _async_update_callback(self):

def set_hvac_mode(self, hvac_mode):
"""Set new target hvac mode."""
#Currently unsupported by API

_LOGGER.debug(
"Setting hvac mode to %s",
hvac_mode
)

if hvac_mode == HVAC_MODE_AUTO:
mode = "at_home" # We have to choose either at_home or leaving_home
elif hvac_mode == HVAC_MODE_HEAT:
mode = "manual"

if mode is None:
return

self._ally.setMode(self._device_id, mode)
2 changes: 1 addition & 1 deletion custom_components/danfoss_ally/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Danfoss Ally",
"documentation": "https://github.com/MTrab/danfoss_ally/blob/master/README.md",
"issue_tracker": "https://github.com/MTrab/danfoss_ally/issues",
"requirements": ["pydanfossally==0.0.25"],
"requirements": ["pydanfossally==0.0.26"],
"codeowners": ["@MTrab"],
"version": "1.0.4",
"config_flow": true,
Expand Down

0 comments on commit eab2273

Please sign in to comment.