Skip to content

Commit

Permalink
Merge pull request #13 from tradel/get-devices-param
Browse files Browse the repository at this point in the history
Handle generic_type param as a list instead of str
  • Loading branch information
jaraco authored Jan 5, 2023
2 parents 8263b96 + 45e0668 commit 3a227b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v3.1.1
======

#12: Restore support for ``Client.get_devices(generic_type)`` as an
iterable.

v3.1.0
======

Expand Down
7 changes: 6 additions & 1 deletion jaraco/abode/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from jaraco.net.http import cookies
from jaraco.functools import retry
from jaraco.itertools import always_iterable
from jaraco.collections import Everything

import jaraco
from .automation import Automation
Expand Down Expand Up @@ -159,10 +160,14 @@ def get_devices(self, refresh=False, generic_type=None):
if refresh or self._devices is None:
self._load_devices()

spec_types = (
Everything() if generic_type is None else set(always_iterable(generic_type))
)

return [
device
for device in self._devices.values()
if not generic_type or device.generic_type in generic_type
if device.generic_type in spec_types
]

def _load_devices(self):
Expand Down
7 changes: 6 additions & 1 deletion tests/test_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,12 @@ def test_get_devices_generic_type_substring(self, all_devices):
"""
assert not self.client.get_devices(generic_type='nect')

def test_get_devices_generic_type_superstring(self, all_devices):
"""
Test that a generic_type superstring does not match in get_devices.
"""
assert not self.client.get_devices(generic_type='connectivity-king')

def test_get_devices_generic_type_simple_string(self, all_devices):
"""
Test that a generic_type selects on a simple string.
Expand All @@ -428,7 +434,6 @@ def test_get_devices_generic_type_simple_string(self, all_devices):
assert selected
assert len(selected) < len(all)

@pytest.mark.xfail(reason="#12")
def test_get_devices_generic_type_list(self, all_devices):
"""
Test that a generic_type can select a list of types.
Expand Down

0 comments on commit 3a227b6

Please sign in to comment.