diff --git a/esphomeyaml/components/cover/template.py b/esphomeyaml/components/cover/template.py index b881bf4fde..a19c7a07d2 100644 --- a/esphomeyaml/components/cover/template.py +++ b/esphomeyaml/components/cover/template.py @@ -3,8 +3,8 @@ import voluptuous as vol from esphomeyaml import automation from esphomeyaml.components import cover import esphomeyaml.config_validation as cv -from esphomeyaml.const import CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, CONF_NAME, \ - CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STOP_ACTION +from esphomeyaml.const import CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, \ + CONF_NAME, CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STOP_ACTION from esphomeyaml.cpp_generator import Pvariable, add, process_lambda from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import App, NoArg, optional @@ -15,10 +15,11 @@ PLATFORM_SCHEMA = cv.nameable(cover.COVER_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateCover), vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_OPTIMISTIC): cv.boolean, + vol.Optional(CONF_ASSUMED_STATE): cv.boolean, vol.Optional(CONF_OPEN_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_CLOSE_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_STOP_ACTION): automation.validate_automation(single=True), -}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_LAMBDA, CONF_OPTIMISTIC)) +}).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): @@ -44,6 +45,8 @@ def to_code(config): config[CONF_STOP_ACTION]) if CONF_OPTIMISTIC in config: add(var.set_optimistic(config[CONF_OPTIMISTIC])) + if CONF_ASSUMED_STATE in config: + add(var.set_assumed_state(config[CONF_ASSUMED_STATE])) BUILD_FLAGS = '-DUSE_TEMPLATE_COVER' diff --git a/esphomeyaml/components/switch/template.py b/esphomeyaml/components/switch/template.py index 7ca25df90a..8e16815513 100644 --- a/esphomeyaml/components/switch/template.py +++ b/esphomeyaml/components/switch/template.py @@ -4,7 +4,7 @@ from esphomeyaml import automation from esphomeyaml.components import switch import esphomeyaml.config_validation as cv from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_OPTIMISTIC, \ - CONF_RESTORE_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION + CONF_RESTORE_STATE, CONF_TURN_OFF_ACTION, CONF_TURN_ON_ACTION, CONF_ASSUMED_STATE from esphomeyaml.cpp_generator import Pvariable, add, process_lambda from esphomeyaml.cpp_helpers import setup_component from esphomeyaml.cpp_types import App, Component, NoArg, bool_, optional @@ -15,10 +15,11 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({ cv.GenerateID(): cv.declare_variable_id(TemplateSwitch), vol.Optional(CONF_LAMBDA): cv.lambda_, vol.Optional(CONF_OPTIMISTIC): cv.boolean, + vol.Optional(CONF_ASSUMED_STATE): cv.boolean, vol.Optional(CONF_TURN_OFF_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True), vol.Optional(CONF_RESTORE_STATE): cv.boolean, -}).extend(cv.COMPONENT_SCHEMA.schema), cv.has_at_least_one_key(CONF_LAMBDA, CONF_OPTIMISTIC)) +}).extend(cv.COMPONENT_SCHEMA.schema)) def to_code(config): @@ -40,6 +41,8 @@ def to_code(config): config[CONF_TURN_ON_ACTION]) if CONF_OPTIMISTIC in config: add(template.set_optimistic(config[CONF_OPTIMISTIC])) + if CONF_ASSUMED_STATE in config: + add(template.set_assumed_state(config[CONF_ASSUMED_STATE])) if CONF_RESTORE_STATE in config: add(template.set_restore_state(config[CONF_RESTORE_STATE])) diff --git a/esphomeyaml/const.py b/esphomeyaml/const.py index c0d9325476..878386ad2f 100644 --- a/esphomeyaml/const.py +++ b/esphomeyaml/const.py @@ -244,6 +244,7 @@ CONF_CLOSE_ACTION = 'close_action' CONF_STOP_ACTION = 'stop_action' CONF_DOMAIN = 'domain' CONF_OPTIMISTIC = 'optimistic' +CONF_ASSUMED_STATE = 'assumed_state' CONF_ON_BOOT = 'on_boot' CONF_ON_SHUTDOWN = 'on_shutdown' CONF_PRIORITY = 'priority' diff --git a/tests/test1.yaml b/tests/test1.yaml index 2e6366d3be..24db85034f 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -886,6 +886,7 @@ switch: - platform: template name: Living Room Lights optimistic: True + assumed_state: yes turn_on_action: - switch.turn_on: living_room_lights_on - output.set_level: @@ -923,6 +924,7 @@ switch: // Switch is OFF, do something else here } optimistic: true + assumed_state: no restore_state: True - platform: uart name: "UART String Output" @@ -931,7 +933,7 @@ switch: name: "UART Bytes Output" data: [0xDE, 0xAD, 0xBE, 0xEF] - platform: template - optimistic: true + assumed_state: yes name: Stepper Switch turn_on_action: - stepper.set_target: @@ -1046,6 +1048,7 @@ cover: return {}; } optimistic: true + assumed_state: no debug: