Skip to content

Commit

Permalink
Add NPSClient.get()
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Nov 23, 2023
1 parent 539d07b commit 7efc79f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 10 additions & 0 deletions src/lvmnps/nps/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ async def refresh(self):

pass

def get(self, outlet: int | str):
"""Retrieves an outlet by ID or name."""

if isinstance(outlet, int):
return get_outlet_by_id(self.outlets, outlet)
elif isinstance(outlet, str):
return get_outlet_by_name(self.outlets, outlet)
else:
raise TypeError("Invalid outlet type. Only int and str are allowed.")

async def set_state(
self,
outlets: OutletArgType,
Expand Down
12 changes: 11 additions & 1 deletion tests/test_nps.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import pytest

from lvmnps.nps.core import NPSClient
from lvmnps.nps.core import NPSClient, OutletModel


async def test_npsclient(nps_test_client: NPSClient):
Expand Down Expand Up @@ -69,3 +69,13 @@ async def test_outlet_cycle(nps_test_client: NPSClient):
await nps_test_client.cycle(outlet, delay=0.1)

assert outlet.state is True


@pytest.mark.parametrize("outlet", [1, "test_1"])
async def test_client_get(nps_test_client: NPSClient, outlet: str | int):
assert isinstance(nps_test_client.get(outlet), OutletModel)


async def test_client_get_invalid_type(nps_test_client: NPSClient):
with pytest.raises(TypeError):
nps_test_client.get(None) # type: ignore

0 comments on commit 7efc79f

Please sign in to comment.