mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 15:12:06 +00:00 
			
		
		
		
	common
This commit is contained in:
		
							
								
								
									
										136
									
								
								tests/test_build_components/common/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										136
									
								
								tests/test_build_components/common/README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,136 @@ | ||||
| # Common Bus Configurations for Component Tests | ||||
|  | ||||
| This directory contains standardized bus configurations (I2C, SPI, UART, BLE) that component tests use, enabling multiple components to be tested together in Phase 2. | ||||
|  | ||||
| ## Purpose | ||||
|  | ||||
| These common configs allow multiple components to **share a single bus**, dramatically reducing CI time from ~12 hours to ~2-3 hours by compiling multiple compatible components together. | ||||
|  | ||||
| ## Structure | ||||
|  | ||||
| ``` | ||||
| common/ | ||||
| ├── i2c/ | ||||
| │   ├── esp32-idf.yaml | ||||
| │   ├── esp32-ard.yaml | ||||
| │   ├── esp32-c3-idf.yaml | ||||
| │   ├── esp32-c3-ard.yaml | ||||
| │   ├── esp8266-ard.yaml | ||||
| │   └── rp2040-ard.yaml | ||||
| ├── spi/ | ||||
| │   └── esp32-idf.yaml | ||||
| ├── uart/ | ||||
| │   └── esp32-idf.yaml | ||||
| └── ble/ | ||||
|     ├── esp32-idf.yaml | ||||
|     ├── esp32-ard.yaml | ||||
|     └── esp32-c3-idf.yaml | ||||
| ``` | ||||
|  | ||||
| ## How It Works | ||||
|  | ||||
| ### Current State (Phase 1) | ||||
| Each component test includes the common bus config: | ||||
|  | ||||
| ```yaml | ||||
| # tests/components/bh1750/test.esp32-idf.yaml | ||||
| packages: | ||||
|   i2c: !include ../../test_build_components/common/i2c/esp32-idf.yaml | ||||
|  | ||||
| <<: !include common.yaml | ||||
| ``` | ||||
|  | ||||
| The common config provides: | ||||
| - Standardized pin assignments | ||||
| - A shared bus instance (`i2c_bus`, `spi_bus`, etc.) | ||||
|  | ||||
| The component's `common.yaml` just defines the sensor: | ||||
| ```yaml | ||||
| # tests/components/bh1750/common.yaml | ||||
| sensor: | ||||
|   - platform: bh1750 | ||||
|     name: Living Room Brightness | ||||
|     address: 0x23 | ||||
| ``` | ||||
|  | ||||
| The component **auto-detects** the shared bus - no need to specify `i2c_id`. | ||||
|  | ||||
| ### Future State (Phase 2) | ||||
| Create merged test YAMLs combining multiple compatible components: | ||||
|  | ||||
| ```yaml | ||||
| # tests/merged_components/i2c_sensors_group_1.esp32-idf.yaml | ||||
| esphome: | ||||
|   name: test_i2c_group_1 | ||||
|  | ||||
| esp32: | ||||
|   board: nodemcu-32s | ||||
|   framework: | ||||
|     type: esp-idf | ||||
|  | ||||
| packages: | ||||
|   # Shared I2C bus | ||||
|   i2c: !include ../test_build_components/common/i2c/esp32-idf.yaml | ||||
|  | ||||
|   # Multiple components sharing the same bus | ||||
|   component_bme280: !include ../components/bme280_i2c/common.yaml | ||||
|   component_bh1750: !include ../components/bh1750/common.yaml | ||||
|   component_sht3xd: !include ../components/sht3xd/common.yaml | ||||
|   component_ags10: !include ../components/ags10/common.yaml  # Different I2C address | ||||
|   component_aht10: !include ../components/aht10/common.yaml | ||||
| ``` | ||||
|  | ||||
| **Result**: 5 components compile in one test instead of 5 separate tests! | ||||
|  | ||||
| ## Pin Allocations | ||||
|  | ||||
| ### I2C | ||||
| - **ESP32 IDF**: SCL=GPIO16, SDA=GPIO17 | ||||
| - **ESP32 Arduino**: SCL=GPIO22, SDA=GPIO21 | ||||
| - **ESP8266**: SCL=GPIO5, SDA=GPIO4 | ||||
| - **RP2040**: SCL=GPIO5, SDA=GPIO4 | ||||
|  | ||||
| ### SPI | ||||
| - **ESP32 IDF**: CLK=GPIO18, MOSI=GPIO23, MISO=GPIO19 | ||||
| - CS pins are component-specific (each SPI device needs unique CS) | ||||
|  | ||||
| ### UART | ||||
| - **ESP32 IDF**: TX=GPIO17, RX=GPIO16 | ||||
| - Components define unique baud rates as needed | ||||
|  | ||||
| ### BLE | ||||
| - **ESP32**: Shared `esp32_ble_tracker` infrastructure | ||||
| - Each component defines unique `ble_client` with different MAC addresses | ||||
|  | ||||
| ## Benefits | ||||
|  | ||||
| 1. **Shared bus = less duplication** | ||||
|    - 171 I2C components removed duplicate bus definitions | ||||
|    - 59 SPI components removed duplicate bus definitions | ||||
|    - 75 UART components removed duplicate bus definitions | ||||
|  | ||||
| 2. **Phase 2 merging enabled** | ||||
|    - Compatible components can compile together | ||||
|    - **Expected reduction: ~500 tests → ~50-100 tests (80-90%)** | ||||
|    - **Expected CI time: 12 hours → 2-3 hours** | ||||
|  | ||||
| 3. **Easier maintenance** | ||||
|    - Change I2C pins for a platform once, affects all tests | ||||
|    - Consistent pin assignments across all components | ||||
|  | ||||
| ## Component Compatibility | ||||
|  | ||||
| Most components auto-detect and use the shared bus. Some edge cases: | ||||
|  | ||||
| - **Special frequency requirements**: Some components (like ags10) need custom I2C frequencies. These can't be merged with standard frequency components. | ||||
| - **Multiple buses needed**: Rare, but some tests might need multiple UART ports. | ||||
|  | ||||
| These special cases will be handled individually in Phase 2. | ||||
|  | ||||
| ## Migration Summary | ||||
|  | ||||
| - **11 common bus config files** created | ||||
| - **1,459 component test files** migrated to use common configs | ||||
| - **346 bus definitions** removed from component files | ||||
| - **41 explicit bus ID references** removed (components now auto-detect) | ||||
| - All sample tests validate successfully ✓ | ||||
							
								
								
									
										9
									
								
								tests/test_build_components/common/ble/esp32-ard.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/test_build_components/common/ble/esp32-ard.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Common BLE tracker configuration for ESP32 Arduino tests | ||||
| # BLE client components share this tracker infrastructure | ||||
| # Each component defines its own ble_client with unique MAC address | ||||
|  | ||||
| esp32_ble_tracker: | ||||
|   scan_parameters: | ||||
|     interval: 1100ms | ||||
|     window: 1100ms | ||||
|     active: true | ||||
							
								
								
									
										9
									
								
								tests/test_build_components/common/ble/esp32-c3-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/test_build_components/common/ble/esp32-c3-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Common BLE tracker configuration for ESP32-C3 IDF tests | ||||
| # BLE client components share this tracker infrastructure | ||||
| # Each component defines its own ble_client with unique MAC address | ||||
|  | ||||
| esp32_ble_tracker: | ||||
|   scan_parameters: | ||||
|     interval: 1100ms | ||||
|     window: 1100ms | ||||
|     active: true | ||||
							
								
								
									
										9
									
								
								tests/test_build_components/common/ble/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								tests/test_build_components/common/ble/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Common BLE tracker configuration for ESP32 IDF tests | ||||
| # BLE client components share this tracker infrastructure | ||||
| # Each component defines its own ble_client with unique MAC address | ||||
|  | ||||
| esp32_ble_tracker: | ||||
|   scan_parameters: | ||||
|     interval: 1100ms | ||||
|     window: 1100ms | ||||
|     active: true | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/i2c/esp32-ard.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/i2c/esp32-ard.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common I2C configuration for ESP32 Arduino tests | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO22 | ||||
|   sda_pin: GPIO21 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     scan: true | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/i2c/esp32-c3-ard.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/i2c/esp32-c3-ard.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common I2C configuration for ESP32-C3 Arduino tests | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO8 | ||||
|   sda_pin: GPIO10 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     scan: true | ||||
							
								
								
									
										5
									
								
								tests/test_build_components/common/i2c/esp32-c3-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								tests/test_build_components/common/i2c/esp32-c3-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,5 @@ | ||||
| # Common I2C configuration for ESP32-C3 IDF tests | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO8 | ||||
|   sda_pin: GPIO10 | ||||
							
								
								
									
										13
									
								
								tests/test_build_components/common/i2c/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								tests/test_build_components/common/i2c/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| # Common I2C configuration for ESP32 IDF tests | ||||
