Skip to content

Commit

Permalink
feat: check whether the device is online before running
Browse files Browse the repository at this point in the history
  • Loading branch information
codematrixer committed Sep 30, 2024
1 parent 527c0a1 commit afd4e52
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
7 changes: 0 additions & 7 deletions hmdriver2/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class Driver:

def __init__(self, serial: str):
self.serial = serial
if not self._is_device_online():
raise DeviceNotFoundError(f"Device [{self.serial}] not found")

self._client = HmClient(self.serial)
self.hdc = self._client.hdc

Expand All @@ -46,10 +43,6 @@ def __del__(self):
def _init_hmclient(self):
self._client.start()

def _is_device_online(self):
_serials = list_devices()
return True if self.serial in _serials else False

def _invoke(self, api: str, args: List = []) -> HypiumResponse:
return self._client.invoke(api, this="Driver#0", args=args)

Expand Down
8 changes: 7 additions & 1 deletion hmdriver2/hdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from . import logger
from .utils import FreePort
from .proto import CommandResult, KeyCode
from .exception import HdcError
from .exception import HdcError, DeviceNotFoundError


def _execute_command(cmdargs: Union[str, List[str]]) -> CommandResult:
Expand Down Expand Up @@ -48,6 +48,12 @@ def list_devices() -> List[str]:
class HdcWrapper:
def __init__(self, serial: str) -> None:
self.serial = serial
if not self.is_online():
raise DeviceNotFoundError(f"Device [{self.serial}] not found")

def is_online(self):
_serials = list_devices()
return True if self.serial in _serials else False

def forward_port(self, rport: int) -> int:
lport: int = FreePort().get()
Expand Down

0 comments on commit afd4e52

Please sign in to comment.