Skip to content

Docstrings updating #143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Apr 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint matrix.py
  • Loading branch information
chrisruk committed Apr 22, 2022
commit 1383f4b0aab1e73b98e356aeb1c98d85c7342a55
25 changes: 21 additions & 4 deletions buildhat/matrix.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Matrix device handling functionality"""

from .devices import Device
from .exc import MatrixError

Expand All @@ -8,7 +10,12 @@ class Matrix(Device):
:param port: Port of device
:raises DeviceError: Occurs if there is no LED matrix attached to port
"""

def __init__(self, port):
"""Initialise matrix

:param port: Port of device
"""
super().__init__(port)
self.on()
self.mode(2)
Expand All @@ -17,8 +24,9 @@ def __init__(self, port):
def set_pixels(self, matrix, display=True):
"""Write pixel data to LED matrix

:param pixels: 3x3 list of tuples, with colour (0–10) and brightness (0–10) (see example for more detail)
:param matrix: 3x3 list of tuples, with colour (0–10) and brightness (0–10) (see example for more detail)
:param display: Whether to update matrix or not
:raises MatrixError: Occurs if invalid matrix height/width provided
"""
if len(matrix) != 3:
raise MatrixError("Incorrect matrix height")
Expand Down Expand Up @@ -47,6 +55,7 @@ def strtocolor(colorstr):
:param colorstr: str of a valid color
:return: (0-10) representing the color
:rtype: int
:raises MatrixError: Occurs if invalid color specified
"""
if colorstr == "pink":
return 1
Expand Down Expand Up @@ -79,6 +88,7 @@ def normalize_pixel(pixel):
:param pixel: tuple of colour (0–10) or string (ie:"red") and brightness (0–10)
:return: (color, brightness) integers
:rtype: tuple
:raises MatrixError: Occurs if invalid pixel specified
"""
if isinstance(pixel, tuple):
c, brightness = pixel # pylint: disable=unpacking-non-sequence
Expand All @@ -96,9 +106,10 @@ def normalize_pixel(pixel):

@staticmethod
def validate_coordinate(coord):
""""Validate an x,y coordinate for the 3x3 Matrix
"""Validate an x,y coordinate for the 3x3 Matrix

:param coord: tuple of 0-2 for the X coordinate and 0-2 for the Y coordinate
:raises MatrixError: Occurs if invalid coordinate specified
"""
# pylint: disable=unsubscriptable-object
if isinstance(coord, tuple):
Expand All @@ -122,15 +133,20 @@ def clear(self, pixel=None):
self._output()

def off(self):
# Never send the "off" command to the port a Matrix is connected to
# Instead, just turn all the pixels off
"""Pretends to turn matrix off

Never send the "off" command to the port a Matrix is connected to
Instead, just turn all the pixels off
"""
self.clear()

def level(self, level):
"""Use the matrix as a "level" meter from 0-9

(The level meter is expressed in green which seems to be unchangeable)

:param level: The height of the bar graph, 0-9
:raises MatrixError: Occurs if invalid level specified
"""
if not isinstance(level, int):
raise MatrixError("Invalid level, not integer")
Expand Down Expand Up @@ -165,6 +181,7 @@ def set_transition(self, transition):
fade which will cause the fade to "pop" in brightness.

:param transition: Transition mode (0-2)
:raises MatrixError: Occurs if invalid transition
"""
if not isinstance(transition, int):
raise MatrixError("Invalid transition, not integer")
Expand Down