Simplify coroutine syntax (#503)

* Simplify coroutine syntax

* More

* Lint

* Fix

* More

* Lint
This commit is contained in:
Otto Winter 2019-04-09 14:30:12 +02:00 committed by GitHub
parent e90829eef2
commit be5330b6ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
103 changed files with 351 additions and 588 deletions

View File

@ -6,7 +6,7 @@ import esphome.config_validation as cv
from esphome.const import CONF_ABOVE, CONF_ACTION_ID, CONF_AND, CONF_AUTOMATION_ID, CONF_BELOW, \
CONF_CONDITION, CONF_CONDITION_ID, CONF_DELAY, CONF_ELSE, CONF_ID, CONF_IF, CONF_LAMBDA, \
CONF_OR, CONF_RANGE, CONF_THEN, CONF_TRIGGER_ID, CONF_WAIT_UNTIL, CONF_WHILE
from esphome.core import CORE
from esphome.core import CORE, coroutine
from esphome.cpp_generator import Pvariable, TemplateArguments, add, get_variable, \
process_lambda, templatable
from esphome.cpp_types import Action, App, Component, PollingComponent, Trigger, bool_, \
@ -167,8 +167,7 @@ AND_CONDITION_SCHEMA = validate_recursive_condition
@CONDITION_REGISTRY.register(CONF_AND, AND_CONDITION_SCHEMA)
def and_condition_to_code(config, condition_id, template_arg, args):
for conditions in build_conditions(config, template_arg, args):
yield
conditions = yield build_conditions(config, template_arg, args)
rhs = AndCondition.new(template_arg, conditions)
type = AndCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)
@ -179,8 +178,7 @@ OR_CONDITION_SCHEMA = validate_recursive_condition
@CONDITION_REGISTRY.register(CONF_OR, OR_CONDITION_SCHEMA)
def or_condition_to_code(config, condition_id, template_arg, args):
for conditions in build_conditions(config, template_arg, args):
yield
conditions = yield build_conditions(config, template_arg, args)
rhs = OrCondition.new(template_arg, conditions)
type = OrCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)
@ -194,18 +192,15 @@ RANGE_CONDITION_SCHEMA = vol.All(cv.Schema({
@CONDITION_REGISTRY.register(CONF_RANGE, RANGE_CONDITION_SCHEMA)
def range_condition_to_code(config, condition_id, template_arg, args):
for conditions in build_conditions(config, template_arg, args):
yield
conditions = yield build_conditions(config, template_arg, args)
rhs = RangeCondition.new(template_arg, conditions)
type = RangeCondition.template(template_arg)
condition = Pvariable(condition_id, rhs, type=type)
if CONF_ABOVE in config:
for template_ in templatable(config[CONF_ABOVE], args, float_):
yield
template_ = yield templatable(config[CONF_ABOVE], args, float_)
condition.set_min(template_)
if CONF_BELOW in config:
for template_ in templatable(config[CONF_BELOW], args, float_):
yield
template_ = yield templatable(config[CONF_BELOW], args, float_)
condition.set_max(template_)
yield condition
@ -218,8 +213,7 @@ def delay_action_to_code(config, action_id, template_arg, args):
rhs = App.register_component(DelayAction.new(template_arg))
type = DelayAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config, args, uint32):
yield
template_ = yield templatable(config, args, uint32)
add(action.set_delay(template_))
yield action
@ -233,18 +227,15 @@ IF_ACTION_SCHEMA = vol.All({
@ACTION_REGISTRY.register(CONF_IF, IF_ACTION_SCHEMA)
def if_action_to_code(config, action_id, template_arg, args):
for conditions in build_conditions(config[CONF_CONDITION], template_arg, args):
yield None
conditions = yield build_conditions(config[CONF_CONDITION], template_arg, args)
rhs = IfAction.new(template_arg, conditions)
type = IfAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
if CONF_THEN in config:
for actions in build_actions(config[CONF_THEN], template_arg, args):
yield None
actions = yield build_actions(config[CONF_THEN], template_arg, args)
add(action.add_then(actions))
if CONF_ELSE in config:
for actions in build_actions(config[CONF_ELSE], template_arg, args):
yield None
actions = yield build_actions(config[CONF_ELSE], template_arg, args)
add(action.add_else(actions))
yield action
@ -257,13 +248,11 @@ WHILE_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_WHILE, WHILE_ACTION_SCHEMA)
def while_action_to_code(config, action_id, template_arg, args):
for conditions in build_conditions(config[CONF_CONDITION], template_arg, args):
yield None
conditions = yield build_conditions(config[CONF_CONDITION], template_arg, args)
rhs = WhileAction.new(template_arg, conditions)
type = WhileAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for actions in build_actions(config[CONF_THEN], template_arg, args):
yield None
actions = yield build_actions(config[CONF_THEN], template_arg, args)
add(action.add_then(actions))
yield action
@ -282,8 +271,7 @@ WAIT_UNTIL_ACTION_SCHEMA = validate_wait_until
@ACTION_REGISTRY.register(CONF_WAIT_UNTIL, WAIT_UNTIL_ACTION_SCHEMA)
def wait_until_action_to_code(config, action_id, template_arg, args):
for conditions in build_conditions(config[CONF_CONDITION], template_arg, args):
yield None
conditions = yield build_conditions(config[CONF_CONDITION], template_arg, args)
rhs = WaitUntilAction.new(template_arg, conditions)
type = WaitUntilAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
@ -296,8 +284,7 @@ LAMBDA_ACTION_SCHEMA = cv.lambda_
@ACTION_REGISTRY.register(CONF_LAMBDA, LAMBDA_ACTION_SCHEMA)
def lambda_action_to_code(config, action_id, template_arg, args):
for lambda_ in process_lambda(config, args, return_type=void):
yield None
lambda_ = yield process_lambda(config, args, return_type=void)
rhs = LambdaAction.new(template_arg, lambda_)
type = LambdaAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -308,8 +295,7 @@ LAMBDA_CONDITION_SCHEMA = cv.lambda_
@CONDITION_REGISTRY.register(CONF_LAMBDA, LAMBDA_CONDITION_SCHEMA)
def lambda_condition_to_code(config, condition_id, template_arg, args):
for lambda_ in process_lambda(config, args, return_type=bool_):
yield
lambda_ = yield process_lambda(config, args, return_type=bool_)
rhs = LambdaCondition.new(template_arg, lambda_)
type = LambdaCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)
@ -323,59 +309,56 @@ COMPONENT_UPDATE_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_COMPONENT_UPDATE, COMPONENT_UPDATE_ACTION_SCHEMA)
def component_update_action_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = UpdateComponentAction.new(template_arg, var)
type = UpdateComponentAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@coroutine
def build_action(full_config, template_arg, args):
action_id = full_config[CONF_ACTION_ID]
key, config = next((k, v) for k, v in full_config.items() if k in ACTION_REGISTRY)
builder = ACTION_REGISTRY[key][1]
for result in builder(config, action_id, template_arg, args):
yield None
yield result
builder = coroutine(ACTION_REGISTRY[key][1])
yield builder(config, action_id, template_arg, args)
@coroutine
def build_actions(config, templ, arg_type):
actions = []
for conf in config:
for action in build_action(conf, templ, arg_type):
yield None
action = yield build_action(conf, templ, arg_type)
actions.append(action)
yield actions
@coroutine
def build_condition(full_config, template_arg, args):
action_id = full_config[CONF_CONDITION_ID]
key, config = next((k, v) for k, v in full_config.items() if k in CONDITION_REGISTRY)
builder = CONDITION_REGISTRY[key][1]
for result in builder(config, action_id, template_arg, args):
yield None
yield result
builder = coroutine(CONDITION_REGISTRY[key][1])
yield builder(config, action_id, template_arg, args)
@coroutine
def build_conditions(config, templ, args):
conditions = []
for conf in config:
for condition in build_condition(conf, templ, args):
yield None
condition = yield build_condition(conf, templ, args)
conditions.append(condition)
yield conditions
@coroutine
def build_automation_(trigger, args, config):
arg_types = [arg[0] for arg in args]
templ = TemplateArguments(*arg_types)
rhs = App.make_automation(templ, trigger)
type = Automation.template(templ)
obj = Pvariable(config[CONF_AUTOMATION_ID], rhs, type=type)
for actions in build_actions(config[CONF_THEN], templ, args):
yield None
actions = yield build_actions(config[CONF_THEN], templ, args)
add(obj.add_actions(actions))
yield obj

View File

@ -108,8 +108,7 @@ HOMEASSISTANT_SERVIC_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_HOMEASSISTANT_SERVICE, HOMEASSISTANT_SERVIC_ACTION_SCHEMA)
def homeassistant_service_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_home_assistant_service_call_action(template_arg)
type = HomeAssistantServiceCallAction.template(template_arg)
act = Pvariable(action_id, rhs, type=type)
@ -123,8 +122,7 @@ def homeassistant_service_to_code(config, action_id, template_arg, args):
if CONF_VARIABLES in config:
datas = []
for key, value in config[CONF_VARIABLES].items():
for value_ in process_lambda(value, []):
yield None
value_ = yield process_lambda(value, [])
datas.append(TemplatableKeyValuePair(key, value_))
add(act.set_variables(datas))
yield act

View File

@ -10,7 +10,7 @@ from esphome.const import CONF_DELAYED_OFF, CONF_DELAYED_ON, CONF_DEVICE_CLASS,
CONF_LAMBDA, CONF_MAX_LENGTH, CONF_MIN_LENGTH, CONF_MQTT_ID, CONF_ON_CLICK, \
CONF_ON_DOUBLE_CLICK, CONF_ON_MULTI_CLICK, CONF_ON_PRESS, CONF_ON_RELEASE, CONF_ON_STATE, \
CONF_STATE, CONF_TIMING, CONF_TRIGGER_ID, CONF_FOR
from esphome.core import CORE
from esphome.core import CORE, coroutine
from esphome.cpp_generator import Pvariable, StructInitializer, add, get_variable, process_lambda
from esphome.cpp_types import App, Component, Nameable, Trigger, bool_, esphome_ns, optional
from esphome.py_compat import string_types
@ -196,6 +196,7 @@ BINARY_SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
BINARY_SENSOR_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(BINARY_SENSOR_SCHEMA.schema)
@coroutine
def setup_filter(config):
if CONF_INVERT in config:
yield InvertFilter.new()
@ -204,21 +205,20 @@ def setup_filter(config):
elif CONF_DELAYED_ON in config:
yield App.register_component(DelayedOnFilter.new(config[CONF_DELAYED_ON]))
elif CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(bool_, 'x')],
return_type=optional.template(bool_)):
yield None
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(bool_, 'x')],
return_type=optional.template(bool_))
yield LambdaFilter.new(lambda_)
@coroutine
def setup_filters(config):
filters = []
for conf in config:
for filter in setup_filter(conf):
yield None
filters.append(filter)
filters.append((yield setup_filter(conf)))
yield filters
@coroutine
def setup_binary_sensor_core_(binary_sensor_var, config):
if CONF_INTERNAL in config:
add(binary_sensor_var.set_internal(CONF_INTERNAL))
@ -227,8 +227,7 @@ def setup_binary_sensor_core_(binary_sensor_var, config):
if CONF_INVERTED in config:
add(binary_sensor_var.set_inverted(config[CONF_INVERTED]))
if CONF_FILTERS in config:
for filters in setup_filters(config[CONF_FILTERS]):
yield
filters = yield setup_filters(config[CONF_FILTERS])
add(binary_sensor_var.add_filters(filters))
for conf in config.get(CONF_ON_PRESS, []):
@ -298,8 +297,7 @@ BINARY_SENSOR_IS_ON_CONDITION_SCHEMA = maybe_simple_id({
@CONDITION_REGISTRY.register(CONF_BINARY_SENSOR_IS_ON, BINARY_SENSOR_IS_ON_CONDITION_SCHEMA)
def binary_sensor_is_on_to_code(config, condition_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_binary_sensor_is_on_condition(template_arg, config.get(CONF_FOR))
type = BinarySensorCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)
@ -314,8 +312,7 @@ BINARY_SENSOR_IS_OFF_CONDITION_SCHEMA = maybe_simple_id({
@CONDITION_REGISTRY.register(CONF_BINARY_SENSOR_IS_OFF, BINARY_SENSOR_IS_OFF_CONDITION_SCHEMA)
def binary_sensor_is_off_to_code(config, condition_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_binary_sensor_is_off_condition(template_arg, config.get(CONF_FOR))
type = BinarySensorCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)

View File

@ -25,8 +25,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_APDS9960_ID]):
yield
hub = yield get_variable(config[CONF_APDS9960_ID])
func = getattr(hub, DIRECTIONS[config[CONF_DIRECTION]])
rhs = func(config[CONF_NAME])
binary_sensor.register_binary_sensor(rhs, config)

View File

@ -20,9 +20,8 @@ PLATFORM_SCHEMA = binary_sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(binary_sensor.BinarySensorPtr)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(binary_sensor.BinarySensorPtr))
rhs = CustomBinarySensorConstructor(template_)
custom = variable(config[CONF_ID], rhs)

View File

@ -19,7 +19,6 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
yield
hub = yield get_variable(config[CONF_ESP32_BLE_ID])
rhs = hub.make_presence_sensor(config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS]))
binary_sensor.register_binary_sensor(rhs, config)

View File

@ -47,9 +47,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
hub = None
for hub in get_variable(config[CONF_ESP32_TOUCH_ID]):
yield
hub = yield get_variable(config[CONF_ESP32_TOUCH_ID])
touch_pad = TOUCH_PADS[config[CONF_PIN]]
rhs = hub.make_touch_pad(config[CONF_NAME], touch_pad, config[CONF_THRESHOLD])
binary_sensor.register_binary_sensor(rhs, config)

View File

@ -19,9 +19,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
pin = None
for pin in gpio_input_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_input_pin_expression(config[CONF_PIN])
rhs = App.make_gpio_binary_sensor(config[CONF_NAME], pin)
gpio = Pvariable(config[CONF_ID], rhs)
binary_sensor.setup_binary_sensor(gpio, config)

View File

@ -18,7 +18,6 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_MPR121_ID]):
yield
hub = yield get_variable(config[CONF_MPR121_ID])
rhs = MPR121Channel.new(config[CONF_NAME], config[CONF_CHANNEL])
binary_sensor.register_binary_sensor(hub.add_channel(rhs), config)

View File

@ -22,8 +22,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_NEXTION_ID]):
yield
hub = yield get_variable(config[CONF_NEXTION_ID])
rhs = hub.make_touch_component(config[CONF_NAME], config[CONF_PAGE_ID],
config[CONF_COMPONENT_ID])
binary_sensor.register_binary_sensor(rhs, config)

View File

@ -38,8 +38,7 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_PN532_ID]):
yield
hub = yield get_variable(config[CONF_PN532_ID])
addr = [HexInt(int(x, 16)) for x in config[CONF_UID].split('-')]
rhs = hub.make_tag(config[CONF_NAME], addr)
binary_sensor.register_binary_sensor(rhs, config)

View File

@ -20,7 +20,6 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_RDM6300_ID]):
yield
hub = yield get_variable(config[CONF_RDM6300_ID])
rhs = hub.make_card(config[CONF_NAME], config[CONF_UID])
binary_sensor.register_binary_sensor(rhs, config)

View File

@ -136,8 +136,7 @@ def receiver_base(full_config):
def to_code(config):
for remote in get_variable(config[CONF_REMOTE_RECEIVER_ID]):
yield
remote = yield get_variable(config[CONF_REMOTE_RECEIVER_ID])
rhs = receiver_base(config)
receiver = Pvariable(config[CONF_RECEIVER_ID], rhs)

View File

@ -27,9 +27,8 @@ def to_code(config):
setup_component(var, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(bool_)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(bool_))
add(var.set_template(template_))
@ -45,12 +44,10 @@ BINARY_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_BINARY_SENSOR_TEMPLATE_PUBLISH,
BINARY_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA)
def binary_sensor_template_publish_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_binary_sensor_publish_action(template_arg)
type = BinarySensorPublishAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_STATE], args, bool_):
yield None
template_ = yield templatable(config[CONF_STATE], args, bool_)
add(action.set_state(template_))
yield action

View File

@ -18,7 +18,6 @@ PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend
def to_code(config):
for hub in get_variable(config[CONF_TTP229_ID]):
yield
hub = yield get_variable(config[CONF_TTP229_ID])
rhs = TTP229Channel.new(config[CONF_NAME], config[CONF_CHANNEL])
binary_sensor.register_binary_sensor(hub.add_channel(rhs), config)

View File

@ -1,6 +1,5 @@
import voluptuous as vol
from esphome import core
from esphome.automation import ACTION_REGISTRY
from esphome.components import mqtt
from esphome.components.mqtt import setup_mqtt_component
@ -8,7 +7,7 @@ import esphome.config_validation as cv
from esphome.const import CONF_AWAY, CONF_ID, CONF_INTERNAL, CONF_MAX_TEMPERATURE, \
CONF_MIN_TEMPERATURE, CONF_MODE, CONF_MQTT_ID, CONF_TARGET_TEMPERATURE, \
CONF_TARGET_TEMPERATURE_HIGH, CONF_TARGET_TEMPERATURE_LOW, CONF_TEMPERATURE_STEP, CONF_VISUAL
from esphome.core import CORE
from esphome.core import CORE, coroutine
from esphome.cpp_generator import Pvariable, add, get_variable, templatable
from esphome.cpp_types import Action, App, Nameable, bool_, esphome_ns, float_
@ -49,6 +48,7 @@ CLIMATE_SCHEMA = cv.MQTT_COMMAND_COMPONENT_SCHEMA.extend({
CLIMATE_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(CLIMATE_SCHEMA.schema)
@coroutine
def setup_climate_core_(climate_var, config):
if CONF_INTERNAL in config:
add(climate_var.set_internal(config[CONF_INTERNAL]))
@ -84,32 +84,24 @@ CLIMATE_CONTROL_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_CLIMATE_CONTROL, CLIMATE_CONTROL_ACTION_SCHEMA)
def climate_control_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = ControlAction.template(template_arg)
rhs = type.new(var)
action = Pvariable(action_id, rhs, type=type)
if CONF_MODE in config:
if isinstance(config[CONF_MODE], core.Lambda):
for template_ in templatable(config[CONF_MODE], args, ClimateMode):
yield None
add(action.set_mode(template_))
else:
add(action.set_mode(CLIMATE_MODES[config[CONF_MODE]]))
template_ = yield templatable(config[CONF_MODE], args, ClimateMode,
to_exp=CLIMATE_MODES)
add(action.set_mode(template_))
if CONF_TARGET_TEMPERATURE in config:
for template_ in templatable(config[CONF_TARGET_TEMPERATURE], args, float_):
yield None
template_ = yield templatable(config[CONF_TARGET_TEMPERATURE], args, float_)
add(action.set_target_temperature(template_))
if CONF_TARGET_TEMPERATURE_LOW in config:
for template_ in templatable(config[CONF_TARGET_TEMPERATURE_LOW], args, float_):
yield None
template_ = yield templatable(config[CONF_TARGET_TEMPERATURE_LOW], args, float_)
add(action.set_target_temperature_low(template_))
if CONF_TARGET_TEMPERATURE_HIGH in config:
for template_ in templatable(config[CONF_TARGET_TEMPERATURE_HIGH], args, float_):
yield None
template_ = yield templatable(config[CONF_TARGET_TEMPERATURE_HIGH], args, float_)
add(action.set_target_temperature_high(template_))
if CONF_AWAY in config:
for template_ in templatable(config[CONF_AWAY], args, bool_):
yield None
template_ = yield templatable(config[CONF_AWAY], args, bool_)
add(action.set_away(template_))
yield action

View File

@ -35,8 +35,7 @@ def to_code(config):
climate.register_climate(control, config)
setup_component(control, config)
for var in get_variable(config[CONF_SENSOR]):
yield
var = yield get_variable(config[CONF_SENSOR])
add(control.set_sensor(var))
normal_config = BangBangClimateTargetTempConfig(

View File

@ -87,8 +87,7 @@ COVER_OPEN_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_COVER_OPEN, COVER_OPEN_ACTION_SCHEMA)
def cover_open_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = OpenAction.template(template_arg)
rhs = type.new(var)
yield Pvariable(action_id, rhs, type=type)
@ -102,8 +101,7 @@ COVER_CLOSE_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_COVER_CLOSE, COVER_CLOSE_ACTION_SCHEMA)
def cover_close_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = CloseAction.template(template_arg)
rhs = type.new(var)
yield Pvariable(action_id, rhs, type=type)
@ -117,8 +115,7 @@ COVER_STOP_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_COVER_STOP, COVER_STOP_ACTION_SCHEMA)
def cover_stop_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = StopAction.template(template_arg)
rhs = type.new(var)
yield Pvariable(action_id, rhs, type=type)
@ -136,26 +133,21 @@ COVER_CONTROL_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_COVER_CONTROL, COVER_CONTROL_ACTION_SCHEMA)
def cover_control_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = StopAction.template(template_arg)
rhs = type.new(var)
action = Pvariable(action_id, rhs, type=type)
if CONF_STOP in config:
for template_ in templatable(config[CONF_STOP], args, bool):
yield None
template_ = yield templatable(config[CONF_STOP], args, bool)
add(action.set_stop(template_))
if CONF_STATE in config:
for template_ in templatable(config[CONF_STATE], args, float,
to_exp=COVER_STATES):
yield None
template_ = yield templatable(config[CONF_STATE], args, float,
to_exp=COVER_STATES)
add(action.set_position(template_))
if CONF_POSITION in config:
for template_ in templatable(config[CONF_POSITION], args, float):
yield None
template_ = yield templatable(config[CONF_POSITION], args, float)
add(action.set_position(template_))
if CONF_TILT in config:
for template_ in templatable(config[CONF_TILT], args, float):
yield None
template_ = yield templatable(config[CONF_TILT], args, float)
add(action.set_tilt(template_))
yield action

View File

@ -36,15 +36,13 @@ def to_code(config):
automation.build_automations(var.get_stop_trigger(), [],
config[CONF_STOP_ACTION])
for bin in get_variable(config[CONF_OPEN_ENDSTOP]):
yield
bin = yield get_variable(config[CONF_OPEN_ENDSTOP])
add(var.set_open_endstop(bin))
add(var.set_open_duration(config[CONF_OPEN_DURATION]))
automation.build_automations(var.get_open_trigger(), [],
config[CONF_OPEN_ACTION])
for bin in get_variable(config[CONF_CLOSE_ENDSTOP]):
yield
bin = yield get_variable(config[CONF_CLOSE_ENDSTOP])
add(var.set_close_endstop(bin))
add(var.set_close_duration(config[CONF_CLOSE_DURATION]))
automation.build_automations(var.get_close_trigger(), [],

View File

@ -4,9 +4,9 @@ from esphome import automation
from esphome.automation import ACTION_REGISTRY
from esphome.components import cover
import esphome.config_validation as cv
from esphome.const import CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_ID, CONF_LAMBDA, CONF_NAME, \
CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_STATE, CONF_STOP_ACTION, CONF_POSITION, \
CONF_CURRENT_OPERATION, CONF_RESTORE_MODE
from esphome.const import CONF_ASSUMED_STATE, CONF_CLOSE_ACTION, CONF_CURRENT_OPERATION, CONF_ID, \
CONF_LAMBDA, CONF_NAME, CONF_OPEN_ACTION, CONF_OPTIMISTIC, CONF_POSITION, CONF_RESTORE_MODE, \
CONF_STATE, CONF_STOP_ACTION
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable
from esphome.cpp_helpers import setup_component
from esphome.cpp_types import Action, App, optional
@ -40,9 +40,8 @@ def to_code(config):
setup_component(var, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(float)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(float))
add(var.set_state_lambda(template_))
if CONF_OPEN_ACTION in config:
automation.build_automations(var.get_open_trigger(), [],
@ -75,24 +74,20 @@ COVER_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_COVER_TEMPLATE_PUBLISH,
COVER_TEMPLATE_PUBLISH_ACTION_SCHEMA)
def cover_template_publish_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = CoverPublishAction.template(template_arg)
rhs = type.new(var)
action = Pvariable(action_id, rhs, type=type)
if CONF_STATE in config:
for template_ in templatable(config[CONF_STATE], args, float,
to_exp=cover.COVER_STATES):
yield None
template_ = yield templatable(config[CONF_STATE], args, float,
to_exp=cover.COVER_STATES)
add(action.set_position(template_))
if CONF_POSITION in config:
for template_ in templatable(config[CONF_POSITION], args, float,
to_exp=cover.COVER_STATES):
yield None
template_ = yield templatable(config[CONF_POSITION], args, float,
to_exp=cover.COVER_STATES)
add(action.set_position(template_))
if CONF_CURRENT_OPERATION in config:
for template_ in templatable(config[CONF_CURRENT_OPERATION], args, cover.CoverOperation,
to_exp=cover.COVER_OPERATIONS):
yield None
template_ = yield templatable(config[CONF_CURRENT_OPERATION], args, cover.CoverOperation,
to_exp=cover.COVER_OPERATIONS)
add(action.set_current_operation(template_))
yield action

View File

@ -19,9 +19,8 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(ComponentPtr)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(ComponentPtr))
rhs = CustomComponentConstructor(template_)
custom = variable(config[CONF_ID], rhs)

View File

@ -63,8 +63,7 @@ def to_code(config):
if CONF_SLEEP_DURATION in config:
add(deep_sleep.set_sleep_duration(config[CONF_SLEEP_DURATION]))
if CONF_WAKEUP_PIN in config:
for pin in gpio_input_pin_expression(config[CONF_WAKEUP_PIN]):
yield
pin = yield gpio_input_pin_expression(config[CONF_WAKEUP_PIN])
add(deep_sleep.set_wakeup_pin(pin))
if CONF_WAKEUP_PIN_MODE in config:
add(deep_sleep.set_wakeup_pin_mode(WAKEUP_PIN_MODES[config[CONF_WAKEUP_PIN_MODE]]))
@ -96,8 +95,7 @@ DEEP_SLEEP_ENTER_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_DEEP_SLEEP_ENTER, DEEP_SLEEP_ENTER_ACTION_SCHEMA)
def deep_sleep_enter_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_enter_deep_sleep_action(template_arg)
type = EnterDeepSleepAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -111,8 +109,7 @@ DEEP_SLEEP_PREVENT_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_DEEP_SLEEP_PREVENT, DEEP_SLEEP_PREVENT_ACTION_SCHEMA)
def deep_sleep_prevent_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_prevent_deep_sleep_action(template_arg)
type = PreventDeepSleepAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)

View File

@ -4,10 +4,10 @@ import voluptuous as vol
from esphome import core
from esphome.automation import ACTION_REGISTRY, maybe_simple_id
import esphome.config_validation as cv
from esphome.const import CONF_LAMBDA, CONF_ROTATION, CONF_UPDATE_INTERVAL, CONF_PAGES, CONF_ID
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES, CONF_ROTATION, CONF_UPDATE_INTERVAL
from esphome.core import CORE
from esphome.cpp_generator import add, process_lambda, Pvariable, templatable, get_variable
from esphome.cpp_types import esphome_ns, void, Action
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable
from esphome.cpp_types import Action, esphome_ns, void
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
@ -63,9 +63,8 @@ def setup_display_core_(display_var, config):
if CONF_PAGES in config:
pages = []
for conf in config[CONF_PAGES]:
for lambda_ in process_lambda(conf[CONF_LAMBDA], [(DisplayBufferRef, 'it')],
return_type=void):
yield
lambda_ = yield process_lambda(conf[CONF_LAMBDA], [(DisplayBufferRef, 'it')],
return_type=void)
var = Pvariable(conf[CONF_ID], DisplayPage.new(lambda_))
pages.append(var)
add(display_var.set_pages(pages))
@ -82,12 +81,10 @@ def display_page_show_to_code(config, action_id, template_arg, args):
type = DisplayPageShowAction.template(template_arg)
action = Pvariable(action_id, type.new(), type=type)
if isinstance(config[CONF_ID], core.Lambda):
for template_ in templatable(config[CONF_ID], args, DisplayPagePtr):
yield None
template_ = yield templatable(config[CONF_ID], args, DisplayPagePtr)
add(action.set_page(template_))
else:
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
add(action.set_page(var))
yield action
@ -100,8 +97,7 @@ DISPLAY_PAGE_SHOW_NEXT_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_DISPLAY_PAGE_SHOW_NEXT, DISPLAY_PAGE_SHOW_NEXT_ACTION_SCHEMA)
def display_page_show_next_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = DisplayPageShowNextAction.template(template_arg)
yield Pvariable(action_id, type.new(var), type=type)
@ -114,8 +110,7 @@ DISPLAY_PAGE_SHOW_PREVIOUS_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_DISPLAY_PAGE_SHOW_PREVIOUS, DISPLAY_PAGE_SHOW_PREVIOUS_ACTION_SCHEMA)
def display_page_show_previous_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = DisplayPageShowPrevAction.template(template_arg)
yield Pvariable(action_id, type.new(var), type=type)

View File

@ -46,27 +46,21 @@ def to_code(config):
lcd = Pvariable(config[CONF_ID], rhs)
pins_ = []
for conf in config[CONF_DATA_PINS]:
for pin in gpio_output_pin_expression(conf):
yield
pins_.append(pin)
pins_.append((yield gpio_output_pin_expression(conf)))
add(lcd.set_data_pins(*pins_))
for enable in gpio_output_pin_expression(config[CONF_ENABLE_PIN]):
yield
enable = yield gpio_output_pin_expression(config[CONF_ENABLE_PIN])
add(lcd.set_enable_pin(enable))
for rs in gpio_output_pin_expression(config[CONF_RS_PIN]):
yield
rs = yield gpio_output_pin_expression(config[CONF_RS_PIN])
add(lcd.set_rs_pin(rs))
if CONF_RW_PIN in config:
for rw in gpio_output_pin_expression(config[CONF_RW_PIN]):
yield
rw = yield gpio_output_pin_expression(config[CONF_RW_PIN])
add(lcd.set_rw_pin(rw))
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')],
return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')],
return_type=void)
add(lcd.set_writer(lambda_))
display.setup_display(lcd, config)

View File

@ -28,9 +28,8 @@ def to_code(config):
add(lcd.set_address(config[CONF_ADDRESS]))
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')],
return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(LCDDisplayRef, 'it')],
return_type=void)
add(lcd.set_writer(lambda_))
display.setup_display(lcd, config)

View File

@ -26,10 +26,8 @@ PLATFORM_SCHEMA = display.BASIC_DISPLAY_PLATFORM_SCHEMA.extend({
def to_code(config):
for spi_ in get_variable(config[CONF_SPI_ID]):
yield
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
yield
spi_ = yield get_variable(config[CONF_SPI_ID])
cs = yield gpio_output_pin_expression(config[CONF_CS_PIN])
rhs = App.make_max7219(spi_, cs)
max7219 = Pvariable(config[CONF_ID], rhs)
@ -39,9 +37,8 @@ def to_code(config):
add(max7219.set_intensity(config[CONF_INTENSITY]))
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')],
return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(MAX7219ComponentRef, 'it')],
return_type=void)
add(max7219.set_writer(lambda_))
display.setup_display(max7219, config)

