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

Convert components to async-def syntax (#1823)

* Convert components to async-def syntax

* Remove stray @coroutine

* Manual part

* Convert complexer components code to async-def

* Manual cleanup

* More manual cleanup
This commit is contained in:
Otto Winter
2021-05-24 21:45:31 +02:00
committed by GitHub
parent 93d9d4b50a
commit a33bb32874
60 changed files with 592 additions and 633 deletions

View File

@@ -10,7 +10,7 @@ from esphome.const import (
CONF_TARGET,
CONF_SPEED,
)
from esphome.core import CORE, coroutine, coroutine_with_priority
from esphome.core import CORE, coroutine_with_priority
IS_PLATFORM_COMPONENT = True
@@ -74,8 +74,7 @@ STEPPER_SCHEMA = cv.Schema(
)
@coroutine
def setup_stepper_core_(stepper_var, config):
async def setup_stepper_core_(stepper_var, config):
if CONF_ACCELERATION in config:
cg.add(stepper_var.set_acceleration(config[CONF_ACCELERATION]))
if CONF_DECELERATION in config:
@@ -84,11 +83,10 @@ def setup_stepper_core_(stepper_var, config):
cg.add(stepper_var.set_max_speed(config[CONF_MAX_SPEED]))
@coroutine
def register_stepper(var, config):
async def register_stepper(var, config):
if not CORE.has_id(config[CONF_ID]):
var = cg.Pvariable(config[CONF_ID], var)
yield setup_stepper_core_(var, config)
await setup_stepper_core_(var, config)
@automation.register_action(
@@ -101,12 +99,12 @@ def register_stepper(var, config):
}
),
)
def stepper_set_target_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
async def stepper_set_target_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren)
template_ = yield cg.templatable(config[CONF_TARGET], args, cg.int32)
template_ = await cg.templatable(config[CONF_TARGET], args, cg.int32)
cg.add(var.set_target(template_))
yield var
return var
@automation.register_action(
@@ -119,12 +117,12 @@ def stepper_set_target_to_code(config, action_id, template_arg, args):
}
),
)
def stepper_report_position_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
async def stepper_report_position_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren)
template_ = yield cg.templatable(config[CONF_POSITION], args, cg.int32)
template_ = await cg.templatable(config[CONF_POSITION], args, cg.int32)
cg.add(var.set_position(template_))
yield var
return var
@automation.register_action(
@@ -137,12 +135,12 @@ def stepper_report_position_to_code(config, action_id, template_arg, args):
}
),
)
def stepper_set_speed_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
async def stepper_set_speed_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren)
template_ = yield cg.templatable(config[CONF_SPEED], args, cg.int32)
template_ = await cg.templatable(config[CONF_SPEED], args, cg.int32)
cg.add(var.set_speed(template_))
yield var
return var
@coroutine_with_priority(100.0)