Skip to content

Commit

Permalink
pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
attdona committed Oct 5, 2017
1 parent ba65058 commit f3131b4
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions commands/led.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@


"""Custom command for managing on/off objects like leds
"""
RED_BIT = 0
YELLOW_BIT = 1
GREEN_BIT =2
GREEN_BIT = 2


class Leds:
"""An array of leds: red, green and yellow
"""

RED = 1 << RED_BIT
RED = 1 << RED_BIT
YELLOW = 1 << YELLOW_BIT
GREEN = 1 << GREEN_BIT
GREEN = 1 << GREEN_BIT

def __init__(self, red=None, green=None, yellow=None):
self.red = red
Expand All @@ -24,19 +26,24 @@ def set_status(self, values):
self.green = 'on' if (values & Leds.GREEN) else 'off'

def set_protobuf(self, obj):
"""Encode the object into a protobuf binary array
"""
obj.id = 1

mask = 0
values = 0

for (led, attr) in ((Leds.RED, self.red), (Leds.YELLOW, self.yellow), (Leds.GREEN, self.green)):
for (led, attr) in (
(Leds.RED, self.red),
(Leds.YELLOW, self.yellow),
(Leds.GREEN, self.green)):
if attr:
mask |= led
values |= led if attr=='on' else 0
values |= led if attr == 'on' else 0

# set the mash/values only if ther is at least one led switch request
# if ther are no switch requests interprets the command as a get led
# states request
# states request
if mask:
obj.ivals.append(mask)
obj.ivals.append(values)
Expand All @@ -45,11 +52,10 @@ def build_from_protobuf(self, obj):
"""used by software simulation of physical board
"""
self.id = obj.id

if len(obj.ivals) == 2:
mask = obj.ivals[0]
values = obj.ivals[1]

if mask & Leds.RED:
self.red = 'on' if (values & Leds.RED) else 'off'
if mask & Leds.YELLOW:
Expand All @@ -58,6 +64,3 @@ def build_from_protobuf(self, obj):
self.green = 'on' if (values & Leds.GREEN) else 'off'

return self



0 comments on commit f3131b4

Please sign in to comment.