mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 01:07:45 +01:00
fix: template cover add position action (#877)
* Update const.py * Update __init__.py * Update template_cover.cpp * Update __init__.py * Update test3.yaml * formatting code * formatting code 2 * removed position lambda * Update test3.yaml * Update __init__.py
This commit is contained in:
parent
6a0268b852
commit
be36eef939
4 changed files with 16 additions and 5 deletions
|
@ -4,7 +4,8 @@ from esphome import automation
|
|||
from esphome.components import cover
|
||||
from esphome.const import CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_CURRENT_OPERATION, CONF_ID, \
|
||||
CONF_LAMBDA, CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_POSITION, CONF_RESTORE_MODE, \
|
||||
CONF_STATE, CONF_STOP_ACTION, CONF_TILT, CONF_TILT_ACTION, CONF_TILT_LAMBDA
|
||||
CONF_STATE, CONF_STOP_ACTION, CONF_TILT, CONF_TILT_ACTION, CONF_TILT_LAMBDA, \
|
||||
CONF_POSITION_ACTION
|
||||
from .. import template_ns
|
||||
|
||||
TemplateCover = template_ns.class_('TemplateCover', cover.Cover, cg.Component)
|
||||
|
@ -29,6 +30,7 @@ CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({
|
|||
cv.Optional(CONF_STOP_ACTION): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_TILT_ACTION): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_TILT_LAMBDA): cv.returning_lambda,
|
||||
cv.Optional(CONF_POSITION_ACTION): automation.validate_automation(single=True),
|
||||
cv.Optional(CONF_RESTORE_MODE, default='RESTORE'): cv.enum(RESTORE_MODES, upper=True),
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
@ -55,11 +57,15 @@ def to_code(config):
|
|||
tilt_template_ = yield cg.process_lambda(config[CONF_TILT_LAMBDA], [],
|
||||
return_type=cg.optional.template(float))
|
||||
cg.add(var.set_tilt_lambda(tilt_template_))
|
||||
|
||||
if CONF_POSITION_ACTION in config:
|
||||
yield automation.build_automation(var.get_position_trigger(), [(float, 'pos')],
|
||||
config[CONF_POSITION_ACTION])
|
||||
cg.add(var.set_has_position(True))
|
||||
else:
|
||||
cg.add(var.set_has_position(config[CONF_HAS_POSITION]))
|
||||
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
||||
cg.add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
|
||||
cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
||||
cg.add(var.set_has_position(config[CONF_HAS_POSITION]))
|
||||
|
||||
|
||||
@automation.register_action('cover.template.publish', cover.CoverPublishAction, cv.Schema({
|
||||
|
|
|
@ -86,10 +86,10 @@ void TemplateCover::control(const CoverCall &call) {
|
|||
} else if (pos == COVER_CLOSED) {
|
||||
this->close_trigger_->trigger();
|
||||
this->prev_command_trigger_ = this->close_trigger_;
|
||||
} else {
|
||||
this->position_trigger_->trigger(pos);
|
||||
}
|
||||
|
||||
this->position_trigger_->trigger(pos);
|
||||
|
||||
if (this->optimistic_) {
|
||||
this->position = pos;
|
||||
}
|
||||
|
|
|
@ -331,6 +331,7 @@ CONF_PM_10_0 = 'pm_10_0'
|
|||
CONF_PM_2_5 = 'pm_2_5'
|
||||
CONF_PORT = 'port'
|
||||
CONF_POSITION = 'position'
|
||||
CONF_POSITION_ACTION = 'position_action'
|
||||
CONF_POWER = 'power'
|
||||
CONF_POWER_FACTOR = 'power_factor'
|
||||
CONF_POWER_ON_VALUE = 'power_on_value'
|
||||
|
|
|
@ -578,6 +578,10 @@ cover:
|
|||
- output.set_level:
|
||||
id: out
|
||||
level: !lambda "return tilt;"
|
||||
position_action:
|
||||
- output.set_level:
|
||||
id: out
|
||||
level: !lambda "return pos;"
|
||||
|
||||
|
||||
output:
|
||||
|
|
Loading…
Reference in a new issue