mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	handle bad pin schemas (#7711)
Co-authored-by: Samuel Sieb <samuel@sieb.net>
This commit is contained in:
		| @@ -67,8 +67,10 @@ def _translate_pin(value): | |||||||
|             "This variable only supports pin numbers, not full pin schemas " |             "This variable only supports pin numbers, not full pin schemas " | ||||||
|             "(with inverted and mode)." |             "(with inverted and mode)." | ||||||
|         ) |         ) | ||||||
|     if isinstance(value, int): |     if isinstance(value, int) and not isinstance(value, bool): | ||||||
|         return value |         return value | ||||||
|  |     if not isinstance(value, str): | ||||||
|  |         raise cv.Invalid(f"Invalid pin number: {value}") | ||||||
|     try: |     try: | ||||||
|         return int(value) |         return int(value) | ||||||
|     except ValueError: |     except ValueError: | ||||||
|   | |||||||
| @@ -1,6 +1,9 @@ | |||||||
| import logging |  | ||||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||||
|  | import logging | ||||||
|  |  | ||||||
|  | from esphome import pins | ||||||
|  | import esphome.codegen as cg | ||||||
|  | import esphome.config_validation as cv | ||||||
| from esphome.const import ( | from esphome.const import ( | ||||||
|     CONF_ANALOG, |     CONF_ANALOG, | ||||||
|     CONF_ID, |     CONF_ID, | ||||||
| @@ -14,10 +17,7 @@ from esphome.const import ( | |||||||
|     CONF_PULLUP, |     CONF_PULLUP, | ||||||
|     PLATFORM_ESP8266, |     PLATFORM_ESP8266, | ||||||
| ) | ) | ||||||
| from esphome import pins |  | ||||||
| from esphome.core import CORE, coroutine_with_priority | from esphome.core import CORE, coroutine_with_priority | ||||||
| import esphome.config_validation as cv |  | ||||||
| import esphome.codegen as cg |  | ||||||
|  |  | ||||||
| from . import boards | from . import boards | ||||||
| from .const import KEY_BOARD, KEY_ESP8266, KEY_PIN_INITIAL_STATES, esp8266_ns | from .const import KEY_BOARD, KEY_ESP8266, KEY_PIN_INITIAL_STATES, esp8266_ns | ||||||
| @@ -48,8 +48,10 @@ def _translate_pin(value): | |||||||
|             "This variable only supports pin numbers, not full pin schemas " |             "This variable only supports pin numbers, not full pin schemas " | ||||||
|             "(with inverted and mode)." |             "(with inverted and mode)." | ||||||
|         ) |         ) | ||||||
|     if isinstance(value, int): |     if isinstance(value, int) and not isinstance(value, bool): | ||||||
|         return value |         return value | ||||||
|  |     if not isinstance(value, str): | ||||||
|  |         raise cv.Invalid(f"Invalid pin number: {value}") | ||||||
|     try: |     try: | ||||||
|         return int(value) |         return int(value) | ||||||
|     except ValueError: |     except ValueError: | ||||||
|   | |||||||
| @@ -1,5 +1,8 @@ | |||||||
| import logging | import logging | ||||||
|  |  | ||||||
|  | from esphome import pins | ||||||
|  | import esphome.codegen as cg | ||||||
|  | import esphome.config_validation as cv | ||||||
| from esphome.const import ( | from esphome.const import ( | ||||||
|     CONF_ID, |     CONF_ID, | ||||||
|     CONF_INPUT, |     CONF_INPUT, | ||||||
| @@ -11,9 +14,6 @@ from esphome.const import ( | |||||||
|     CONF_PULLDOWN, |     CONF_PULLDOWN, | ||||||
|     CONF_PULLUP, |     CONF_PULLUP, | ||||||
| ) | ) | ||||||
| from esphome import pins |  | ||||||
| import esphome.config_validation as cv |  | ||||||
| import esphome.codegen as cg |  | ||||||
|  |  | ||||||
| from .const import host_ns | from .const import host_ns | ||||||
|  |  | ||||||
| @@ -28,8 +28,10 @@ def _translate_pin(value): | |||||||
|             "This variable only supports pin numbers, not full pin schemas " |             "This variable only supports pin numbers, not full pin schemas " | ||||||
|             "(with inverted and mode)." |             "(with inverted and mode)." | ||||||
|         ) |         ) | ||||||
|     if isinstance(value, int): |     if isinstance(value, int) and not isinstance(value, bool): | ||||||
|         return value |         return value | ||||||
|  |     if not isinstance(value, str): | ||||||
|  |         raise cv.Invalid(f"Invalid pin number: {value}") | ||||||
|     try: |     try: | ||||||
|         return int(value) |         return int(value) | ||||||
|     except ValueError: |     except ValueError: | ||||||
|   | |||||||
| @@ -1,8 +1,8 @@ | |||||||
| import logging | import logging | ||||||
|  |  | ||||||
|  | from esphome import pins | ||||||
| import esphome.codegen as cg | import esphome.codegen as cg | ||||||
| import esphome.config_validation as cv | import esphome.config_validation as cv | ||||||
| from esphome import pins |  | ||||||
| from esphome.const import ( | from esphome.const import ( | ||||||
|     CONF_ANALOG, |     CONF_ANALOG, | ||||||
|     CONF_ID, |     CONF_ID, | ||||||
| @@ -103,8 +103,10 @@ def _translate_pin(value): | |||||||
|             "This variable only supports pin numbers, not full pin schemas " |             "This variable only supports pin numbers, not full pin schemas " | ||||||
|             "(with inverted and mode)." |             "(with inverted and mode)." | ||||||
|         ) |         ) | ||||||
|     if isinstance(value, int): |     if isinstance(value, int) and not isinstance(value, bool): | ||||||
|         return value |         return value | ||||||
|  |     if not isinstance(value, str): | ||||||
|  |         raise cv.Invalid(f"Invalid pin number: {value}") | ||||||
|     try: |     try: | ||||||
|         return int(value) |         return int(value) | ||||||
|     except ValueError: |     except ValueError: | ||||||
|   | |||||||
| @@ -1,6 +1,8 @@ | |||||||
|  | from esphome import pins | ||||||
| import esphome.codegen as cg | import esphome.codegen as cg | ||||||
| import esphome.config_validation as cv | import esphome.config_validation as cv | ||||||
| from esphome.const import ( | from esphome.const import ( | ||||||
|  |     CONF_ANALOG, | ||||||
|     CONF_ID, |     CONF_ID, | ||||||
|     CONF_INPUT, |     CONF_INPUT, | ||||||
|     CONF_INVERTED, |     CONF_INVERTED, | ||||||
| @@ -10,10 +12,8 @@ from esphome.const import ( | |||||||
|     CONF_OUTPUT, |     CONF_OUTPUT, | ||||||
|     CONF_PULLDOWN, |     CONF_PULLDOWN, | ||||||
|     CONF_PULLUP, |     CONF_PULLUP, | ||||||
|     CONF_ANALOG, |  | ||||||
| ) | ) | ||||||
| from esphome.core import CORE | from esphome.core import CORE | ||||||
| from esphome import pins |  | ||||||
|  |  | ||||||
| from . import boards | from . import boards | ||||||
| from .const import KEY_BOARD, KEY_RP2040, rp2040_ns | from .const import KEY_BOARD, KEY_RP2040, rp2040_ns | ||||||
| @@ -41,8 +41,10 @@ def _translate_pin(value): | |||||||
|             "This variable only supports pin numbers, not full pin schemas " |             "This variable only supports pin numbers, not full pin schemas " | ||||||
|             "(with inverted and mode)." |             "(with inverted and mode)." | ||||||
|         ) |         ) | ||||||
|     if isinstance(value, int): |     if isinstance(value, int) and not isinstance(value, bool): | ||||||
|         return value |         return value | ||||||
|  |     if not isinstance(value, str): | ||||||
|  |         raise cv.Invalid(f"Invalid pin number: {value}") | ||||||
|     try: |     try: | ||||||
|         return int(value) |         return int(value) | ||||||
|     except ValueError: |     except ValueError: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user