Convert core components to async-def coroutine syntax (#1658)

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Otto Winter
2021-05-23 22:10:30 +02:00
committed by GitHub
parent 514d11d46f
commit aebad04c0b
29 changed files with 313 additions and 359 deletions
+15 -17
View File
@@ -11,7 +11,7 @@ from esphome.const import (
CONF_MIN_POWER,
CONF_POWER_SUPPLY,
)
from esphome.core import CORE, coroutine
from esphome.core import CORE
CODEOWNERS = ["@esphome/core"]
@@ -43,12 +43,11 @@ TurnOnAction = output_ns.class_("TurnOnAction", automation.Action)
SetLevelAction = output_ns.class_("SetLevelAction", automation.Action)
@coroutine
def setup_output_platform_(obj, config):
async def setup_output_platform_(obj, config):
if CONF_INVERTED in config:
cg.add(obj.set_inverted(config[CONF_INVERTED]))
if CONF_POWER_SUPPLY in config:
power_supply_ = yield cg.get_variable(config[CONF_POWER_SUPPLY])
power_supply_ = await cg.get_variable(config[CONF_POWER_SUPPLY])
cg.add(obj.set_power_supply(power_supply_))
if CONF_MAX_POWER in config:
cg.add(obj.set_max_power(config[CONF_MAX_POWER]))
@@ -56,11 +55,10 @@ def setup_output_platform_(obj, config):
cg.add(obj.set_min_power(config[CONF_MIN_POWER]))
@coroutine
def register_output(var, config):
async def register_output(var, config):
if not CORE.has_id(config[CONF_ID]):
var = cg.Pvariable(config[CONF_ID], var)
yield setup_output_platform_(var, config)
await setup_output_platform_(var, config)
BINARY_OUTPUT_ACTION_SCHEMA = maybe_simple_id(
@@ -71,17 +69,17 @@ BINARY_OUTPUT_ACTION_SCHEMA = maybe_simple_id(
@automation.register_action("output.turn_on", TurnOnAction, BINARY_OUTPUT_ACTION_SCHEMA)
def output_turn_on_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
yield cg.new_Pvariable(action_id, template_arg, paren)
async def output_turn_on_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
return cg.new_Pvariable(action_id, template_arg, paren)
@automation.register_action(
"output.turn_off", TurnOffAction, BINARY_OUTPUT_ACTION_SCHEMA
)
def output_turn_off_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
yield cg.new_Pvariable(action_id, template_arg, paren)
async def output_turn_off_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
return cg.new_Pvariable(action_id, template_arg, paren)
@automation.register_action(
@@ -94,12 +92,12 @@ def output_turn_off_to_code(config, action_id, template_arg, args):
}
),
)
def output_set_level_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
async def output_set_level_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_LEVEL], args, float)
template_ = await cg.templatable(config[CONF_LEVEL], args, float)
cg.add(var.set_level(template_))
yield var
return var
def to_code(config):