| # Provides a shared I2C bus that all components can use | ||||
| # Components will auto-use this bus if they don't specify i2c_id | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO16 | ||||
|   sda_pin: GPIO17 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     scan: true | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/i2c/esp8266-ard.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/i2c/esp8266-ard.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common I2C configuration for ESP8266 Arduino tests | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO5 | ||||
|   sda_pin: GPIO4 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     scan: true | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/i2c/rp2040-ard.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/i2c/rp2040-ard.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common I2C configuration for RP2040 Arduino tests | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO5 | ||||
|   sda_pin: GPIO4 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     scan: true | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common I2C configuration for ESP32 Arduino tests - Low Frequency (10kHz) | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO22 | ||||
|   sda_pin: GPIO21 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     frequency: 10kHz | ||||
|     scan: true | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common I2C configuration for ESP32-C3 Arduino tests - Low Frequency (10kHz) | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO6 | ||||
|   sda_pin: GPIO5 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     frequency: 10kHz | ||||
|     scan: true | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common I2C configuration for ESP32-C3 IDF tests - Low Frequency (10kHz) | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO5 | ||||
|   sda_pin: GPIO4 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     frequency: 10kHz | ||||
|     scan: true | ||||
| @@ -0,0 +1,13 @@ | ||||
| # Common I2C configuration for ESP32 IDF tests - Low Frequency (10kHz) | ||||
| # For components that require I2C frequency <= 15kHz (ags10, ltr501, ltr_als_ps) | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO16 | ||||
|   sda_pin: GPIO17 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     frequency: 10kHz | ||||
|     scan: true | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common I2C configuration for ESP8266 Arduino tests - Low Frequency (10kHz) | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO5 | ||||
|   sda_pin: GPIO4 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     frequency: 10kHz | ||||
|     scan: true | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common I2C configuration for RP2040 Arduino tests - Low Frequency (10kHz) | ||||
|  | ||||
| substitutions: | ||||
|   scl_pin: GPIO5 | ||||
|   sda_pin: GPIO4 | ||||
|  | ||||
| i2c: | ||||
|   - id: i2c_bus | ||||
|     scl: ${scl_pin} | ||||
|     sda: ${sda_pin} | ||||
|     frequency: 10kHz | ||||
|     scan: true | ||||
							
								
								
									
										15
									
								
								tests/test_build_components/common/spi/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								tests/test_build_components/common/spi/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| # Common SPI configuration for ESP32 IDF tests | ||||
| # Provides a shared SPI bus that all components can use | ||||
| # Components will auto-use this bus if they don't specify spi_id | ||||
| # CS pins are component-specific | ||||
|  | ||||
| substitutions: | ||||
|   clk_pin: GPIO18 | ||||
|   mosi_pin: GPIO23 | ||||
|   miso_pin: GPIO19 | ||||
|  | ||||
| spi: | ||||
|   - id: spi_bus | ||||
|     clk_pin: ${clk_pin} | ||||
|     mosi_pin: ${mosi_pin} | ||||
|     miso_pin: ${miso_pin} | ||||
							
								
								
									
										13
									
								
								tests/test_build_components/common/uart/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								tests/test_build_components/common/uart/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| # Common UART configuration for ESP32 IDF tests | ||||
| # Provides a shared UART bus that components can use | ||||
| # Components will auto-use this bus if they don't specify uart_id | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 9600 | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/uart_1200/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/uart_1200/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 1200 baud | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 1200 | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 1200 baud, EVEN parity | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 1200 | ||||
|     parity: EVEN | ||||
							
								
								
									
										12
									
								
								tests/test_build_components/common/uart_19200/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								tests/test_build_components/common/uart_19200/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 19200 baud | ||||
| # For components that require UART baud rate 19200 (bl0906) | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 19200 | ||||
| @@ -0,0 +1,11 @@ | ||||
| # Common UART configuration for ESP8266 Arduino tests - 19200 baud | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO4 | ||||
|   rx_pin: GPIO5 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 19200 | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/uart_38400/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/uart_38400/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 38400 baud | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 38400 | ||||
							
								
								
									
										11
									
								
								tests/test_build_components/common/uart_4800/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								tests/test_build_components/common/uart_4800/esp32-idf.yaml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 4800 baud | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 4800 | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 4800 baud, EVEN parity | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 4800 | ||||
|     parity: EVEN | ||||
| @@ -0,0 +1,12 @@ | ||||
| # Common UART configuration for ESP32 IDF tests - 9600 baud, EVEN parity | ||||
|  | ||||
| substitutions: | ||||
|   tx_pin: GPIO17 | ||||
|   rx_pin: GPIO16 | ||||
|  | ||||
| uart: | ||||
|   - id: uart_bus | ||||
|     tx_pin: ${tx_pin} | ||||
|     rx_pin: ${rx_pin} | ||||
|     baud_rate: 9600 | ||||
|     parity: EVEN | ||||
		Reference in New Issue
	
	Block a user