diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c8e4cd..27cca0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## Next version + +### ✨ Improved + +* Added `NPSClient.all_off()` to turn off all outlets at once. + + ## 1.0.0 - November 24, 2023 ### 🔥 Breaking changes diff --git a/src/lvmnps/nps/core.py b/src/lvmnps/nps/core.py index 3e72441..1f98d11 100644 --- a/src/lvmnps/nps/core.py +++ b/src/lvmnps/nps/core.py @@ -195,6 +195,13 @@ async def _set_state_internal( """ + pass + + async def all_off(self): + """Turns off all outlets.""" + + await self._set_state_internal(list(self.outlets.values()), on=False) + async def cycle( self, outlets: OutletArgType, diff --git a/tests/test_nps.py b/tests/test_nps.py index 0a5b1ec..8c62b94 100644 --- a/tests/test_nps.py +++ b/tests/test_nps.py @@ -9,6 +9,7 @@ from __future__ import annotations import pytest +from pytest_mock import MockerFixture from lvmnps.nps.core import NPSClient, OutletModel @@ -79,3 +80,14 @@ async def test_client_get(nps_test_client: NPSClient, outlet: str | int): async def test_client_get_invalid_type(nps_test_client: NPSClient): with pytest.raises(TypeError): nps_test_client.get(None) # type: ignore + + +async def test_all_off(nps_test_client: NPSClient, mocker: MockerFixture): + assert nps_test_client is not None + + nps_test_client._set_state_internal = mocker.AsyncMock() + + await nps_test_client.all_off() + + outlets = list(nps_test_client.outlets.values()) + nps_test_client._set_state_internal.assert_called_once_with(outlets, on=False)