From a3f3ea4e2529e3c7de253197b188b10813030aeb Mon Sep 17 00:00:00 2001 From: Jon Gilmore <7232986+JonGilmore@users.noreply.github.com> Date: Wed, 23 Oct 2019 11:29:30 -0500 Subject: [PATCH] Fix Lutron Pico (#27059) * removed a nesting level * Lutron Pico fix * Reverted logging change Was unaware that f-strings aren't used in logging commands, reverted the usage * Reverted logging change Was unaware that f-strings aren't used in logging commands, reverted the usage * fixed logic --- homeassistant/components/lutron/__init__.py | 25 +++++++++++---------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/lutron/__init__.py b/homeassistant/components/lutron/__init__.py index de3ca40fd1d..09ab0fc747b 100644 --- a/homeassistant/components/lutron/__init__.py +++ b/homeassistant/components/lutron/__init__.py @@ -68,18 +68,19 @@ def setup(hass, base_config): hass.data[LUTRON_DEVICES]["switch"].append((area.name, output)) for keypad in area.keypads: for button in keypad.buttons: - # This is the best way to determine if a button does anything - # useful until pylutron is updated to provide information on - # which buttons actually control scenes. - for led in keypad.leds: - if ( - led.number == button.number - and button.name != "Unknown Button" - and button.button_type in ("SingleAction", "Toggle") - ): - hass.data[LUTRON_DEVICES]["scene"].append( - (area.name, keypad.name, button, led) - ) + # If the button has a function assigned to it, add it as a scene + if button.name != "Unknown Button" and button.button_type in ( + "SingleAction", + "Toggle", + ): + # Associate an LED with a button if there is one + led = next( + (led for led in keypad.leds if led.number == button.number), + None, + ) + hass.data[LUTRON_DEVICES]["scene"].append( + (area.name, keypad.name, button, led) + ) hass.data[LUTRON_BUTTONS].append(LutronButton(hass, keypad, button)) if area.occupancy_group is not None: