mirror of
https://github.com/esphome/esphome.git
synced 2025-01-30 23:02:14 +01:00
Improve valid_dac_pin() readability
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
2b47ebce0b
commit
809366995f
@ -1,18 +1,27 @@
|
|||||||
|
import esphome.codegen as cg
|
||||||
|
import esphome.config_validation as cv
|
||||||
from esphome import pins
|
from esphome import pins
|
||||||
from esphome.components import output
|
from esphome.components import output
|
||||||
import esphome.config_validation as cv
|
|
||||||
import esphome.codegen as cg
|
|
||||||
from esphome.components.esp32 import get_esp32_variant
|
from esphome.components.esp32 import get_esp32_variant
|
||||||
from esphome.components.esp32.const import VARIANT_ESP32S2
|
from esphome.components.esp32.const import VARIANT_ESP32, VARIANT_ESP32S2
|
||||||
from esphome.const import CONF_ID, CONF_NUMBER, CONF_PIN
|
from esphome.const import CONF_ID, CONF_NUMBER, CONF_PIN
|
||||||
|
|
||||||
DEPENDENCIES = ["esp32"]
|
DEPENDENCIES = ["esp32"]
|
||||||
|
|
||||||
|
DAC_PINS = {
|
||||||
|
VARIANT_ESP32: (25, 26),
|
||||||
|
VARIANT_ESP32S2: (17, 18),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def valid_dac_pin(value):
|
def valid_dac_pin(value):
|
||||||
valid_pins = (17, 18) if get_esp32_variant() == VARIANT_ESP32S2 else (25, 26)
|
variant = get_esp32_variant()
|
||||||
num = value[CONF_NUMBER]
|
try:
|
||||||
cv.one_of(*valid_pins)(num)
|
valid_pins = DAC_PINS[variant]
|
||||||
|
except KeyError as ex:
|
||||||
|
raise cv.Invalid(f"DAC is not supported on {variant}") from ex
|
||||||
|
given_pin = value[CONF_NUMBER]
|
||||||
|
cv.one_of(*valid_pins)(given_pin)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user