Skip to content

Commit

Permalink
Add NPSClient.all_off() to turn off all outlets
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 24, 2023
1 parent 225403c commit 733a8fd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions src/lvmnps/nps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_nps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from __future__ import annotations

import pytest
from pytest_mock import MockerFixture

from lvmnps.nps.core import NPSClient, OutletModel

Expand Down Expand Up @@ -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)

0 comments on commit 733a8fd

Please sign in to comment.