mirror of
https://github.com/esphome/esphome.git
synced 2024-12-22 05:24:53 +01:00
add time cover assumed_state option (#979)
This commit is contained in:
parent
177617e6e3
commit
fcb2cc2471
3 changed files with 6 additions and 2 deletions
|
@ -3,7 +3,7 @@ import esphome.config_validation as cv
|
|||
from esphome import automation
|
||||
from esphome.components import cover
|
||||
from esphome.const import CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_ID, CONF_OPEN_ACTION, \
|
||||
CONF_OPEN_DURATION, CONF_STOP_ACTION
|
||||
CONF_OPEN_DURATION, CONF_STOP_ACTION, CONF_ASSUMED_STATE
|
||||
|
||||
time_based_ns = cg.esphome_ns.namespace('time_based')
|
||||
TimeBasedCover = time_based_ns.class_('TimeBasedCover', cover.Cover, cg.Component)
|
||||
|
@ -21,6 +21,7 @@ CONFIG_SCHEMA = cover.COVER_SCHEMA.extend({
|
|||
cv.Required(CONF_CLOSE_DURATION): cv.positive_time_period_milliseconds,
|
||||
|
||||
cv.Optional(CONF_HAS_BUILT_IN_ENDSTOP, default=False): cv.boolean,
|
||||
cv.Optional(CONF_ASSUMED_STATE, default=True): cv.boolean,
|
||||
}).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
|
@ -38,3 +39,4 @@ def to_code(config):
|
|||
yield automation.build_automation(var.get_close_trigger(), [], config[CONF_CLOSE_ACTION])
|
||||
|
||||
cg.add(var.set_has_built_in_endstop(config[CONF_HAS_BUILT_IN_ENDSTOP]))
|
||||
cg.add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))
|
||||
|
|
|
@ -51,7 +51,7 @@ float TimeBasedCover::get_setup_priority() const { return setup_priority::DATA;
|
|||
CoverTraits TimeBasedCover::get_traits() {
|
||||
auto traits = CoverTraits();
|
||||
traits.set_supports_position(true);
|
||||
traits.set_is_assumed_state(true);
|
||||
traits.set_is_assumed_state(this->assumed_state_);
|
||||
return traits;
|
||||
}
|
||||
void TimeBasedCover::control(const CoverCall &call) {
|
||||
|
|
|
@ -21,6 +21,7 @@ class TimeBasedCover : public cover::Cover, public Component {
|
|||
void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; }
|
||||
cover::CoverTraits get_traits() override;
|
||||
void set_has_built_in_endstop(bool value) { this->has_built_in_endstop_ = value; }
|
||||
void set_assumed_state(bool value) { this->assumed_state_ = value; }
|
||||
|
||||
protected:
|
||||
void control(const cover::CoverCall &call) override;
|
||||
|
@ -43,6 +44,7 @@ class TimeBasedCover : public cover::Cover, public Component {
|
|||
uint32_t last_publish_time_{0};
|
||||
float target_position_{0};
|
||||
bool has_built_in_endstop_{false};
|
||||
bool assumed_state_{false};
|
||||
};
|
||||
|
||||
} // namespace time_based
|
||||
|
|
Loading…
Reference in a new issue