Skip to content

Commit

Permalink
fix: fix failing climate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Apr 6, 2020
1 parent 4ce4269 commit 8144a3a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion teslajsonpy/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ async def set_preset_mode(self, preset_mode: str) -> None:
wake_if_asleep=True,
)
if data and data["response"]["result"]:
self.__preset_mode = preset_mode
await self.async_update(force=True)
self.__preset_mode = preset_mode

@property
def preset_mode(self) -> Optional[str]:
Expand Down
20 changes: 17 additions & 3 deletions tests/unit_tests/test_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ async def test_set_temperature(monkeypatch):


@pytest.mark.asyncio
async def test_set_preset_mode_no_success(monkeypatch):
"""Test set_temperature()."""
async def test_set_preset_mode_success(monkeypatch):
"""Test set_preset_mode()."""

_mock = TeslaMock(monkeypatch)
_controller = Controller(None)
Expand All @@ -218,8 +218,22 @@ async def test_set_preset_mode_no_success(monkeypatch):
assert _climate.preset_mode is not None
assert _climate.preset_mode == mode


@pytest.mark.asyncio
async def test_set_preset_mode_invalid_modes(monkeypatch):
"""Test set_preset_mode() with invalid modes."""

_mock = TeslaMock(monkeypatch)
_controller = Controller(None)

_data = _mock.data_request_vehicle()
_climate = Climate(_data, _controller)

await _climate.async_update()

preset_modes = _climate.preset_modes
with pytest.raises(UnknownPresetMode):
bad_modes = ["UKNOWN_MODE", "home", "auto", "away", "hot"]
for mode in bad_modes:
assert mode not in preset_modes
await _climate.set_preset_mode("mode")
await _climate.set_preset_mode(mode)

0 comments on commit 8144a3a

Please sign in to comment.