Skip to content

Commit

Permalink
Switch to using Colour Enum for led interface
Browse files Browse the repository at this point in the history
  • Loading branch information
WillB97 committed Jul 10, 2024
1 parent f3cfc87 commit b638985
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions sbot/leds.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,14 @@ def __init__(self, led: RGBled) -> None:
self._led = led

@property
def colour(self) -> tuple[bool, bool, bool]:
def colour(self) -> Colour:
"""Get the colour of the user LED."""
return False, False, False
return Colour.OFF

@colour.setter
def colour(self, value: tuple[bool, bool, bool]) -> None:
def colour(self, value: Colour) -> None:
"""Set the colour of the user LED."""
if not isinstance(value, (tuple, list)) or len(value) != 3:
raise ValueError("The LED requires 3 values for its colour")
pass


class PhysicalLED(LED):
Expand All @@ -188,24 +187,21 @@ def __init__(self, led: RGBled) -> None:
self._led = led

@property
def colour(self) -> tuple[bool, bool, bool]:
def colour(self) -> Colour:
"""Get the colour of the user LED."""
return (
return Colour(
GPIO.input(self._led.red),
GPIO.input(self._led.green),
GPIO.input(self._led.blue),
)

@colour.setter
def colour(self, value: tuple[bool, bool, bool]) -> None:
def colour(self, value: Colour) -> None:
"""Set the colour of the user LED."""
if not isinstance(value, (tuple, list)) or len(value) != 3:
raise ValueError("The LED requires 3 values for its colour")

GPIO.output(
self._led,
tuple(
GPIO.HIGH if v else GPIO.LOW for v in value
GPIO.HIGH if v else GPIO.LOW for v in value.value
),
)

Expand Down Expand Up @@ -313,21 +309,18 @@ def __init__(self, led_num: int, server: LedServer) -> None:
self._server = server

@property
def colour(self) -> tuple[bool, bool, bool]:
def colour(self) -> Colour:
"""Get the colour of the user LED."""
return self._server.get_leds(self._led_num)
return Colour(self._server.get_leds(self._led_num))

@colour.setter
def colour(self, value: tuple[bool, bool, bool]) -> None:
def colour(self, value: Colour) -> None:
"""Set the colour of the user LED."""
if not isinstance(value, (tuple, list)) or len(value) != 3:
raise ValueError("The LED requires 3 values for its colour")

self._server.set_leds(
self._led_num,
(
bool(value[0]),
bool(value[1]),
bool(value[2]),
bool(value.value[0]),
bool(value.value[1]),
bool(value.value[2]),
)
)

0 comments on commit b638985

Please sign in to comment.