mirror of
https://github.com/esphome/esphome.git
synced 2025-10-30 14:43:51 +00:00
Convert components to async-def syntax (#1821)
This commit is contained in:
@@ -17,13 +17,13 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await binary_sensor.register_binary_sensor(var, config)
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
template_ = yield cg.process_lambda(
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.optional.template(bool)
|
||||
)
|
||||
cg.add(var.set_template(template_))
|
||||
|
||||
@@ -52,39 +52,39 @@ CONFIG_SCHEMA = cover.COVER_SCHEMA.extend(
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield cover.register_cover(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await cover.register_cover(var, config)
|
||||
if CONF_LAMBDA in config:
|
||||
template_ = yield cg.process_lambda(
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.optional.template(float)
|
||||
)
|
||||
cg.add(var.set_state_lambda(template_))
|
||||
if CONF_OPEN_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_open_trigger(), [], config[CONF_OPEN_ACTION]
|
||||
)
|
||||
if CONF_CLOSE_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_close_trigger(), [], config[CONF_CLOSE_ACTION]
|
||||
)
|
||||
if CONF_STOP_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_stop_trigger(), [], config[CONF_STOP_ACTION]
|
||||
)
|
||||
if CONF_TILT_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_tilt_trigger(), [(float, "tilt")], config[CONF_TILT_ACTION]
|
||||
)
|
||||
cg.add(var.set_has_tilt(True))
|
||||
if CONF_TILT_LAMBDA in config:
|
||||
tilt_template_ = yield cg.process_lambda(
|
||||
tilt_template_ = await cg.process_lambda(
|
||||
config[CONF_TILT_LAMBDA], [], return_type=cg.optional.template(float)
|
||||
)
|
||||
cg.add(var.set_tilt_lambda(tilt_template_))
|
||||
if CONF_POSITION_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_position_trigger(), [(float, "pos")], config[CONF_POSITION_ACTION]
|
||||
)
|
||||
cg.add(var.set_has_position(True))
|
||||
|
||||
@@ -34,14 +34,14 @@ CONFIG_SCHEMA = cv.typed_schema(
|
||||
)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
if config[CONF_TYPE] == CONF_BINARY:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_trigger(), [(bool, "state")], config[CONF_WRITE_ACTION]
|
||||
)
|
||||
else:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_trigger(), [(float, "state")], config[CONF_WRITE_ACTION]
|
||||
)
|
||||
yield output.register_output(var, config)
|
||||
await output.register_output(var, config)
|
||||
|
||||
@@ -28,13 +28,13 @@ CONFIG_SCHEMA = (
|
||||
)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield sensor.register_sensor(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await sensor.register_sensor(var, config)
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
template_ = yield cg.process_lambda(
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.optional.template(float)
|
||||
)
|
||||
cg.add(var.set_template(template_))
|
||||
|
||||
@@ -29,22 +29,22 @@ CONFIG_SCHEMA = switch.SWITCH_SCHEMA.extend(
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield switch.register_switch(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await switch.register_switch(var, config)
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
template_ = yield cg.process_lambda(
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.optional.template(bool)
|
||||
)
|
||||
cg.add(var.set_state_lambda(template_))
|
||||
if CONF_TURN_OFF_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_turn_off_trigger(), [], config[CONF_TURN_OFF_ACTION]
|
||||
)
|
||||
if CONF_TURN_ON_ACTION in config:
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
var.get_turn_on_trigger(), [], config[CONF_TURN_ON_ACTION]
|
||||
)
|
||||
cg.add(var.set_optimistic(config[CONF_OPTIMISTIC]))
|
||||
|
||||
@@ -18,13 +18,13 @@ CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend(
|
||||
).extend(cv.polling_component_schema("60s"))
|
||||
|
||||
|
||||
def to_code(config):
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield text_sensor.register_text_sensor(var, config)
|
||||
await cg.register_component(var, config)
|
||||
await text_sensor.register_text_sensor(var, config)
|
||||
|
||||
if CONF_LAMBDA in config:
|
||||
template_ = yield cg.process_lambda(
|
||||
template_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [], return_type=cg.optional.template(cg.std_string)
|
||||
)
|
||||
cg.add(var.set_template(template_))
|
||||
|
||||
Reference in New Issue
Block a user