mirror of
https://github.com/esphome/esphome.git
synced 2024-11-14 02:58:11 +01:00
Replace optimistic with Assumed State (#394)
* Replace optimistic with Assumed State * Add tests * Fix * Lint
This commit is contained in:
parent
6eb769e6d5
commit
61762bf299
4 changed files with 16 additions and 6 deletions
|
@ -3,8 +3,8 @@ import voluptuous as vol
|
||||||
from esphomeyaml import automation
|
from esphomeyaml import automation
|
||||||
from esphomeyaml.components import cover
|
from esphomeyaml.components import cover
|
||||||
import esphomeyaml.config_validation as cv
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml.const import CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, CONF_NAME, \
|
from esphomeyaml.const import CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, \
|
||||||
CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STOP_ACTION
|
CONF_NAME, CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STOP_ACTION
|
||||||
from esphomeyaml.cpp_generator import Pvariable, add, process_lambda
|
from esphomeyaml.cpp_generator import Pvariable, add, process_lambda
|
||||||
from esphomeyaml.cpp_helpers import setup_component
|
from esphomeyaml.cpp_helpers import setup_component
|
||||||
from esphomeyaml.cpp_types import App, NoArg, optional
|
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),
|
cv.GenerateID(): cv.declare_variable_id(TemplateCover),
|
||||||
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
||||||
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
|
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_OPEN_ACTION): automation.validate_automation(single=True),
|
||||||
vol.Optional(CONF_CLOSE_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),
|
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):
|
def to_code(config):
|
||||||
|
@ -44,6 +45,8 @@ def to_code(config):
|
||||||
config[CONF_STOP_ACTION])
|
config[CONF_STOP_ACTION])
|
||||||
if CONF_OPTIMISTIC in config:
|
if CONF_OPTIMISTIC in config:
|
||||||
add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
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'
|
BUILD_FLAGS = '-DUSE_TEMPLATE_COVER'
|
||||||
|
|
|
@ -4,7 +4,7 @@ from esphomeyaml import automation
|
||||||
from esphomeyaml.components import switch
|
from esphomeyaml.components import switch
|
||||||
import esphomeyaml.config_validation as cv
|
import esphomeyaml.config_validation as cv
|
||||||
from esphomeyaml.const import CONF_ID, CONF_LAMBDA, CONF_NAME, CONF_OPTIMISTIC, \
|
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_generator import Pvariable, add, process_lambda
|
||||||
from esphomeyaml.cpp_helpers import setup_component
|
from esphomeyaml.cpp_helpers import setup_component
|
||||||
from esphomeyaml.cpp_types import App, Component, NoArg, bool_, optional
|
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),
|
cv.GenerateID(): cv.declare_variable_id(TemplateSwitch),
|
||||||
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
vol.Optional(CONF_LAMBDA): cv.lambda_,
|
||||||
vol.Optional(CONF_OPTIMISTIC): cv.boolean,
|
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_OFF_ACTION): automation.validate_automation(single=True),
|
||||||
vol.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True),
|
vol.Optional(CONF_TURN_ON_ACTION): automation.validate_automation(single=True),
|
||||||
vol.Optional(CONF_RESTORE_STATE): cv.boolean,
|
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):
|
def to_code(config):
|
||||||
|
@ -40,6 +41,8 @@ def to_code(config):
|
||||||
config[CONF_TURN_ON_ACTION])
|
config[CONF_TURN_ON_ACTION])
|
||||||
if CONF_OPTIMISTIC in config:
|
if CONF_OPTIMISTIC in config:
|
||||||
add(template.set_optimistic(config[CONF_OPTIMISTIC]))
|
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:
|
if CONF_RESTORE_STATE in config:
|
||||||
add(template.set_restore_state(config[CONF_RESTORE_STATE]))
|
add(template.set_restore_state(config[CONF_RESTORE_STATE]))
|
||||||
|
|
|
@ -244,6 +244,7 @@ CONF_CLOSE_ACTION = 'close_action'
|
||||||
CONF_STOP_ACTION = 'stop_action'
|
CONF_STOP_ACTION = 'stop_action'
|
||||||
CONF_DOMAIN = 'domain'
|
CONF_DOMAIN = 'domain'
|
||||||
CONF_OPTIMISTIC = 'optimistic'
|
CONF_OPTIMISTIC = 'optimistic'
|
||||||
|
CONF_ASSUMED_STATE = 'assumed_state'
|
||||||
CONF_ON_BOOT = 'on_boot'
|
CONF_ON_BOOT = 'on_boot'
|
||||||
CONF_ON_SHUTDOWN = 'on_shutdown'
|
CONF_ON_SHUTDOWN = 'on_shutdown'
|
||||||
CONF_PRIORITY = 'priority'
|
CONF_PRIORITY = 'priority'
|
||||||
|
|
|
@ -886,6 +886,7 @@ switch:
|
||||||
- platform: template
|
- platform: template
|
||||||
name: Living Room Lights
|
name: Living Room Lights
|
||||||
optimistic: True
|
optimistic: True
|
||||||
|
assumed_state: yes
|
||||||
turn_on_action:
|
turn_on_action:
|
||||||
- switch.turn_on: living_room_lights_on
|
- switch.turn_on: living_room_lights_on
|
||||||
- output.set_level:
|
- output.set_level:
|
||||||
|
@ -923,6 +924,7 @@ switch:
|
||||||
// Switch is OFF, do something else here
|
// Switch is OFF, do something else here
|
||||||
}
|
}
|
||||||
optimistic: true
|
optimistic: true
|
||||||
|
assumed_state: no
|
||||||
restore_state: True
|
restore_state: True
|
||||||
- platform: uart
|
- platform: uart
|
||||||
name: "UART String Output"
|
name: "UART String Output"
|
||||||
|
@ -931,7 +933,7 @@ switch:
|
||||||
name: "UART Bytes Output"
|
name: "UART Bytes Output"
|
||||||
data: [0xDE, 0xAD, 0xBE, 0xEF]
|
data: [0xDE, 0xAD, 0xBE, 0xEF]
|
||||||
- platform: template
|
- platform: template
|
||||||
optimistic: true
|
assumed_state: yes
|
||||||
name: Stepper Switch
|
name: Stepper Switch
|
||||||
turn_on_action:
|
turn_on_action:
|
||||||
- stepper.set_target:
|
- stepper.set_target:
|
||||||
|
@ -1046,6 +1048,7 @@ cover:
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
optimistic: true
|
optimistic: true
|
||||||
|
assumed_state: no
|
||||||
|
|
||||||
debug:
|
debug:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue