mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Add ESP32 variant config validator function (#3088)
* Add esp32_variant config validator function * Drop unused is_esp32c3 function Co-authored-by: Otto Winter <otto@otto-winter.com>
This commit is contained in:
		| @@ -65,8 +65,26 @@ def get_esp32_variant(): | |||||||
|     return CORE.data[KEY_ESP32][KEY_VARIANT] |     return CORE.data[KEY_ESP32][KEY_VARIANT] | ||||||
|  |  | ||||||
|  |  | ||||||
| def is_esp32c3(): | def only_on_variant(*, supported=None, unsupported=None): | ||||||
|     return get_esp32_variant() == VARIANT_ESP32C3 |     """Config validator for features only available on some ESP32 variants.""" | ||||||
|  |     if supported is not None and not isinstance(supported, list): | ||||||
|  |         supported = [supported] | ||||||
|  |     if unsupported is not None and not isinstance(unsupported, list): | ||||||
|  |         unsupported = [unsupported] | ||||||
|  |  | ||||||
|  |     def validator_(obj): | ||||||
|  |         variant = get_esp32_variant() | ||||||
|  |         if supported is not None and variant not in supported: | ||||||
|  |             raise cv.Invalid( | ||||||
|  |                 f"This feature is only available on {', '.join(supported)}" | ||||||
|  |             ) | ||||||
|  |         if unsupported is not None and variant in unsupported: | ||||||
|  |             raise cv.Invalid( | ||||||
|  |                 f"This feature is not available on {', '.join(unsupported)}" | ||||||
|  |             ) | ||||||
|  |         return obj | ||||||
|  |  | ||||||
|  |     return validator_ | ||||||
|  |  | ||||||
|  |  | ||||||
| @dataclass | @dataclass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user