From a59cde91adb650d0770669324ed3d09369d6ff2a Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Sat, 2 Nov 2019 20:56:42 +0100 Subject: [PATCH] Add servo missing restore option to codegen (#829) See also https://github.com/esphome/issues/issues/609 --- esphome/components/servo/__init__.py | 4 +++- esphome/components/servo/servo.h | 1 + tests/test3.yaml | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/esphome/components/servo/__init__.py b/esphome/components/servo/__init__.py index 92243ee18d..9b06159c13 100644 --- a/esphome/components/servo/__init__.py +++ b/esphome/components/servo/__init__.py @@ -4,7 +4,7 @@ from esphome import automation from esphome.automation import maybe_simple_id from esphome.components.output import FloatOutput 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 = 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_IDLE_LEVEL, default='7.5%'): cv.percentage, cv.Optional(CONF_MAX_LEVEL, default='12%'): cv.percentage, + cv.Optional(CONF_RESTORE, default=False): cv.boolean, }).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_idle_level(config[CONF_IDLE_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({ diff --git a/esphome/components/servo/servo.h b/esphome/components/servo/servo.h index 3a0993c0c4..19165be23d 100644 --- a/esphome/components/servo/servo.h +++ b/esphome/components/servo/servo.h @@ -47,6 +47,7 @@ class Servo : public Component { void set_min_level(float min_level) { min_level_ = min_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_restore(bool restore) { restore_ = restore; } protected: void save_level_(float v) { this->rtc_.save(&v); } diff --git a/tests/test3.yaml b/tests/test3.yaml index d1596c8f41..6d70f60764 100644 --- a/tests/test3.yaml +++ b/tests/test3.yaml @@ -620,6 +620,7 @@ light: servo: id: my_servo output: out + restore: true ttp229_lsf: