From 4a764ae1e388ab713f25c5b982653a004d292a65 Mon Sep 17 00:00:00 2001 From: Jonathan Swoboda <154711427+swoboda1337@users.noreply.github.com> Date: Wed, 8 Apr 2026 15:42:47 -0400 Subject: [PATCH] [spi] Fix IndexError on invalid RP2040 CLK pin (#15562) --- esphome/components/spi/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/esphome/components/spi/__init__.py b/esphome/components/spi/__init__.py index 931882be8d1..33ccfbb5ee8 100644 --- a/esphome/components/spi/__init__.py +++ b/esphome/components/spi/__init__.py @@ -246,11 +246,15 @@ def validate_hw_pins(spi, index=-1): return clk_pin_no >= 0 if target_platform == PLATFORM_RP2040: - pin_set = ( - list(filter(lambda s: clk_pin_no in s[CONF_CLK_PIN], RP_SPI_PINSETS))[0] - if index == -1 - else RP_SPI_PINSETS[index] - ) + if index == -1: + matches = list( + filter(lambda s: clk_pin_no in s[CONF_CLK_PIN], RP_SPI_PINSETS) + ) + if not matches: + return False + pin_set = matches[0] + else: + pin_set = RP_SPI_PINSETS[index] if pin_set is None: return False if sdo_pin_no not in pin_set[CONF_MOSI_PIN]: