Add servo missing restore option to codegen (#829)

See also https://github.com/esphome/issues/issues/609
This commit is contained in:
Otto Winter 2019-11-02 20:56:42 +01:00
parent 1f243ae37e
commit a59cde91ad
No known key found for this signature in database
GPG key ID: DB66C0BE6013F97E
3 changed files with 5 additions and 1 deletions

View file

@ -4,7 +4,7 @@ from esphome import automation
from esphome.automation import maybe_simple_id from esphome.automation import maybe_simple_id
from esphome.components.output import FloatOutput from esphome.components.output import FloatOutput
from esphome.const import CONF_ID, CONF_IDLE_LEVEL, CONF_MAX_LEVEL, CONF_MIN_LEVEL, CONF_OUTPUT, \ from esphome.const import CONF_ID, CONF_IDLE_LEVEL, CONF_MAX_LEVEL, CONF_MIN_LEVEL, CONF_OUTPUT, \
CONF_LEVEL CONF_LEVEL, CONF_RESTORE
servo_ns = cg.esphome_ns.namespace('servo') servo_ns = cg.esphome_ns.namespace('servo')
Servo = servo_ns.class_('Servo', cg.Component) Servo = servo_ns.class_('Servo', cg.Component)
@ -18,6 +18,7 @@ CONFIG_SCHEMA = cv.Schema({
cv.Optional(CONF_MIN_LEVEL, default='3%'): cv.percentage, cv.Optional(CONF_MIN_LEVEL, default='3%'): cv.percentage,
cv.Optional(CONF_IDLE_LEVEL, default='7.5%'): cv.percentage, cv.Optional(CONF_IDLE_LEVEL, default='7.5%'): cv.percentage,
cv.Optional(CONF_MAX_LEVEL, default='12%'): cv.percentage, cv.Optional(CONF_MAX_LEVEL, default='12%'): cv.percentage,
cv.Optional(CONF_RESTORE, default=False): cv.boolean,
}).extend(cv.COMPONENT_SCHEMA) }).extend(cv.COMPONENT_SCHEMA)
@ -30,6 +31,7 @@ def to_code(config):
cg.add(var.set_min_level(config[CONF_MIN_LEVEL])) cg.add(var.set_min_level(config[CONF_MIN_LEVEL]))
cg.add(var.set_idle_level(config[CONF_IDLE_LEVEL])) cg.add(var.set_idle_level(config[CONF_IDLE_LEVEL]))
cg.add(var.set_max_level(config[CONF_MAX_LEVEL])) cg.add(var.set_max_level(config[CONF_MAX_LEVEL]))
cg.add(var.set_restore(config[CONF_RESTORE]))
@automation.register_action('servo.write', ServoWriteAction, cv.Schema({ @automation.register_action('servo.write', ServoWriteAction, cv.Schema({

View file

@ -47,6 +47,7 @@ class Servo : public Component {
void set_min_level(float min_level) { min_level_ = min_level; } void set_min_level(float min_level) { min_level_ = min_level; }
void set_idle_level(float idle_level) { idle_level_ = idle_level; } void set_idle_level(float idle_level) { idle_level_ = idle_level; }
void set_max_level(float max_level) { max_level_ = max_level; } void set_max_level(float max_level) { max_level_ = max_level; }
void set_restore(bool restore) { restore_ = restore; }
protected: protected:
void save_level_(float v) { this->rtc_.save(&v); } void save_level_(float v) { this->rtc_.save(&v); }

View file

@ -620,6 +620,7 @@ light:
servo: servo:
id: my_servo id: my_servo
output: out output: out
restore: true
ttp229_lsf: ttp229_lsf: