From 871c9268b204bcdc695c2b1a0b87d2a6d27e3f97 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Sat, 28 May 2016 10:42:49 +0100 Subject: [PATCH] Change LEDBoard.leds to return a static tuple fixes #337 --- gpiozero/boards.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gpiozero/boards.py b/gpiozero/boards.py index 192fda3..83fa3d2 100644 --- a/gpiozero/boards.py +++ b/gpiozero/boards.py @@ -116,19 +116,22 @@ class LEDCollection(CompositeOutputDevice): LEDClass(pin_or_collection, active_high, initial_value) for name, pin_or_collection in kwargs.items() }) + leds = [] + for item in self: + if isinstance(item, LEDCollection): + for subitem in item.leds: + leds.append(subitem) + else: + leds.append(item) + self._leds = tuple(leds) @property def leds(self): """ - A flat iterator over all LEDs contained in this collection (and all + A flat tuple of all LEDs contained in this collection (and all sub-collections). """ - for item in self: - if isinstance(item, LEDCollection): - for subitem in item.leds: - yield subitem - else: - yield item + return self._leds @property def active_high(self):