diff --git a/src/pybricks/_common.py b/src/pybricks/_common.py index 7861dbd..38012db 100644 --- a/src/pybricks/_common.py +++ b/src/pybricks/_common.py @@ -605,28 +605,19 @@ class ColorLight: """ -class LightArray: - """Control an array of single-color lights.""" +class LightArray3: + """Control an array of three single-color lights.""" - def __init__(self, n: int): - """LightArray(n) - - Initializes the light array. - - Arguments: - n (int): Number of lights - """ - - def on(self, brightness: Union[Number, Collection[Number]]) -> None: + def on(self, brightness: Union[Number, Tuple[Number, Number, Number]]) -> None: """on(brightness) Turns on the lights at the specified brightness. Arguments: - brightness (Number or tuple): - Brightness (0--100) of each light, in the order shown above. - If you give just one brightness value, all lights get that - brightness. + brightness (Number or tuple, %): + Use a single value to set the brightness of all lights at the + same time. Use a tuple of three values to set the brightness + of each light individually. """ def off(self) -> None: @@ -635,6 +626,25 @@ class LightArray: Turns off all the lights.""" +class LightArray4(LightArray3): + """Control an array of four single-color lights.""" + + def on( + self, brightness: Union[Number, Tuple[Number, Number, Number, Number]] + ) -> None: + """on(brightness) + + Turns on the lights at the specified brightness. + + Arguments: + brightness (Number or tuple, %): + Use a single value to set the brightness of all lights at the + same time. Use a tuple of four values to set the brightness + of each light individually. The order of the lights is shown + in the image above. + """ + + class LightMatrix: """Control a rectangular grid of single-color lights.""" diff --git a/src/pybricks/pupdevices.py b/src/pybricks/pupdevices.py index 8242653..93c176e 100644 --- a/src/pybricks/pupdevices.py +++ b/src/pybricks/pupdevices.py @@ -203,24 +203,7 @@ class PFMotor(DCMotor): class ColorSensor(_common.AmbientColorSensor): """LEGO® SPIKE Color Sensor.""" - class _LightArray(_common.LightArray): - def __init__(self): - super().__init__(3) - - def on(self, brightness: Union[Number, Tuple[Number, Number, Number]]) -> None: - """on(brightness) - - Turns on the lights at the specified brightness. - - Arguments: - brightness (Number or tuple, %): - A single value will set the brightness of all three lights - to the same value. A tuple of 3 values will set the - brightness of each LED individually. - """ - return super().on(brightness) - - lights = _LightArray() + lights = _common.LightArray3() # HACK: jedi can't find inherited __init__ so docs have to be duplicated def __init__(self, port: Port): @@ -234,26 +217,7 @@ class ColorSensor(_common.AmbientColorSensor): class UltrasonicSensor: """LEGO® SPIKE Color Sensor.""" - class _LightArray(_common.LightArray): - def __init__(self): - super().__init__(4) - - def on( - self, brightness: Union[Number, Tuple[Number, Number, Number, Number]] - ) -> None: - """on(brightness) - - Turns on the lights at the specified brightness. - - Arguments: - brightness (Number or tuple, %): - A single value will set the brightness of all four lights - to the same value. A tuple of 4 values will set the - brightness of each LED individually. - """ - return super().on(brightness) - - lights = _LightArray() + lights = _common.LightArray4() def __init__(self, port: Port): """UltrasonicSensor(port)