diff --git a/shellhub/__init__.py b/shellhub/__init__.py index 0d63d72..0222d04 100644 --- a/shellhub/__init__.py +++ b/shellhub/__init__.py @@ -1,5 +1,5 @@ # Increment versions here according to SemVer -__version__ = "0.1.0" +__version__ = "0.2.0" from .models.device import ShellHubDevice, ShellHubDeviceInfo from .models.base import ShellHub diff --git a/shellhub/models/device.py b/shellhub/models/device.py index f7c49e1..04d2ef5 100644 --- a/shellhub/models/device.py +++ b/shellhub/models/device.py @@ -135,6 +135,12 @@ def refresh(self) -> None: except requests.exceptions.HTTPError as e: raise ShellHubApiError(e) + @property + def sshid(self) -> Optional[str]: + if self.acceptable: + return None + return f"{self.namespace}.{self.name}@{self._api._endpoint}" + def __repr__(self) -> str: return ( f"ShellHubDevice(name={self.name}, online={self.online}, namespace={self.namespace}, status={self.status})" diff --git a/tests/test_devices.py b/tests/test_devices.py index 0b793c4..1328866 100644 --- a/tests/test_devices.py +++ b/tests/test_devices.py @@ -260,3 +260,12 @@ def test_accept_device(self, shellhub_device, requests_mock): shellhub_device.accept() assert not shellhub_device.acceptable + + +class TestDeviceSSHID: + def test_get_sshid(self, shellhub_device, shellhub): + assert shellhub_device.sshid == f"{shellhub_device.namespace}.{shellhub_device.name}@{shellhub._endpoint}" + + def test_acceptable_device_sshid(self, shellhub_device, shellhub): + shellhub_device.acceptable = True + assert shellhub_device.sshid is None