Skip to content

added __getitem__ for iterable behavior #5

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 3 commits into from
Mar 18, 2019
Merged
Changes from all commits
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
30 changes: 30 additions & 0 deletions adafruit_fancyled/adafruit_fancyled.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ def __repr__(self):
def __str__(self):
return "(%s, %s, %s)" % (self.red, self.green, self.blue)

def __len__(self):
"""Retrieve total number of color-parts available."""
return 3

def __getitem__(self, key):
"""Retrieve red, green or blue value as iterable."""
if key == 0:
return self.red
elif key == 1:
return self.green
elif key == 2:
return self.blue
else:
raise IndexError

def pack(self):
"""'Pack' a `CRGB` color into a 24-bit RGB integer.

Expand Down Expand Up @@ -164,6 +179,21 @@ def __repr__(self):
def __str__(self):
return "(%s, %s, %s)" % (self.hue, self.saturation, self.value)

def __len__(self):
"""Retrieve total number of 'color-parts' available."""
return 3

def __getitem__(self, key):
"""Retrieve hue, saturation or value as iterable."""
if key == 0:
return self.hue
elif key == 1:
return self.saturation
elif key == 2:
return self.value
else:
raise IndexError

def pack(self):
"""'Pack' a `CHSV` color into a 24-bit RGB integer.

Expand Down