View File

@ -18,15 +18,13 @@ PLATFORM_SCHEMA = display.BASIC_DISPLAY_PLATFORM_SCHEMA.extend({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
rhs = App.make_nextion(uart_)
nextion = Pvariable(config[CONF_ID], rhs)
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(NextionRef, 'it')],
return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(NextionRef, 'it')],
return_type=void)
add(nextion.set_writer(lambda_))
display.setup_display(nextion, config)

View File

@ -28,17 +28,15 @@ def to_code(config):
add(ssd.set_model(ssd1306_spi.MODELS[config[CONF_MODEL]]))
if CONF_RESET_PIN in config:
for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
yield
reset = yield gpio_output_pin_expression(config[CONF_RESET_PIN])
add(ssd.set_reset_pin(reset))
if CONF_EXTERNAL_VCC in config:
add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC]))
if CONF_ADDRESS in config:
add(ssd.set_address(config[CONF_ADDRESS]))
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA],
[(display.DisplayBufferRef, 'it')], return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA],
[(display.DisplayBufferRef, 'it')], return_type=void)
add(ssd.set_writer(lambda_))
display.setup_display(ssd, config)

View File

@ -5,7 +5,7 @@ from esphome.components import display, spi
from esphome.components.spi import SPIComponent
import esphome.config_validation as cv
from esphome.const import CONF_CS_PIN, CONF_DC_PIN, CONF_EXTERNAL_VCC, CONF_ID, CONF_LAMBDA, \
CONF_MODEL, CONF_RESET_PIN, CONF_SPI_ID, CONF_PAGES
CONF_MODEL, CONF_PAGES, CONF_RESET_PIN, CONF_SPI_ID
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda
from esphome.cpp_helpers import gpio_output_pin_expression, setup_component
from esphome.cpp_types import App, PollingComponent, void
@ -41,27 +41,22 @@ PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
def to_code(config):
for spi_ in get_variable(config[CONF_SPI_ID]):
yield
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
yield
for dc in gpio_output_pin_expression(config[CONF_DC_PIN]):
yield
spi_ = yield get_variable(config[CONF_SPI_ID])
cs = yield gpio_output_pin_expression(config[CONF_CS_PIN])
dc = yield gpio_output_pin_expression(config[CONF_DC_PIN])
rhs = App.make_spi_ssd1306(spi_, cs, dc)
ssd = Pvariable(config[CONF_ID], rhs)
add(ssd.set_model(MODELS[config[CONF_MODEL]]))
if CONF_RESET_PIN in config:
for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
yield
reset = yield gpio_output_pin_expression(config[CONF_RESET_PIN])
add(ssd.set_reset_pin(reset))
if CONF_EXTERNAL_VCC in config:
add(ssd.set_external_vcc(config[CONF_EXTERNAL_VCC]))
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA],
[(display.DisplayBufferRef, 'it')], return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA],
[(display.DisplayBufferRef, 'it')], return_type=void)
add(ssd.set_writer(lambda_))
display.setup_display(ssd, config)

View File

@ -53,12 +53,9 @@ PLATFORM_SCHEMA = vol.All(display.FULL_DISPLAY_PLATFORM_SCHEMA.extend({
def to_code(config):
for spi_ in get_variable(config[CONF_SPI_ID]):
yield
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
yield
for dc in gpio_output_pin_expression(config[CONF_DC_PIN]):
yield
spi_ = yield get_variable(config[CONF_SPI_ID])
cs = yield gpio_output_pin_expression(config[CONF_CS_PIN])
dc = yield gpio_output_pin_expression(config[CONF_DC_PIN])
model_type, model = MODELS[config[CONF_MODEL]]
if model_type == 'a':
@ -71,17 +68,14 @@ def to_code(config):
raise NotImplementedError()
if CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')],
return_type=void):
yield
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(display.DisplayBufferRef, 'it')],
return_type=void)
add(epaper.set_writer(lambda_))
if CONF_RESET_PIN in config:
for reset in gpio_output_pin_expression(config[CONF_RESET_PIN]):
yield
reset = yield gpio_output_pin_expression(config[CONF_RESET_PIN])
add(epaper.set_reset_pin(reset))
if CONF_BUSY_PIN in config:
for reset in gpio_input_pin_expression(config[CONF_BUSY_PIN]):
yield
reset = yield gpio_input_pin_expression(config[CONF_BUSY_PIN])
add(epaper.set_busy_pin(reset))
if CONF_FULL_UPDATE_EVERY in config:
add(epaper.set_full_update_every(config[CONF_FULL_UPDATE_EVERY]))

View File

@ -74,8 +74,7 @@ def to_code(config):
add(eth.set_use_address(config[CONF_USE_ADDRESS]))
if CONF_POWER_PIN in config:
for pin in gpio_output_pin_expression(config[CONF_POWER_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_POWER_PIN])
add(eth.set_power_pin(pin))
if CONF_MANUAL_IP in config:

View File

@ -10,7 +10,6 @@ from esphome.const import CONF_ID, CONF_INTERNAL, CONF_MQTT_ID, CONF_OSCILLATING
from esphome.core import CORE
from esphome.cpp_generator import Pvariable, add, get_variable, templatable
from esphome.cpp_types import Action, Application, Component, Nameable, bool_, esphome_ns
from esphome.py_compat import string_types
PLATFORM_SCHEMA = cv.PLATFORM_SCHEMA.extend({
@ -82,8 +81,7 @@ FAN_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_FAN_TOGGLE, FAN_TOGGLE_ACTION_SCHEMA)
def fan_toggle_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_toggle_action(template_arg)
type = ToggleAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -97,8 +95,7 @@ FAN_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_FAN_TURN_OFF, FAN_TURN_OFF_ACTION_SCHEMA)
def fan_turn_off_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_turn_off_action(template_arg)
type = TurnOffAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -114,19 +111,15 @@ FAN_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_FAN_TURN_ON, FAN_TURN_ON_ACTION_SCHEMA)
def fan_turn_on_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_turn_on_action(template_arg)
type = TurnOnAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
if CONF_OSCILLATING in config:
for template_ in templatable(config[CONF_OSCILLATING], args, bool_):
yield None
template_ = yield templatable(config[CONF_OSCILLATING], args, bool_)
add(action.set_oscillating(template_))
if CONF_SPEED in config:
for template_ in templatable(config[CONF_SPEED], args, FanSpeed):
yield None
if isinstance(template_, string_types):
template_ = FAN_SPEEDS[template_]
template_ = yield templatable(config[CONF_SPEED], args, FanSpeed,
to_exp=FAN_SPEEDS)
add(action.set_speed(template_))
yield action

View File

@ -15,15 +15,13 @@ PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
def to_code(config):
for output_ in get_variable(config[CONF_OUTPUT]):
yield
output_ = yield get_variable(config[CONF_OUTPUT])
rhs = App.make_fan(config[CONF_NAME])
fan_struct = variable(config[CONF_MAKE_ID], rhs)
add(fan_struct.Poutput.set_binary(output_))
if CONF_OSCILLATION_OUTPUT in config:
for oscillation_output in get_variable(config[CONF_OSCILLATION_OUTPUT]):
yield
oscillation_output = yield get_variable(config[CONF_OSCILLATION_OUTPUT])
add(fan_struct.Poutput.set_oscillation(oscillation_output))
fan.setup_fan(fan_struct.Pstate, config)

View File

@ -23,8 +23,7 @@ PLATFORM_SCHEMA = cv.nameable(fan.FAN_PLATFORM_SCHEMA.extend({
def to_code(config):
for output_ in get_variable(config[CONF_OUTPUT]):
yield
output_ = yield get_variable(config[CONF_OUTPUT])
rhs = App.make_fan(config[CONF_NAME])
fan_struct = variable(config[CONF_MAKE_ID], rhs)
if CONF_SPEED in config:
@ -37,8 +36,7 @@ def to_code(config):
add(fan_struct.Poutput.set_speed(output_))
if CONF_OSCILLATION_OUTPUT in config:
for oscillation_output in get_variable(config[CONF_OSCILLATION_OUTPUT]):
yield
oscillation_output = yield get_variable(config[CONF_OSCILLATION_OUTPUT])
add(fan_struct.Poutput.set_oscillation(oscillation_output))
fan.setup_fan(fan_struct.Pstate, config)

View File

@ -9,7 +9,7 @@ from esphome.const import CONF_ALPHA, CONF_BLUE, CONF_BRIGHTNESS, CONF_COLORS, C
CONF_EFFECTS, CONF_EFFECT_ID, CONF_FLASH_LENGTH, CONF_GAMMA_CORRECT, CONF_GREEN, CONF_ID, \
CONF_INTERNAL, CONF_LAMBDA, CONF_MQTT_ID, CONF_NAME, CONF_NUM_LEDS, CONF_RANDOM, CONF_RED, \
CONF_SPEED, CONF_STATE, CONF_TRANSITION_LENGTH, CONF_UPDATE_INTERVAL, CONF_WHITE, CONF_WIDTH
from esphome.core import CORE
from esphome.core import CORE, coroutine
from esphome.cpp_generator import Pvariable, StructInitializer, add, get_variable, process_lambda, \
templatable
from esphome.cpp_types import Action, Application, Component, Nameable, esphome_ns, std_string, \
@ -269,12 +269,11 @@ ADDRESSABLE_LIGHT_SCHEMA = RGB_LIGHT_SCHEMA.extend({
})
@coroutine
def build_effect(full_config):
key, config = next(iter(full_config.items()))
if key == CONF_LAMBDA:
lambda_ = None
for lambda_ in process_lambda(config[CONF_LAMBDA], [], return_type=void):
yield None
lambda_ = yield process_lambda(config[CONF_LAMBDA], [], return_type=void)
yield LambdaLightEffect.new(config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL])
elif key == CONF_RANDOM:
rhs = RandomLightEffect.new(config[CONF_NAME])
@ -309,8 +308,7 @@ def build_effect(full_config):
yield effect
elif key == CONF_ADDRESSABLE_LAMBDA:
args = [(AddressableLightRef, 'it')]
for lambda_ in process_lambda(config[CONF_LAMBDA], args, return_type=void):
yield None
lambda_ = yield process_lambda(config[CONF_LAMBDA], args, return_type=void)
yield AddressableLambdaLightEffect.new(config[CONF_NAME], lambda_,
config[CONF_UPDATE_INTERVAL])
elif key == CONF_ADDRESSABLE_RAINBOW:
@ -388,6 +386,7 @@ def build_effect(full_config):
raise NotImplementedError("Effect {} not implemented".format(next(config.keys())))
@coroutine
def setup_light_core_(light_var, output_var, config):
if CONF_INTERNAL in config:
add(light_var.set_internal(config[CONF_INTERNAL]))
@ -397,8 +396,7 @@ def setup_light_core_(light_var, output_var, config):
add(light_var.set_gamma_correct(config[CONF_GAMMA_CORRECT]))
effects = []
for conf in config.get(CONF_EFFECTS, []):
for effect in build_effect(conf):
yield
effect = yield build_effect(conf)
effects.append(effect)
if effects:
add(light_var.add_effects(effects))
@ -425,14 +423,12 @@ LIGHT_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_LIGHT_TOGGLE, LIGHT_TOGGLE_ACTION_SCHEMA)
def light_toggle_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = ToggleAction.template(template_arg)
rhs = type.new(var)
action = Pvariable(action_id, rhs, type=type)
if CONF_TRANSITION_LENGTH in config:
for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
yield None
template_ = yield templatable(config[CONF_TRANSITION_LENGTH], args, uint32)
add(action.set_transition_length(template_))
yield action
@ -446,14 +442,12 @@ LIGHT_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_LIGHT_TURN_OFF, LIGHT_TURN_OFF_ACTION_SCHEMA)
def light_turn_off_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = LightControlAction.template(template_arg)
rhs = type.new(var)
action = Pvariable(action_id, rhs, type=type)
if CONF_TRANSITION_LENGTH in config:
for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
yield None
template_ = yield templatable(config[CONF_TRANSITION_LENGTH], args, uint32)
add(action.set_transition_length(template_))
yield action
@ -490,49 +484,38 @@ LIGHT_TURN_ON_ACTION_SCHEMA = maybe_simple_id(LIGHT_CONTROL_ACTION_SCHEMA.extend
@ACTION_REGISTRY.register(CONF_LIGHT_TURN_ON, LIGHT_TURN_ON_ACTION_SCHEMA)
@ACTION_REGISTRY.register(CONF_LIGHT_CONTROL, LIGHT_CONTROL_ACTION_SCHEMA)
def light_control_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
type = LightControlAction.template(template_arg)
rhs = type.new(var)
action = Pvariable(action_id, rhs, type=type)
if CONF_STATE in config:
for template_ in templatable(config[CONF_STATE], args, bool):
yield None
template_ = yield templatable(config[CONF_STATE], args, bool)
add(action.set_state(template_))
if CONF_TRANSITION_LENGTH in config:
for template_ in templatable(config[CONF_TRANSITION_LENGTH], args, uint32):
yield None
template_ = yield templatable(config[CONF_TRANSITION_LENGTH], args, uint32)
add(action.set_transition_length(template_))
if CONF_FLASH_LENGTH in config:
for template_ in templatable(config[CONF_FLASH_LENGTH], args, uint32):
yield None
template_ = yield templatable(config[CONF_FLASH_LENGTH], args, uint32)
add(action.set_flash_length(template_))
if CONF_BRIGHTNESS in config:
for template_ in templatable(config[CONF_BRIGHTNESS], args, float):
yield None
template_ = yield templatable(config[CONF_BRIGHTNESS], args, float)
add(action.set_brightness(template_))
if CONF_RED in config:
for template_ in templatable(config[CONF_RED], args, float):
yield None
template_ = yield templatable(config[CONF_RED], args, float)
add(action.set_red(template_))
if CONF_GREEN in config:
for template_ in templatable(config[CONF_GREEN], args, float):
yield None
template_ = yield templatable(config[CONF_GREEN], args, float)
add(action.set_green(template_))
if CONF_BLUE in config:
for template_ in templatable(config[CONF_BLUE], args, float):
yield None
template_ = yield templatable(config[CONF_BLUE], args, float)
add(action.set_blue(template_))
if CONF_WHITE in config:
for template_ in templatable(config[CONF_WHITE], args, float):
yield None
template_ = yield templatable(config[CONF_WHITE], args, float)
add(action.set_white(template_))
if CONF_COLOR_TEMPERATURE in config:
for template_ in templatable(config[CONF_COLOR_TEMPERATURE], args, float):
yield None
template_ = yield templatable(config[CONF_COLOR_TEMPERATURE], args, float)
add(action.set_color_temperature(template_))
if CONF_EFFECT in config:
for template_ in templatable(config[CONF_EFFECT], args, std_string):
yield None
template_ = yield templatable(config[CONF_EFFECT], args, std_string)
add(action.set_effect(template_))
yield action

View File

@ -14,8 +14,7 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
for output_ in get_variable(config[CONF_OUTPUT]):
yield
output_ = yield get_variable(config[CONF_OUTPUT])
rhs = App.make_binary_light(config[CONF_NAME], output_)
light_struct = variable(config[CONF_MAKE_ID], rhs)
light.setup_light(light_struct.Pstate, light_struct.Poutput, config)

View File

@ -20,10 +20,8 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
for cold_white in get_variable(config[CONF_COLD_WHITE]):
yield
for warm_white in get_variable(config[CONF_WARM_WHITE]):
yield
cold_white = yield get_variable(config[CONF_COLD_WHITE])
warm_white = yield get_variable(config[CONF_WARM_WHITE])
rhs = App.make_cwww_light(config[CONF_NAME], config[CONF_COLD_WHITE_COLOR_TEMPERATURE],
config[CONF_WARM_WHITE_COLOR_TEMPERATURE],
cold_white, warm_white)

View File

@ -85,8 +85,7 @@ def to_code(config):
add(fast_led.set_max_refresh_rate(config[CONF_MAX_REFRESH_RATE]))
if CONF_POWER_SUPPLY in config:
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
power_supply = yield get_variable(config[CONF_POWER_SUPPLY])
add(fast_led.set_power_supply(power_supply))
light.setup_light(make.Pstate, make.Pfast_led, config)

View File

@ -68,8 +68,7 @@ def to_code(config):
add(fast_led.set_max_refresh_rate(config[CONF_MAX_REFRESH_RATE]))
if CONF_POWER_SUPPLY in config:
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
power_supply = yield get_variable(config[CONF_POWER_SUPPLY])
add(fast_led.set_power_supply(power_supply))
light.setup_light(make.Pstate, make.Pfast_led, config)

View File

@ -14,8 +14,7 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
for output_ in get_variable(config[CONF_OUTPUT]):
yield
output_ = yield get_variable(config[CONF_OUTPUT])
rhs = App.make_monochromatic_light(config[CONF_NAME], output_)
light_struct = variable(config[CONF_MAKE_ID], rhs)
light.setup_light(light_struct.Pstate, light_struct.Poutput, config)

View File

@ -169,8 +169,7 @@ def to_code(config):
add(output.set_pixel_order(getattr(ESPNeoPixelOrder, type_)))
if CONF_POWER_SUPPLY in config:
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
power_supply = yield get_variable(config[CONF_POWER_SUPPLY])
add(output.set_power_supply(power_supply))
light.setup_light(make.Pstate, output, config)

View File

@ -34,8 +34,7 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
segments = []
for conf in config[CONF_SEGMENTS]:
for var in get_variable(conf[CONF_ID]):
yield
var = yield get_variable(conf[CONF_ID])
segments.append(AddressableSegment(var, conf[CONF_FROM],
conf[CONF_TO] - conf[CONF_FROM] + 1))

View File

@ -16,12 +16,9 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
for red in get_variable(config[CONF_RED]):
yield
for green in get_variable(config[CONF_GREEN]):
yield
for blue in get_variable(config[CONF_BLUE]):
yield
red = yield get_variable(config[CONF_RED])
green = yield get_variable(config[CONF_GREEN])
blue = yield get_variable(config[CONF_BLUE])
rhs = App.make_rgb_light(config[CONF_NAME], red, green, blue)
light_struct = variable(config[CONF_MAKE_ID], rhs)
light.setup_light(light_struct.Pstate, light_struct.Poutput, config)

View File

@ -17,14 +17,10 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
for red in get_variable(config[CONF_RED]):
yield
for green in get_variable(config[CONF_GREEN]):
yield
for blue in get_variable(config[CONF_BLUE]):
yield
for white in get_variable(config[CONF_WHITE]):
yield
red = yield get_variable(config[CONF_RED])
green = yield get_variable(config[CONF_GREEN])
blue = yield get_variable(config[CONF_BLUE])
white = yield get_variable(config[CONF_WHITE])
rhs = App.make_rgbw_light(config[CONF_NAME], red, green, blue, white)
light_struct = variable(config[CONF_MAKE_ID], rhs)
light.setup_light(light_struct.Pstate, light_struct.Poutput, config)

View File

@ -34,16 +34,11 @@ PLATFORM_SCHEMA = cv.nameable(light.PLATFORM_SCHEMA.extend({
def to_code(config):
for red in get_variable(config[CONF_RED]):
yield
for green in get_variable(config[CONF_GREEN]):
yield
for blue in get_variable(config[CONF_BLUE]):
yield
for cold_white in get_variable(config[CONF_COLD_WHITE]):
yield
for warm_white in get_variable(config[CONF_WARM_WHITE]):
yield
red = yield get_variable(config[CONF_RED])
green = yield get_variable(config[CONF_GREEN])
blue = yield get_variable(config[CONF_BLUE])
cold_white = yield get_variable(config[CONF_COLD_WHITE])
warm_white = yield get_variable(config[CONF_WARM_WHITE])
rhs = App.make_rgbww_light(config[CONF_NAME], config[CONF_COLD_WHITE_COLOR_TEMPERATURE],
config[CONF_WARM_WHITE_COLOR_TEMPERATURE],
red, green, blue, cold_white, warm_white)

View File

@ -177,8 +177,7 @@ def logger_log_action_to_code(config, action_id, template_arg, args):
text = text_type(statement(esp_log(config[CONF_TAG], config[CONF_FORMAT], *args_)))
for lambda_ in process_lambda(Lambda(text), args, return_type=void):
yield None
lambda_ = yield process_lambda(Lambda(text), args, return_type=void)
rhs = LambdaAction.new(template_arg, lambda_)
type = LambdaAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)

View File

@ -203,25 +203,20 @@ MQTT_PUBLISH_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH, MQTT_PUBLISH_ACTION_SCHEMA)
def mqtt_publish_action_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_publish_action(template_arg)
type = MQTTPublishAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_TOPIC], args, std_string):
yield None
template_ = yield templatable(config[CONF_TOPIC], args, std_string)
add(action.set_topic(template_))
for template_ in templatable(config[CONF_PAYLOAD], args, std_string):
yield None
template_ = yield templatable(config[CONF_PAYLOAD], args, std_string)
add(action.set_payload(template_))
if CONF_QOS in config:
for template_ in templatable(config[CONF_QOS], args, uint8):
yield
template_ = yield templatable(config[CONF_QOS], args, uint8)
add(action.set_qos(template_))
if CONF_RETAIN in config:
for template_ in templatable(config[CONF_RETAIN], args, bool_):
yield None
template_ = yield templatable(config[CONF_RETAIN], args, bool_)
add(action.set_retain(template_))
yield action
@ -238,18 +233,15 @@ MQTT_PUBLISH_JSON_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_MQTT_PUBLISH_JSON, MQTT_PUBLISH_JSON_ACTION_SCHEMA)
def mqtt_publish_json_action_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_publish_json_action(template_arg)
type = MQTTPublishJsonAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_TOPIC], args, std_string):
yield None
template_ = yield templatable(config[CONF_TOPIC], args, std_string)
add(action.set_topic(template_))
args_ = args + [(JsonObjectRef, 'root')]
for lambda_ in process_lambda(config[CONF_PAYLOAD], args_, return_type=void):
yield None
lambda_ = yield process_lambda(config[CONF_PAYLOAD], args_, return_type=void)
add(action.set_payload(lambda_))
if CONF_QOS in config:
add(action.set_qos(config[CONF_QOS]))

View File

@ -26,10 +26,8 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for di in gpio_output_pin_expression(config[CONF_DATA_PIN]):
yield
for dcki in gpio_output_pin_expression(config[CONF_CLOCK_PIN]):
yield
di = yield gpio_output_pin_expression(config[CONF_DATA_PIN])
dcki = yield gpio_output_pin_expression(config[CONF_CLOCK_PIN])
rhs = App.make_my9231_component(di, dcki)
my9231 = Pvariable(config[CONF_ID], rhs)
if CONF_NUM_CHANNELS in config:

View File

@ -43,9 +43,7 @@ def setup_output_platform_(obj, config, skip_power_supply=False):
if CONF_INVERTED in config:
add(obj.set_inverted(config[CONF_INVERTED]))
if not skip_power_supply and CONF_POWER_SUPPLY in config:
power_supply = None
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
power_supply = yield get_variable(config[CONF_POWER_SUPPLY])
add(obj.set_power_supply(power_supply))
if CONF_MAX_POWER in config:
add(obj.set_max_power(config[CONF_MAX_POWER]))
@ -72,8 +70,7 @@ OUTPUT_TURN_ON_ACTION = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_ON, OUTPUT_TURN_ON_ACTION)
def output_turn_on_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_turn_on_action(template_arg)
type = TurnOnAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -87,8 +84,7 @@ OUTPUT_TURN_OFF_ACTION = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_OUTPUT_TURN_OFF, OUTPUT_TURN_OFF_ACTION)
def output_turn_off_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_turn_off_action(template_arg)
type = TurnOffAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -103,12 +99,10 @@ OUTPUT_SET_LEVEL_ACTION = cv.Schema({
@ACTION_REGISTRY.register(CONF_OUTPUT_SET_LEVEL, OUTPUT_SET_LEVEL_ACTION)
def output_set_level_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_set_level_action(template_arg)
type = SetLevelAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_LEVEL], args, float_):
yield None
template_ = yield templatable(config[CONF_LEVEL], args, float_)
add(action.set_level(template_))
yield action

View File

@ -40,9 +40,7 @@ PLATFORM_SCHEMA = validate_copy_output
def to_code(config):
outputs = []
for out in config[CONF_OUTPUTS]:
for var in get_variable(out):
yield
outputs.append(var)
outputs.append((yield get_variable(out)))
klass = {
'binary': BinaryCopyOutput,

View File

@ -55,9 +55,8 @@ def to_code(config):
else:
ret_type = output.FloatOutputPtr
klass = CustomFloatOutputConstructor
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(ret_type)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(ret_type))
rhs = klass(template_)
custom = variable(config[CONF_ID], rhs)

View File

@ -27,8 +27,7 @@ PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_esp8266_pwm_output(pin)
gpio = Pvariable(config[CONF_ID], rhs)

View File

@ -18,8 +18,7 @@ PLATFORM_SCHEMA = output.BINARY_OUTPUT_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_gpio_output(pin)
gpio = Pvariable(config[CONF_ID], rhs)
output.setup_output_platform(gpio, config)

View File

@ -22,11 +22,8 @@ PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
def to_code(config):
power_supply = None
if CONF_POWER_SUPPLY in config:
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
my9231 = None
for my9231 in get_variable(config[CONF_MY9231_ID]):
yield
power_supply = yield get_variable(config[CONF_POWER_SUPPLY])
my9231 = yield get_variable(config[CONF_MY9231_ID])
rhs = my9231.create_channel(config[CONF_CHANNEL], power_supply)
out = Pvariable(config[CONF_ID], rhs)
output.setup_output_platform(out, config, skip_power_supply=True)

View File

@ -21,10 +21,8 @@ PLATFORM_SCHEMA = output.FLOAT_OUTPUT_PLATFORM_SCHEMA.extend({
def to_code(config):
power_supply = None
if CONF_POWER_SUPPLY in config:
for power_supply in get_variable(config[CONF_POWER_SUPPLY]):
yield
for pca9685 in get_variable(config[CONF_PCA9685_ID]):
yield
power_supply = yield get_variable(config[CONF_POWER_SUPPLY])
pca9685 = yield get_variable(config[CONF_PCA9685_ID])
rhs = pca9685.create_channel(config[CONF_CHANNEL], power_supply)
out = Pvariable(config[CONF_ID], rhs)
output.setup_output_platform(out, config, skip_power_supply=True)

View File

@ -29,10 +29,8 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for spi_ in get_variable(config[CONF_SPI_ID]):
yield
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
yield
spi_ = yield get_variable(config[CONF_SPI_ID])
cs = yield gpio_output_pin_expression(config[CONF_CS_PIN])
rhs = App.make_pn532_component(spi_, cs, config.get(CONF_UPDATE_INTERVAL))
pn532 = Pvariable(config[CONF_ID], rhs)

View File

@ -20,8 +20,7 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_power_supply(pin)
psu = Pvariable(config[CONF_ID], rhs)

View File

@ -17,8 +17,7 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
rhs = App.make_rdm6300_component(uart_)
var = Pvariable(config[CONF_ID], rhs)
setup_component(var, config)

View File

@ -54,8 +54,7 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for pin in gpio_input_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_input_pin_expression(config[CONF_PIN])
rhs = App.make_remote_receiver_component(pin)
receiver = Pvariable(config[CONF_ID], rhs)

View File

@ -106,8 +106,7 @@ def binary_code(value):
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_remote_transmitter_component(pin)
transmitter = Pvariable(config[CONF_ID], rhs)

View File

@ -30,8 +30,7 @@ SCRIPT_EXECUTE_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_SCRIPT_EXECUTE, SCRIPT_EXECUTE_ACTION_SCHEMA)
def script_execute_action_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_execute_action(template_arg)
type = ScriptExecuteAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -45,8 +44,7 @@ SCRIPT_STOP_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_SCRIPT_STOP, SCRIPT_STOP_ACTION_SCHEMA)
def script_stop_action_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_stop_action(template_arg)
type = ScriptStopAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)

View File

