Skip to content

Commit c65d526

Browse files
Clean up some pylint complaints (still WIP)
1 parent 9af3fdf commit c65d526

File tree

1 file changed

+24
-46
lines changed

1 file changed

+24
-46
lines changed

adafruit_fancyled.py

Lines changed: 24 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@
3636
from math import floor
3737

3838

39-
"""
40-
FancyLED provides color- and palette-related utilities for LED projects,
41-
offering a buttery smooth look instead of the usual 8-bit-like "blip blip"
42-
effects often seen with LEDs. It's loosely inspired by, but NOT a drop-in
43-
replacement for, the FastLED library for Arduino.
44-
"""
39+
# FancyLED provides color- and palette-related utilities for LED projects,
40+
# offering a buttery smooth look instead of the usual 8-bit-like "blip blip"
41+
# effects often seen with LEDs. It's loosely inspired by, but NOT a drop-in
42+
# replacement for, the FastLED library for Arduino.
4543

4644

47-
class CRGB:
45+
class CRGB(object):
4846
""" RGB (red, green, blue) color class.
4947
"""
5048

@@ -67,9 +65,9 @@ def __init__(self, red, green=0.0, blue=0.0):
6765
# If first/only argument is a CHSV type, perform HSV to RGB
6866
# conversion.
6967
hsv = red # 'red' is CHSV, this is just more readable
70-
h = hsv.hue * 6.0 # Hue circle = 0.0 to 6.0
71-
sxt = floor(h) # Sextant index is next-lower integer of hue
72-
frac = h - sxt # Fraction-within-sextant is 0.0 to <1.0
68+
hue = hsv.hue * 6.0 # Hue circle = 0.0 to 6.0
69+
sxt = floor(hue) # Sextant index is next-lower integer of hue
70+
frac = hue - sxt # Fraction-within-sextant is 0.0 to <1.0
7371
sxt = int(sxt) % 6 # mod6 the sextant so it's always 0 to 5
7472

7573
if sxt == 0: # Red to <yellow
@@ -112,7 +110,7 @@ def __str__(self):
112110
return "(%s, %s, %s)" % (self.red, self.green, self.blue)
113111

114112

115-
class CHSV:
113+
class CHSV(object):
116114
""" HSV (hue, saturation, value) color class.
117115
"""
118116

@@ -220,7 +218,7 @@ def pack(val):
220218

221219
# Convert CHSV input to CRGB if needed
222220
if isinstance(val, CHSV):
223-
val = CRGB(val)
221+
val = CRGB(val)
224222

225223
return ((denormalize(val.red) << 16) |
226224
(denormalize(val.green) << 8) |
@@ -323,7 +321,7 @@ def gamma_adjust(val, gamma_value=None, brightness=1.0, inplace=False):
323321
gamma_value = GFACTOR
324322
return pow(val, gamma_value) * brightness
325323

326-
if isinstance(val, list) or isinstance(val, tuple):
324+
if isinstance(val, (list, tuple)):
327325
# List or tuple of values
328326
if isinstance(val[0], float):
329327
# Input appears to be a list of floats
@@ -341,27 +339,17 @@ def gamma_adjust(val, gamma_value=None, brightness=1.0, inplace=False):
341339
# but first determine gamma-correction factors for R,G,B:
342340
if gamma_value is None:
343341
# No gamma specified, use default
344-
gamma_red = GFACTOR
345-
gamma_green = GFACTOR
346-
gamma_blue = GFACTOR
342+
gamma_red, gamma_green, gamma_blue = GFACTOR, GFACTOR, GFACTOR
347343
elif isinstance(gamma_value, float):
348344
# Single gamma value provided, apply to R,G,B
349-
gamma_red = gamma_value
350-
gamma_green = gamma_value
351-
gamma_blue = gamma_value
345+
gamma_red, gamma_green, gamma_blue = gamma_value, gamma_value, gamma_value
352346
else:
353-
gamma_red = gamma_value[0]
354-
gamma_green = gamma_value[1]
355-
gamma_blue = gamma_value[2]
347+
gamma_red, gamma_green, gamma_blue = gamma_value[0], gamma_value[1], gamma_value[2]
356348
if isinstance(brightness, float):
357349
# Single brightness value provided, apply to R,G,B
358-
brightness_red = brightness
359-
brightness_green = brightness
360-
brightness_blue = brightness
350+
brightness_red, brightness_green, brightness_blue = brightness, brightness, brightness
361351
else:
362-
brightness_red = brightness[0]
363-
brightness_green = brightness[1]
364-
brightness_blue = brightness[2]
352+
brightness_red, brightness_green, brightness_blue = brightness[0], brightness[1], brightness[2]
365353
if inplace:
366354
for i, x in enumerate(val):
367355
if isinstance(x, CHSV):
@@ -382,27 +370,17 @@ def gamma_adjust(val, gamma_value=None, brightness=1.0, inplace=False):
382370
# Single CRGB or CHSV value
383371
if gamma_value is None:
384372
# No gamma specified, use default
385-
gamma_red = GFACTOR
386-
gamma_green = GFACTOR
387-
gamma_blue = GFACTOR
373+
gamma_red, gamma_green, gamma_blue = GFACTOR, GFACTOR, GFACTOR
388374
elif isinstance(gamma_value, float):
389375
# Single gamma value provided, apply to R,G,B
390-
gamma_red = gamma_value
391-
gamma_green = gamma_value
392-
gamma_blue = gamma_value
376+
gamma_red, gamma_green, gamma_blue = gamma_value, gamma_value, gamma_value
393377
else:
394-
gamma_red = gamma_value[0]
395-
gamma_green = gamma_value[1]
396-
gamma_blue = gamma_value[2]
378+
gamma_red, gamma_green, gamma_blue = gamma_value[0], gamma_value[1], gamma_value[2]
397379
if isinstance(brightness, float):
398380
# Single brightness value provided, apply to R,G,B
399-
brightness_red = brightness
400-
brightness_green = brightness
401-
brightness_blue = brightness
381+
brightness_red, brightness_green, brightness_blue = brightness, brightness, brightness
402382
else:
403-
brightness_red = brightness[0]
404-
brightness_green = brightness[1]
405-
brightness_blue = brightness[2]
383+
brightness_red, brightness_green, brightness_blue = brightness[0], brightness[1], brightness[2]
406384

407385
if isinstance(val, CHSV):
408386
val = CRGB(val)
@@ -432,7 +410,7 @@ def palette_lookup(pal, pos):
432410
return mix(color1, color2, weight2)
433411

434412

435-
def expand_gradient(grad, len):
413+
def expand_gradient(grad, length):
436414
""" Convert gradient palette into standard equal-interval palette.
437415
ACCEPTS: List or tuple of of 2-element lists/tuples containing position
438416
(0.0 to 1.0) and color (packed int, CRGB or CHSV). It's OK if
@@ -446,8 +424,8 @@ def expand_gradient(grad, len):
446424
most = grad[-1][0] # Highest position value (ostensibly 1.0)
447425
newlist = []
448426

449-
for i in range(len):
450-
pos = i / float(len - 1) # 0.0 to 1.0 in 'len' steps
427+
for i in range(length):
428+
pos = i / float(length - 1) # 0.0 to 1.0 in 'length' steps
451429
# Determine indices in list of item 'below' and 'above' pos
452430
if pos <= least:
453431
# Off bottom of list - use lowest index

0 commit comments

Comments
 (0)