1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-25 14:42:21 +01:00

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
103 changed files with 351 additions and 588 deletions

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)