Skip to content

Commit 3877382

Browse files
authored
changed asserts into raised exceptions
did some pylint beautifications
1 parent 162df6c commit 3877382

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

adafruit_tlc5947.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def duty_cycle(self):
104104

105105
@duty_cycle.setter
106106
def duty_cycle(self, val):
107-
if (0 > val) or (65535 < val):
107+
if (val < 0) or (val > 65535):
108108
raise ValueError("PWM intensity {0} outside supported range [0;65535]".format(val))
109109
# Convert to 12-bit value (quantization error will occur!).
110110
val = (val >> 4) & 0xFFF
@@ -129,7 +129,7 @@ def frequency(self, val):
129129

130130

131131
def __init__(self, spi, latch, *, auto_write=True, num_drivers=1):
132-
if (1 > num_drivers):
132+
if num_drivers < 1:
133133
raise ValueError("need at least one driver; {0} is not supported.".format(num_drivers))
134134
self._spi = spi
135135
self._latch = latch
@@ -168,8 +168,9 @@ def write(self):
168168
def _get_gs_value(self, channel):
169169
# pylint: disable=no-else-return
170170
# Disable should be removed when refactor can be tested
171-
if (0 > channel) or (_CHANNELS * self._n <= channel):
172-
raise ValueError("channel {0} not available with {1} board(s).".format(channel, self._n))
171+
if (channel < 0) or (channel >= _CHANNELS * self._n):
172+
raise ValueError(
173+
"channel {0} not available with {1} board(s).".format(channel, self._n))
173174
# Invert channel position as the last channel needs to be written first.
174175
# I.e. is in the first position of the shift registr.
175176
channel = _CHANNELS * self._n - 1 - channel
@@ -194,9 +195,10 @@ def _get_gs_value(self, channel):
194195
raise RuntimeError('Unsupported bit offset!')
195196

196197
def _set_gs_value(self, channel, val):
197-
if (0 > channel) or (_CHANNELS * self._n <= channel):
198-
raise ValueError("channel {0} not available with {1} board(s).".format(channel, self._n))
199-
if (0 > val) or (4095 < val):
198+
if (channel < 0) or (channel >= _CHANNELS * self._n):
199+
raise ValueError(
200+
"channel {0} not available with {1} board(s).".format(channel, self._n))
201+
if (val < 0) or (val > 4095):
200202
raise ValueError("PWM intensity {0} outside supported range [0;4095]".format(val))
201203

202204
# Invert channel position as the last channel needs to be written first.

0 commit comments

Comments
 (0)