pulse_counter_ulp: Validate platform properly

Only available on ESP32 with ESP-IDF
This commit is contained in:
brisk 2024-09-29 22:19:14 +09:30
parent 7b9d000522
commit e5ac747225

View file

@ -8,7 +8,6 @@ from esphome.const import (
CONF_COUNT_MODE, CONF_COUNT_MODE,
CONF_DEBOUNCE, CONF_DEBOUNCE,
CONF_FALLING_EDGE, CONF_FALLING_EDGE,
CONF_NUMBER,
CONF_PIN, CONF_PIN,
CONF_RISING_EDGE, CONF_RISING_EDGE,
CONF_SLEEP_DURATION, CONF_SLEEP_DURATION,
@ -16,7 +15,6 @@ from esphome.const import (
STATE_CLASS_MEASUREMENT, STATE_CLASS_MEASUREMENT,
UNIT_PULSES_PER_MINUTE, UNIT_PULSES_PER_MINUTE,
) )
from esphome.core import CORE
pulse_counter_ulp_ns = cg.esphome_ns.namespace("pulse_counter_ulp") pulse_counter_ulp_ns = cg.esphome_ns.namespace("pulse_counter_ulp")
CountMode = pulse_counter_ulp_ns.enum("CountMode", is_class=True) CountMode = pulse_counter_ulp_ns.enum("CountMode", is_class=True)
@ -35,10 +33,6 @@ PulseCounterUlpSensor = pulse_counter_ulp_ns.class_(
def validate_pulse_counter_pin(value): def validate_pulse_counter_pin(value):
value = pins.internal_gpio_input_pin_schema(value) value = pins.internal_gpio_input_pin_schema(value)
if CORE.is_esp8266 and value[CONF_NUMBER] >= 16:
raise cv.Invalid(
"Pins GPIO16 and GPIO17 cannot be used as pulse counters on ESP8266."
)
return value return value
@ -86,6 +80,8 @@ CONFIG_SCHEMA = cv.All(
}, },
) )
.extend(cv.polling_component_schema("60s")), .extend(cv.polling_component_schema("60s")),
cv.only_on_esp32,
cv.only_with_esp_idf,
) )