-
-
Notifications
You must be signed in to change notification settings - Fork 28.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use integration fallback configuration for tado water heater fallback (…
…#111014) * 103619 tado water heater fallback * extracted a method to remove code duplication * test cases and suggested changes * tests * util method for connector * Update homeassistant/components/tado/climate.py Co-authored-by: Andriy Kushnir <me@orhideous.name> * missing import after applies suggestion * early return * simplify if statements * simplify pr * pr requested changes * better docstring --------- Co-authored-by: Andriy Kushnir <me@orhideous.name>
- Loading branch information
1 parent
ad6e6a1
commit b684801
Showing
4 changed files
with
98 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Helper methods for Tado.""" | ||
|
||
from . import TadoConnector | ||
from .const import ( | ||
CONST_OVERLAY_TADO_DEFAULT, | ||
CONST_OVERLAY_TADO_MODE, | ||
CONST_OVERLAY_TIMER, | ||
) | ||
|
||
|
||
def decide_overlay_mode( | ||
tado: TadoConnector, | ||
duration: int | None, | ||
zone_id: int, | ||
overlay_mode: str | None = None, | ||
) -> str: | ||
"""Return correct overlay mode based on the action and defaults.""" | ||
# If user gave duration then overlay mode needs to be timer | ||
if duration: | ||
return CONST_OVERLAY_TIMER | ||
# If no duration or timer set to fallback setting | ||
if overlay_mode is None: | ||
overlay_mode = tado.fallback or CONST_OVERLAY_TADO_MODE | ||
# If default is Tado default then look it up | ||
if overlay_mode == CONST_OVERLAY_TADO_DEFAULT: | ||
overlay_mode = ( | ||
tado.data["zone"][zone_id].default_overlay_termination_type | ||
or CONST_OVERLAY_TADO_MODE | ||
) | ||
|
||
return overlay_mode |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
"""Helper method tests.""" | ||
|
||
from unittest.mock import patch | ||
|
||
from homeassistant.components.tado import TadoConnector | ||
from homeassistant.components.tado.const import ( | ||
CONST_OVERLAY_MANUAL, | ||
CONST_OVERLAY_TADO_DEFAULT, | ||
CONST_OVERLAY_TADO_MODE, | ||
CONST_OVERLAY_TIMER, | ||
) | ||
from homeassistant.components.tado.helper import decide_overlay_mode | ||
from homeassistant.core import HomeAssistant | ||
|
||
|
||
def dummy_tado_connector(hass: HomeAssistant, fallback) -> TadoConnector: | ||
"""Return dummy tado connector.""" | ||
return TadoConnector(hass, username="dummy", password="dummy", fallback=fallback) | ||
|
||
|
||
async def test_overlay_mode_duration_set(hass: HomeAssistant) -> None: | ||
"""Test overlay method selection when duration is set.""" | ||
tado = dummy_tado_connector(hass=hass, fallback=CONST_OVERLAY_TADO_MODE) | ||
overlay_mode = decide_overlay_mode(tado=tado, duration="01:00:00", zone_id=1) | ||
# Must select TIMER overlay | ||
assert overlay_mode == CONST_OVERLAY_TIMER | ||
|
||
|
||
async def test_overlay_mode_next_time_block_fallback(hass: HomeAssistant) -> None: | ||
"""Test overlay method selection when duration is not set.""" | ||
integration_fallback = CONST_OVERLAY_TADO_MODE | ||
tado = dummy_tado_connector(hass=hass, fallback=integration_fallback) | ||
overlay_mode = decide_overlay_mode(tado=tado, duration=None, zone_id=1) | ||
# Must fallback to integration wide setting | ||
assert overlay_mode == integration_fallback | ||
|
||
|
||
async def test_overlay_mode_tado_default_fallback(hass: HomeAssistant) -> None: | ||
"""Test overlay method selection when tado default is selected.""" | ||
integration_fallback = CONST_OVERLAY_TADO_DEFAULT | ||
zone_fallback = CONST_OVERLAY_MANUAL | ||
tado = dummy_tado_connector(hass=hass, fallback=integration_fallback) | ||
|
||
class MockZoneData: | ||
def __init__(self) -> None: | ||
self.default_overlay_termination_type = zone_fallback | ||
|
||
zone_id = 1 | ||
|
||
zone_data = {"zone": {zone_id: MockZoneData()}} | ||
with patch.dict(tado.data, zone_data): | ||
overlay_mode = decide_overlay_mode(tado=tado, duration=None, zone_id=zone_id) | ||
# Must fallback to zone setting | ||
assert overlay_mode == zone_fallback |