mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 17:07:50 +01:00
Pulse counter validate not both disabled (#902)
This commit is contained in:
parent
d26cd85306
commit
e86f2e993f
@ -38,16 +38,25 @@ def validate_pulse_counter_pin(value):
|
|||||||
return 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({
|
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_PULSES_PER_MINUTE, ICON_PULSE, 2).extend({
|
||||||
cv.GenerateID(): cv.declare_id(PulseCounterSensor),
|
cv.GenerateID(): cv.declare_id(PulseCounterSensor),
|
||||||
cv.Required(CONF_PIN): validate_pulse_counter_pin,
|
cv.Required(CONF_PIN): validate_pulse_counter_pin,
|
||||||
cv.Optional(CONF_COUNT_MODE, default={
|
cv.Optional(CONF_COUNT_MODE, default={
|
||||||
CONF_RISING_EDGE: 'INCREMENT',
|
CONF_RISING_EDGE: 'INCREMENT',
|
||||||
CONF_FALLING_EDGE: 'DISABLE',
|
CONF_FALLING_EDGE: 'DISABLE',
|
||||||
}): cv.Schema({
|
}): cv.All(cv.Schema({
|
||||||
cv.Required(CONF_RISING_EDGE): COUNT_MODE_SCHEMA,
|
cv.Required(CONF_RISING_EDGE): COUNT_MODE_SCHEMA,
|
||||||
cv.Required(CONF_FALLING_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,
|
cv.Optional(CONF_INTERNAL_FILTER, default='13us'): validate_internal_filter,
|
||||||
}).extend(cv.polling_component_schema('60s'))
|
}).extend(cv.polling_component_schema('60s'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user