mirror of
https://github.com/esphome/esphome.git
synced 2024-11-29 18:24:13 +01:00
Pulse counter validate not both disabled (#902)
This commit is contained in:
parent
d26cd85306
commit
e86f2e993f
1 changed files with 11 additions and 2 deletions
|
@ -38,16 +38,25 @@ def validate_pulse_counter_pin(value):
|
|||
return value
|
||||
|
||||
|
||||
def validate_count_mode(value):
|
||||
rising_edge = value[CONF_RISING_EDGE]
|
||||
falling_edge = value[CONF_FALLING_EDGE]
|
||||
if rising_edge == 'DISABLE' and falling_edge == 'DISABLE':
|
||||
raise cv.Invalid("Can't set both count modes to DISABLE! This means no counting occurs at "
|
||||
"all!")
|
||||
return value
|
||||
|
||||
|
||||
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2).extend({
|
||||
cv.GenerateID(): cv.declare_id(PulseCounterSensor),
|
||||
cv.Required(CONF_PIN): validate_pulse_counter_pin,
|
||||
cv.Optional(CONF_COUNT_MODE, default={
|
||||
CONF_RISING_EDGE: 'INCREMENT',
|
||||
CONF_FALLING_EDGE: 'DISABLE',
|
||||
}): cv.Schema({
|
||||
}): cv.All(cv.Schema({
|
||||
cv.Required(CONF_RISING_EDGE): COUNT_MODE_SCHEMA,
|
||||
cv.Required(CONF_FALLING_EDGE): COUNT_MODE_SCHEMA,
|
||||
}),
|
||||
}), validate_count_mode),
|
||||
cv.Optional(CONF_INTERNAL_FILTER, default='13us'): validate_internal_filter,
|
||||
}).extend(cv.polling_component_schema('60s'))
|
||||
|
||||
|
|
Loading…
Reference in a new issue