forked from chrism0dwk/PyTado
-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from chiefdragon/enable-auto-geofencing
Add setAuto() to enable auto geofencing with checks and tests
- Loading branch information
Showing
8 changed files
with
155 additions
and
5 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,10 @@ | ||
"""Tado exceptions.""" | ||
|
||
|
||
class TadoException(Exception): | ||
"""Base exception class for Tado.""" | ||
|
||
|
||
class TadoNotSupportedException(TadoException): | ||
"""Exception to indicate a requested action is not supported by Tado.""" | ||
|
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
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,4 @@ | ||
{ | ||
"presence": "HOME", | ||
"presenceLocked": true | ||
} |
4 changes: 4 additions & 0 deletions
4
tests/fixtures/tadov2.home_state.auto_supported.auto_mode.json
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,4 @@ | ||
{ | ||
"presence": "HOME", | ||
"presenceLocked": false | ||
} |
5 changes: 5 additions & 0 deletions
5
tests/fixtures/tadov2.home_state.auto_supported.manual_mode.json
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,5 @@ | ||
{ | ||
"presence": "HOME", | ||
"presenceLocked": true, | ||
"showSwitchToAutoGeofencingButton": true | ||
} |
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,80 @@ | ||
"""Test the Tado object.""" | ||
|
||
import os | ||
import json | ||
from unittest.mock import patch | ||
|
||
from PyTado.interface import Tado | ||
|
||
|
||
def load_fixture(filename): | ||
"""Load a fixture.""" | ||
path = os.path.join(os.path.dirname(__file__), "fixtures", filename) | ||
with open(path) as fptr: | ||
return fptr.read() | ||
|
||
|
||
def mock_tado(): | ||
"""Mock out a Tado object.""" | ||
with patch("PyTado.interface.Tado._loginV2"), patch( | ||
"PyTado.interface.Tado.getMe" | ||
): | ||
tado = Tado("[email protected]", "mypassword") | ||
return tado | ||
|
||
|
||
def test_home_can_be_set_to_auto_when_home_supports_geofencing_and_home_set_to_manual_mode(): | ||
"""Test that the Tado home can be set to auto geofencing mode when it is supported and currently in manual mode.""" | ||
tado = mock_tado() | ||
with patch("PyTado.interface.Tado._apiCall", | ||
return_value=json.loads(load_fixture("tadov2.home_state.auto_supported.manual_mode.json")), | ||
): | ||
tado.getHomeState() | ||
|
||
with patch("PyTado.interface.Tado._apiCall"): | ||
raised = False | ||
try: | ||
tado.setAuto() | ||
except: | ||
raised = True | ||
|
||
# An exception should NOT have been raised because geofencing is supported | ||
assert raised is False | ||
|
||
|
||
def test_home_remains_set_to_auto_when_home_supports_geofencing_and_home_already_set_to_auto_mode(): | ||
"""Test that the Tado home remains set to auto geofencing mode when it is supported, and already in auto mode.""" | ||
tado = mock_tado() | ||
with patch("PyTado.interface.Tado._apiCall", | ||
return_value=json.loads(load_fixture("tadov2.home_state.auto_supported.auto_mode.json")), | ||
): | ||
tado.getHomeState() | ||
|
||
with patch("PyTado.interface.Tado._apiCall"): | ||
raised = False | ||
try: | ||
tado.setAuto() | ||
except: | ||
raised = True | ||
|
||
# An exception should NOT have been raised because geofencing is supported | ||
assert raised is False | ||
|
||
|
||
def test_home_cant_be_set_to_auto_when_home_does_not_support_geofencing(): | ||
"""Test that the Tado home can't be set to auto geofencing mode when it is not supported.""" | ||
tado = mock_tado() | ||
with patch("PyTado.interface.Tado._apiCall", | ||
return_value=json.loads(load_fixture("tadov2.home_state.auto_not_supported.json")), | ||
): | ||
tado.getHomeState() | ||
|
||
with patch("PyTado.interface.Tado._apiCall"): | ||
raised = False | ||
try: | ||
tado.setAuto() | ||
except: | ||
raised = True | ||
|
||
# An exception should have been raised because geofencing is NOT supported | ||
assert raised is True |