add time cover assumed_state option (#979)

This commit is contained in:
Guillermo Ruffino 2020-03-11 21:35:01 -03:00 committed by GitHub
parent 177617e6e3
commit fcb2cc2471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 2 deletions

View File

@ -3,7 +3,7 @@ import esphome.config_validation as cv
from esphome import automation from esphome import automation
from esphome.components import cover from esphome.components import cover
from esphome.const import CONF_CLOSE_ACTION, CONF_CLOSE_DURATION, CONF_ID, CONF_OPEN_ACTION, \ 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') time_based_ns = cg.esphome_ns.namespace('time_based')
TimeBasedCover = time_based_ns.class_('TimeBasedCover', cover.Cover, cg.Component) 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.Required(CONF_CLOSE_DURATION): cv.positive_time_period_milliseconds,
cv.Optional(CONF_HAS_BUILT_IN_ENDSTOP, default=False): cv.boolean, cv.Optional(CONF_HAS_BUILT_IN_ENDSTOP, default=False): cv.boolean,
cv.Optional(CONF_ASSUMED_STATE, default=True): cv.boolean,
}).extend(cv.COMPONENT_SCHEMA) }).extend(cv.COMPONENT_SCHEMA)
@ -38,3 +39,4 @@ def to_code(config):
yield automation.build_automation(var.get_close_trigger(), [], config[CONF_CLOSE_ACTION]) 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_has_built_in_endstop(config[CONF_HAS_BUILT_IN_ENDSTOP]))
cg.add(var.set_assumed_state(config[CONF_ASSUMED_STATE]))

View File

@ -51,7 +51,7 @@ float TimeBasedCover::get_setup_priority() const { return setup_priority::DATA;
CoverTraits TimeBasedCover::get_traits() { CoverTraits TimeBasedCover::get_traits() {
auto traits = CoverTraits(); auto traits = CoverTraits();
traits.set_supports_position(true); traits.set_supports_position(true);
traits.set_is_assumed_state(true); traits.set_is_assumed_state(this->assumed_state_);
return traits; return traits;
} }
void TimeBasedCover::control(const CoverCall &call) { void TimeBasedCover::control(const CoverCall &call) {

View File

@ -21,6 +21,7 @@ class TimeBasedCover : public cover::Cover, public Component {
void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; } void set_close_duration(uint32_t close_duration) { this->close_duration_ = close_duration; }
cover::CoverTraits get_traits() override; cover::CoverTraits get_traits() override;
void set_has_built_in_endstop(bool value) { this->has_built_in_endstop_ = value; } 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: protected:
void control(const cover::CoverCall &call) override; void control(const cover::CoverCall &call) override;
@ -43,6 +44,7 @@ class TimeBasedCover : public cover::Cover, public Component {
uint32_t last_publish_time_{0}; uint32_t last_publish_time_{0};
float target_position_{0}; float target_position_{0};
bool has_built_in_endstop_{false}; bool has_built_in_endstop_{false};
bool assumed_state_{false};
}; };
} // namespace time_based } // namespace time_based