Skip to content

Commit

Permalink
Tidy up ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Jan 4, 2025
1 parent edf63f1 commit 7d23c2c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
9 changes: 5 additions & 4 deletions sbot/future/classless/motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,11 @@ def _find_output(self, id: int) -> BoardIdentifier:
raise ValueError(f"Output {id} does not exist")

def _get_boards(self) -> list[SerialWrapper]:
return sorted(
set(output.port for output in self._outputs),
key=lambda x: x.identity.asset_tag,
)
unique_boards = []
for output in self._outputs:
if output.port not in unique_boards:
unique_boards.append(output.port)
return unique_boards

def __repr__(self) -> str:
board_ports = self._get_boards()
Expand Down
9 changes: 5 additions & 4 deletions sbot/future/classless/servos.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,11 @@ def _find_output(self, id: int) -> BoardIdentifier:
raise ValueError(f"Output {id} does not exist")

def _get_boards(self) -> list[SerialWrapper]:
return sorted(
set(output.port for output in self._outputs),
key=lambda x: x.identity.asset_tag,
)
unique_boards = []
for output in self._outputs:
if output.port not in unique_boards:
unique_boards.append(output.port)
return unique_boards

def __repr__(self) -> str:
board_ports = self._get_boards()
Expand Down
11 changes: 11 additions & 0 deletions sbot/serial_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,14 @@ def __str__(self) -> str:
return (
f"<{self.__class__.__qualname__} {self.serial.port!r} {self.identity.asset_tag!r}>"
)

def __lt__(self, other: SerialWrapper) -> bool:
return self.identity.asset_tag.lower() < other.identity.asset_tag.lower()

def __eq__(self, other: object) -> bool:
if not isinstance(other, SerialWrapper):
return False
if self.identity.asset_tag != "":
return self.identity.asset_tag == other.identity.asset_tag
else:
return self.serial.port == other.serial.port

0 comments on commit 7d23c2c

Please sign in to comment.