Skip to content

Commit 261f823

Browse files
committed
Merge pull request gpiozero#338 from lurch/patch-1
Change LEDBoard.leds to return a static tuple
2 parents b581719 + 871c926 commit 261f823

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

gpiozero/boards.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,22 @@ def __init__(self, *args, **kwargs):
116116
LEDClass(pin_or_collection, active_high, initial_value)
117117
for name, pin_or_collection in kwargs.items()
118118
})
119+
leds = []
120+
for item in self:
121+
if isinstance(item, LEDCollection):
122+
for subitem in item.leds:
123+
leds.append(subitem)
124+
else:
125+
leds.append(item)
126+
self._leds = tuple(leds)
119127

120128
@property
121129
def leds(self):
122130
"""
123-
A flat iterator over all LEDs contained in this collection (and all
131+
A flat tuple of all LEDs contained in this collection (and all
124132
sub-collections).
125133
"""
126-
for item in self:
127-
if isinstance(item, LEDCollection):
128-
for subitem in item.leds:
129-
yield subitem
130-
else:
131-
yield item
134+
return self._leds
132135

133136
@property
134137
def active_high(self):

0 commit comments

Comments
 (0)