@ -15,7 +15,7 @@ from esphome.const import CONF_ABOVE, CONF_ACCURACY_DECIMALS, CONF_ALPHA, CONF_B
CONF_SEND_EVERY, CONF_SEND_FIRST_AT, CONF_SLIDING_WINDOW_MOVING_AVERAGE, \
CONF_THROTTLE, CONF_TO, CONF_TRIGGER_ID, CONF_UNIQUE, CONF_UNIT_OF_MEASUREMENT, \
CONF_WINDOW_SIZE
from esphome.core import CORE
from esphome.core import CORE, coroutine
from esphome.cpp_generator import Pvariable, add, get_variable, process_lambda, templatable
from esphome.cpp_types import App, Component, Nameable, PollingComponent, Trigger, \
esphome_ns, float_, optional
@ -143,6 +143,7 @@ SENSOR_SCHEMA = cv.MQTT_COMPONENT_SCHEMA.extend({
SENSOR_PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(SENSOR_SCHEMA.schema)
@coroutine
def setup_filter(config):
if CONF_OFFSET in config:
yield OffsetFilter.new(config[CONF_OFFSET])
@ -158,17 +159,15 @@ def setup_filter(config):
conf = config[CONF_EXPONENTIAL_MOVING_AVERAGE]
yield ExponentialMovingAverageFilter.new(conf[CONF_ALPHA], conf[CONF_SEND_EVERY])
elif CONF_LAMBDA in config:
for lambda_ in process_lambda(config[CONF_LAMBDA], [(float_, 'x')],
return_type=optional.template(float_)):
yield None
lambda_ = yield process_lambda(config[CONF_LAMBDA], [(float_, 'x')],
return_type=optional.template(float_))
yield LambdaFilter.new(lambda_)
elif CONF_THROTTLE in config:
yield ThrottleFilter.new(config[CONF_THROTTLE])
elif CONF_DELTA in config:
yield DeltaFilter.new(config[CONF_DELTA])
elif CONF_OR in config:
for filters in setup_filters(config[CONF_OR]):
yield None
filters = yield setup_filters(config[CONF_OR])
yield OrFilter.new(filters)
elif CONF_HEARTBEAT in config:
yield App.register_component(HeartbeatFilter.new(config[CONF_HEARTBEAT]))
@ -181,15 +180,15 @@ def setup_filter(config):
yield CalibrateLinearFilter.new(k, b)
@coroutine
def setup_filters(config):
filters = []
for conf in config:
for filter in setup_filter(conf):
yield None
filters.append(filter)
filters.append((yield setup_filter(conf)))
yield filters
@coroutine
def setup_sensor_core_(sensor_var, config):
if CONF_INTERNAL in config:
add(sensor_var.set_internal(config[CONF_INTERNAL]))
@ -200,8 +199,7 @@ def setup_sensor_core_(sensor_var, config):
if CONF_ACCURACY_DECIMALS in config:
add(sensor_var.set_accuracy_decimals(config[CONF_ACCURACY_DECIMALS]))
if CONF_FILTERS in config:
for filters in setup_filters(config[CONF_FILTERS]):
yield
filters = yield setup_filters(config[CONF_FILTERS])
add(sensor_var.set_filters(filters))
for conf in config.get(CONF_ON_VALUE, []):
@ -217,12 +215,10 @@ def setup_sensor_core_(sensor_var, config):
trigger = Pvariable(conf[CONF_TRIGGER_ID], rhs)
add(App.register_component(trigger))
if CONF_ABOVE in conf:
for template_ in templatable(conf[CONF_ABOVE], float_, float_):
yield
template_ = yield templatable(conf[CONF_ABOVE], float_, float_)
add(trigger.set_min(template_))
if CONF_BELOW in conf:
for template_ in templatable(conf[CONF_BELOW], float_, float_):
yield
template_ = yield templatable(conf[CONF_BELOW], float_, float_)
add(trigger.set_max(template_))
automation.build_automations(trigger, [(float_, 'x')], conf)
@ -260,8 +256,7 @@ SENSOR_IN_RANGE_CONDITION_SCHEMA = vol.All({
@CONDITION_REGISTRY.register(CONF_SENSOR_IN_RANGE, SENSOR_IN_RANGE_CONDITION_SCHEMA)
def sensor_in_range_to_code(config, condition_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_sensor_in_range_condition(template_arg)
type = SensorInRangeCondition.template(template_arg)
cond = Pvariable(condition_id, rhs, type=type)

View File

@ -60,8 +60,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for hub in get_variable(config[CONF_ADS1115_ID]):
yield
hub = yield get_variable(config[CONF_ADS1115_ID])
mux = MUX[config[CONF_MULTIPLEXER]]
gain = GAIN[config[CONF_GAIN]]

View File

@ -24,8 +24,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for hub in get_variable(config[CONF_APDS9960_ID]):
yield
hub = yield get_variable(config[CONF_APDS9960_ID])
func = getattr(hub, TYPES[config[CONF_TYPE]])
rhs = func(config[CONF_NAME])
sensor.register_sensor(rhs, config)

View File

@ -20,7 +20,6 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
yield
hub = yield get_variable(config[CONF_ESP32_BLE_ID])
rhs = hub.make_rssi_sensor(config[CONF_NAME], make_address_array(config[CONF_MAC_ADDRESS]))
sensor.register_sensor(rhs, config)

View File

@ -38,8 +38,7 @@ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
rhs = App.make_cse7766(uart_, config.get(CONF_UPDATE_INTERVAL))
cse = Pvariable(config[CONF_ID], rhs)

View File

@ -18,9 +18,8 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(sensor.SensorPtr)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(sensor.SensorPtr))
rhs = CustomSensorConstructor(template_)
custom = variable(config[CONF_ID], rhs)

View File

@ -20,8 +20,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for hub in get_variable(config[CONF_DALLAS_ID]):
yield
hub = yield get_variable(config[CONF_DALLAS_ID])
if CONF_ADDRESS in config:
address = HexIntLiteral(config[CONF_ADDRESS])
rhs = hub.Pget_sensor_by_address(config[CONF_NAME], address, config.get(CONF_RESOLUTION))

View File

@ -40,8 +40,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_dht_sensor(config[CONF_TEMPERATURE][CONF_NAME],
config[CONF_HUMIDITY][CONF_NAME],
pin, config.get(CONF_UPDATE_INTERVAL))

View File

@ -19,8 +19,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin in gpio_input_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_input_pin_expression(config[CONF_PIN])
rhs = App.make_duty_cycle_sensor(config[CONF_NAME], pin,
config.get(CONF_UPDATE_INTERVAL))
duty = Pvariable(config[CONF_ID], rhs)

View File

@ -40,8 +40,7 @@ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for sel in gpio_output_pin_expression(config[CONF_SEL_PIN]):
yield
sel = yield gpio_output_pin_expression(config[CONF_SEL_PIN])
rhs = App.make_hlw8012(sel, config[CONF_CF_PIN], config[CONF_CF1_PIN],
config.get(CONF_UPDATE_INTERVAL))

View File

@ -30,10 +30,8 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for dout_pin in gpio_input_pin_expression(config[CONF_DOUT_PIN]):
yield
for sck_pin in gpio_input_pin_expression(config[CONF_CLK_PIN]):
yield
dout_pin = yield gpio_input_pin_expression(config[CONF_DOUT_PIN])
sck_pin = yield gpio_input_pin_expression(config[CONF_CLK_PIN])
rhs = App.make_hx711_sensor(config[CONF_NAME], dout_pin, sck_pin,
config.get(CONF_UPDATE_INTERVAL))

View File

@ -21,10 +21,8 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for spi_ in get_variable(config[CONF_SPI_ID]):
yield
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
yield
spi_ = yield get_variable(config[CONF_SPI_ID])
cs = yield gpio_output_pin_expression(config[CONF_CS_PIN])
rhs = App.make_max31855_sensor(config[CONF_NAME], spi_, cs,
config.get(CONF_UPDATE_INTERVAL))
max31855 = Pvariable(config[CONF_ID], rhs)

View File

@ -22,10 +22,8 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for spi_ in get_variable(config[CONF_SPI_ID]):
yield
for cs in gpio_output_pin_expression(config[CONF_CS_PIN]):
yield
spi_ = yield get_variable(config[CONF_SPI_ID])
cs = yield gpio_output_pin_expression(config[CONF_CS_PIN])
rhs = App.make_max6675_sensor(config[CONF_NAME], spi_, cs,
config.get(CONF_UPDATE_INTERVAL))
max6675 = Pvariable(config[CONF_ID], rhs)

View File

@ -30,8 +30,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
rhs = App.make_mhz19_sensor(uart_, config[CONF_CO2][CONF_NAME],
config.get(CONF_UPDATE_INTERVAL))
mhz19 = Pvariable(config[CONF_ID], rhs)

View File

@ -61,8 +61,7 @@ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
rhs = App.make_pmsx003(uart_, PMSX003_TYPES[config[CONF_TYPE]])
pms = Pvariable(config[CONF_ID], rhs)

View File

@ -58,8 +58,7 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin in gpio_input_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_input_pin_expression(config[CONF_PIN])
rhs = App.make_pulse_counter_sensor(config[CONF_NAME], pin,
config.get(CONF_UPDATE_INTERVAL))
pcnt = Pvariable(config[CONF_ID], rhs)

View File

@ -46,16 +46,13 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin_a in gpio_input_pin_expression(config[CONF_PIN_A]):
yield
for pin_b in gpio_input_pin_expression(config[CONF_PIN_B]):
yield
pin_a = yield gpio_input_pin_expression(config[CONF_PIN_A])
pin_b = yield gpio_input_pin_expression(config[CONF_PIN_B])
rhs = App.make_rotary_encoder_sensor(config[CONF_NAME], pin_a, pin_b)
encoder = Pvariable(config[CONF_ID], rhs)
if CONF_PIN_RESET in config:
for pin_i in gpio_input_pin_expression(config[CONF_PIN_RESET]):
yield
pin_i = yield gpio_input_pin_expression(config[CONF_PIN_RESET])
add(encoder.set_reset_pin(pin_i))
if CONF_RESOLUTION in config:
resolution = RESOLUTIONS[config[CONF_RESOLUTION]]

View File

@ -46,8 +46,7 @@ PLATFORM_SCHEMA = vol.All(sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
rhs = App.make_sds011(uart_)
sds011 = Pvariable(config[CONF_ID], rhs)

View File

@ -26,9 +26,8 @@ def to_code(config):
setup_component(template, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(float_)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(float_))
add(template.set_template(template_))
@ -43,12 +42,10 @@ SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_SENSOR_TEMPLATE_PUBLISH, SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA)
def sensor_template_publish_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_sensor_publish_action(template_arg)
type = SensorPublishAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_STATE], args, float_):
yield None
template_ = yield templatable(config[CONF_STATE], args, float_)
add(action.set_state(template_))
yield action

View File

@ -20,10 +20,8 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for time_ in get_variable(config[CONF_TIME_ID]):
yield
for sens in get_variable(config[CONF_POWER_ID]):
yield
time_ = yield get_variable(config[CONF_TIME_ID])
sens = yield get_variable(config[CONF_POWER_ID])
rhs = App.make_total_daily_energy_sensor(config[CONF_NAME], time_, sens)
total_energy = Pvariable(config[CONF_ID], rhs)

View File

@ -33,10 +33,8 @@ PLATFORM_SCHEMA = cv.nameable(sensor.SENSOR_PLATFORM_SCHEMA.extend({
def to_code(config):
for trigger in gpio_output_pin_expression(config[CONF_TRIGGER_PIN]):
yield
for echo in gpio_input_pin_expression(config[CONF_ECHO_PIN]):
yield
trigger = yield gpio_output_pin_expression(config[CONF_TRIGGER_PIN])
echo = yield gpio_input_pin_expression(config[CONF_ECHO_PIN])
rhs = App.make_ultrasonic_sensor(config[CONF_NAME], trigger, echo,
config.get(CONF_UPDATE_INTERVAL))
ultrasonic = Pvariable(config[CONF_ID], rhs)

View File

@ -23,8 +23,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
yield
hub = yield get_variable(config[CONF_ESP32_BLE_ID])
rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
dev = Pvariable(config[CONF_ID], rhs)
if CONF_TEMPERATURE in config:

View File

@ -21,8 +21,7 @@ PLATFORM_SCHEMA = sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for hub in get_variable(config[CONF_ESP32_BLE_ID]):
yield
hub = yield get_variable(config[CONF_ESP32_BLE_ID])
rhs = hub.make_xiaomi_device(make_address_array(config[CONF_MAC_ADDRESS]))
dev = Pvariable(config[CONF_MAKE_ID], rhs)
if CONF_TEMPERATURE in config:

View File

@ -24,8 +24,7 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for out in get_variable(config[CONF_OUTPUT]):
yield
out = yield get_variable(config[CONF_OUTPUT])
rhs = App.register_component(Servo.new(out))
servo = Pvariable(config[CONF_ID], rhs)
@ -48,12 +47,10 @@ SERVO_WRITE_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_SERVO_WRITE, SERVO_WRITE_ACTION_SCHEMA)
def servo_write_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = ServoWriteAction.new(template_arg, var)
type = ServoWriteAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_LEVEL], args, float_):
yield None
template_ = yield templatable(config[CONF_LEVEL], args, float_)
add(action.set_value(template_))
yield action

View File

@ -21,17 +21,14 @@ CONFIG_SCHEMA = vol.All(cv.Schema({
def to_code(config):
for clk in gpio_output_pin_expression(config[CONF_CLK_PIN]):
yield
clk = yield gpio_output_pin_expression(config[CONF_CLK_PIN])
rhs = App.init_spi(clk)
spi = Pvariable(config[CONF_ID], rhs)
if CONF_MISO_PIN in config:
for miso in gpio_input_pin_expression(config[CONF_MISO_PIN]):
yield
miso = yield gpio_input_pin_expression(config[CONF_MISO_PIN])
add(spi.set_miso(miso))
if CONF_MOSI_PIN in config:
for mosi in gpio_input_pin_expression(config[CONF_MOSI_PIN]):
yield
mosi = yield gpio_input_pin_expression(config[CONF_MOSI_PIN])
add(spi.set_mosi(mosi))
setup_component(spi, config)

View File

@ -15,8 +15,7 @@ CONFIG_SCHEMA = cv.Schema({
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_status_led(pin)
var = Pvariable(config[CONF_ID], rhs)

View File

@ -93,13 +93,11 @@ STEPPER_SET_TARGET_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_STEPPER_SET_TARGET, STEPPER_SET_TARGET_ACTION_SCHEMA)
def stepper_set_target_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_set_target_action(template_arg)
type = SetTargetAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_TARGET], args, int32):
yield None
template_ = yield templatable(config[CONF_TARGET], args, int32)
add(action.set_target(template_))
yield action
@ -113,12 +111,10 @@ STEPPER_REPORT_POSITION_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_STEPPER_REPORT_POSITION, STEPPER_REPORT_POSITION_ACTION_SCHEMA)
def stepper_report_position_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_report_position_action(template_arg)
type = ReportPositionAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_POSITION], args, int32):
yield None
template_ = yield templatable(config[CONF_POSITION], args, int32)
add(action.set_position(template_))
yield action

View File

@ -19,16 +19,13 @@ PLATFORM_SCHEMA = stepper.STEPPER_PLATFORM_SCHEMA.extend({
def to_code(config):
for step_pin in gpio_output_pin_expression(config[CONF_STEP_PIN]):
yield
for dir_pin in gpio_output_pin_expression(config[CONF_DIR_PIN]):
yield
step_pin = yield gpio_output_pin_expression(config[CONF_STEP_PIN])
dir_pin = yield gpio_output_pin_expression(config[CONF_DIR_PIN])
rhs = App.make_a4988(step_pin, dir_pin)
a4988 = Pvariable(config[CONF_ID], rhs)
if CONF_SLEEP_PIN in config:
for sleep_pin in gpio_output_pin_expression(config[CONF_SLEEP_PIN]):
yield
sleep_pin = yield gpio_output_pin_expression(config[CONF_SLEEP_PIN])
add(a4988.set_sleep_pin(sleep_pin))
stepper.setup_stepper(a4988, config)

View File

@ -31,14 +31,10 @@ PLATFORM_SCHEMA = stepper.STEPPER_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin_a in gpio_output_pin_expression(config[CONF_PIN_A]):
yield
for pin_b in gpio_output_pin_expression(config[CONF_PIN_B]):
yield
for pin_c in gpio_output_pin_expression(config[CONF_PIN_C]):
yield
for pin_d in gpio_output_pin_expression(config[CONF_PIN_D]):
yield
pin_a = yield gpio_output_pin_expression(config[CONF_PIN_A])
pin_b = yield gpio_output_pin_expression(config[CONF_PIN_B])
pin_c = yield gpio_output_pin_expression(config[CONF_PIN_C])
pin_d = yield gpio_output_pin_expression(config[CONF_PIN_D])
rhs = App.make_uln2003(pin_a, pin_b, pin_c, pin_d)
uln = Pvariable(config[CONF_ID], rhs)

View File

@ -84,8 +84,7 @@ SWITCH_TOGGLE_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_SWITCH_TOGGLE, SWITCH_TOGGLE_ACTION_SCHEMA)
def switch_toggle_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_toggle_action(template_arg)
type = ToggleAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -99,8 +98,7 @@ SWITCH_TURN_OFF_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_SWITCH_TURN_OFF, SWITCH_TURN_OFF_ACTION_SCHEMA)
def switch_turn_off_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_turn_off_action(template_arg)
type = TurnOffAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -114,8 +112,7 @@ SWITCH_TURN_ON_ACTION_SCHEMA = maybe_simple_id({
@ACTION_REGISTRY.register(CONF_SWITCH_TURN_ON, SWITCH_TURN_ON_ACTION_SCHEMA)
def switch_turn_on_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_turn_on_action(template_arg)
type = TurnOnAction.template(template_arg)
yield Pvariable(action_id, rhs, type=type)
@ -129,8 +126,7 @@ SWITCH_IS_ON_CONDITION_SCHEMA = maybe_simple_id({
@CONDITION_REGISTRY.register(CONF_SWITCH_IS_ON, SWITCH_IS_ON_CONDITION_SCHEMA)
def switch_is_on_to_code(config, condition_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_switch_is_on_condition(template_arg)
type = SwitchCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)
@ -144,8 +140,7 @@ SWITCH_IS_OFF_CONDITION_SCHEMA = maybe_simple_id({
@CONDITION_REGISTRY.register(CONF_SWITCH_IS_OFF, SWITCH_IS_OFF_CONDITION_SCHEMA)
def switch_is_off_to_code(config, condition_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_switch_is_off_condition(template_arg)
type = SwitchCondition.template(template_arg)
yield Pvariable(condition_id, rhs, type=type)

View File

@ -19,9 +19,8 @@ PLATFORM_SCHEMA = switch.PLATFORM_SCHEMA.extend({
def to_code(config):
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(switch.SwitchPtr)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(switch.SwitchPtr))
rhs = CustomSwitchConstructor(template_)
custom = variable(config[CONF_ID], rhs)

View File

@ -27,8 +27,7 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
def to_code(config):
for pin in gpio_output_pin_expression(config[CONF_PIN]):
yield
pin = yield gpio_output_pin_expression(config[CONF_PIN])
rhs = App.make_gpio_switch(config[CONF_NAME], pin)
gpio = Pvariable(config[CONF_ID], rhs)
@ -38,8 +37,7 @@ def to_code(config):
if CONF_INTERLOCK in config:
interlock = []
for it in config[CONF_INTERLOCK]:
for lock in get_variable(it):
yield
lock = yield get_variable(it)
interlock.append(lock)
add(gpio.set_interlock(interlock))

View File

@ -16,8 +16,7 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
def to_code(config):
for output_ in get_variable(config[CONF_OUTPUT]):
yield
output_ = yield get_variable(config[CONF_OUTPUT])
rhs = App.make_output_switch(config[CONF_NAME], output_)
switch_ = Pvariable(config[CONF_ID], rhs)

View File

@ -146,8 +146,7 @@ def transmitter_base(full_config):
def to_code(config):
for remote in get_variable(config[CONF_REMOTE_TRANSMITTER_ID]):
yield
remote = yield get_variable(config[CONF_REMOTE_TRANSMITTER_ID])
rhs = transmitter_base(config)
transmitter = Pvariable(config[CONF_TRANSMITTER_ID], rhs)

View File

@ -31,9 +31,8 @@ def to_code(config):
switch.setup_switch(template, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(bool_)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(bool_))
add(template.set_state_lambda(template_))
if CONF_TURN_OFF_ACTION in config:
automation.build_automations(template.get_turn_off_trigger(), [],
@ -63,12 +62,10 @@ SWITCH_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_SWITCH_TEMPLATE_PUBLISH, SWITCH_TEMPLATE_PUBLISH_ACTION_SCHEMA)
def switch_template_publish_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_switch_publish_action(template_arg)
type = SwitchPublishAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_STATE], args, bool_):
yield None
template_ = yield templatable(config[CONF_STATE], args, bool_)
add(action.set_state(template_))
yield action

View File

@ -33,8 +33,7 @@ PLATFORM_SCHEMA = cv.nameable(switch.SWITCH_PLATFORM_SCHEMA.extend({
def to_code(config):
for uart_ in get_variable(config[CONF_UART_ID]):
yield
uart_ = yield get_variable(config[CONF_UART_ID])
data = config[CONF_DATA]
if isinstance(data, str):
data = [HexInt(ord(x)) for x in data]

View File

@ -19,9 +19,8 @@ PLATFORM_SCHEMA = text_sensor.PLATFORM_SCHEMA.extend({
def to_code(config):
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(text_sensor.TextSensorPtr)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=std_vector.template(text_sensor.TextSensorPtr))
rhs = CustomTextSensorConstructor(template_)
custom = variable(config[CONF_ID], rhs)

View File

@ -26,9 +26,8 @@ def to_code(config):
setup_component(template, config)
if CONF_LAMBDA in config:
for template_ in process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(std_string)):
yield
template_ = yield process_lambda(config[CONF_LAMBDA], [],
return_type=optional.template(std_string))
add(template.set_template(template_))
@ -44,12 +43,10 @@ TEXT_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA = cv.Schema({
@ACTION_REGISTRY.register(CONF_TEXT_SENSOR_TEMPLATE_PUBLISH,
TEXT_SENSOR_TEMPLATE_PUBLISH_ACTION_SCHEMA)
def text_sensor_template_publish_to_code(config, action_id, template_arg, args):
for var in get_variable(config[CONF_ID]):
yield None
var = yield get_variable(config[CONF_ID])
rhs = var.make_text_sensor_publish_action(template_arg)
type = TextSensorPublishAction.template(template_arg)
action = Pvariable(action_id, rhs, type=type)
for template_ in templatable(config[CONF_STATE], args, std_string):
yield None
template_ = yield templatable(config[CONF_STATE], args, std_string)
add(action.set_state(template_))
yield action

View File

@ -483,7 +483,7 @@ if IS_PY2:
def temperature(value):
try:
return _temperature_c(value)
except vol.Invalid as orig_err:
except vol.Invalid as orig_err: # noqa
pass
try:
@ -498,7 +498,7 @@ def temperature(value):
except vol.Invalid:
pass
raise orig_err
raise orig_err # noqa
_color_temperature_mireds = float_with_unit('Color Temperature', r'(mireds|Mireds)')

Some files were not shown because too many files have changed in this diff Show More