Skip to content
This repository was archived by the owner on Jun 28, 2024. It is now read-only.

Commit 1bd5bdb

Browse files
Add devices.unmanaged.get method, add is_managed and capabilities_supported props to unmanaged device object (#114)
* Add method, add and props to unmanaged device object * Remove duplicate capabilities_supported
1 parent cfc457a commit 1bd5bdb

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

seamapi/devices.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,8 @@ class UnmanagedDevices(AbstractUnmanagedDevices):
295295
296296
Methods
297297
-------
298+
get(device=None, name=None)
299+
Gets an unmanaged device
298300
list(connected_account=None, connected_accounts=None, connect_webview=None, device_type=None, device_ids=None, manufacturer=None)
299301
Gets a list of unmanaged devices
300302
update(device, is_managed)
@@ -313,6 +315,47 @@ def __init__(self, seam: Seam):
313315

314316
self.seam = seam
315317

318+
@report_error
319+
def get(
320+
self,
321+
device: Optional[Union[DeviceId, Device]] = None,
322+
name: Optional[str] = None,
323+
) -> UnmanagedDevice:
324+
"""Gets an unmanaged devices.
325+
326+
Parameters
327+
----------
328+
device : Union[DeviceId, Device], optional
329+
Device ID or Device
330+
name : str, optional
331+
Device name
332+
333+
Raises
334+
------
335+
Exception
336+
If the API request wasn't successful.
337+
338+
Returns
339+
------
340+
An unmanaged device.
341+
"""
342+
343+
params = {}
344+
345+
if device:
346+
params["device_id"] = to_device_id(device)
347+
if name:
348+
params["name"] = name
349+
350+
res = self.seam.make_request(
351+
"GET",
352+
"/devices/unmanaged/get",
353+
params=params,
354+
)
355+
json_device = res["device"]
356+
357+
return UnmanagedDevice.from_dict(json_device)
358+
316359
@report_error
317360
def list(
318361
self,

seamapi/types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class Device:
7373
connected_account_id: str
7474
workspace_id: str
7575
created_at: str
76+
is_managed: bool
7677

7778
@staticmethod
7879
def from_dict(d: Dict[str, Any]):
@@ -87,6 +88,7 @@ def from_dict(d: Dict[str, Any]):
8788
connected_account_id=d["connected_account_id"],
8889
workspace_id=d["workspace_id"],
8990
created_at=d["created_at"],
91+
is_managed=d["is_managed"],
9092
)
9193

9294

@@ -100,6 +102,8 @@ class UnmanagedDevice:
100102
created_at: str
101103
errors: List[Dict[str, Any]]
102104
warnings: List[Dict[str, Any]]
105+
capabilities_supported: List[str]
106+
is_managed: bool
103107

104108
@staticmethod
105109
def from_dict(d: Dict[str, Any]):
@@ -112,6 +116,8 @@ def from_dict(d: Dict[str, Any]):
112116
created_at=d["created_at"],
113117
errors=d["errors"],
114118
warnings=d["warnings"],
119+
capabilities_supported=d["capabilities_supported"],
120+
is_managed=d["is_managed"],
115121
)
116122

117123

@@ -415,6 +421,14 @@ def list_noise_levels(
415421

416422

417423
class AbstractUnmanagedDevices(abc.ABC):
424+
@abc.abstractmethod
425+
def get(
426+
self,
427+
device: Optional[Union[DeviceId, Device]] = None,
428+
name: Optional[str] = None,
429+
) -> UnmanagedDevice:
430+
raise NotImplementedError
431+
418432
@abc.abstractmethod
419433
def list(
420434
self,

tests/devices/test_devices.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ def test_unmanaged_devices(seam: Seam):
8585
unmanaged_devices = seam.devices.unmanaged.list()
8686
assert len(unmanaged_devices) == 1
8787

88+
unmanaged_device = seam.devices.unmanaged.get(device=device)
89+
assert unmanaged_device.device_id == device.device_id
90+
unmanaged_device = seam.devices.unmanaged.get(name=device.properties.name)
91+
assert unmanaged_device.properties.name == device.properties.name
92+
8893
connected_account = seam.connected_accounts.list()[0]
8994
devices = seam.devices.unmanaged.list(connected_account=connected_account)
9095
assert len(devices) > 0

0 commit comments

Comments
 (0)