mirror of
https://github.com/esphome/esphome.git
synced 2024-12-24 22:44:54 +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:
parent
93d9d4b50a
commit
a33bb32874
60 changed files with 592 additions and 633 deletions
|
@ -21,8 +21,7 @@ CONFIG_SCHEMA = cv.Schema({})
|
|||
"Adalight",
|
||||
{cv.GenerateID(CONF_UART_ID): cv.use_id(uart.UARTComponent)},
|
||||
)
|
||||
def adalight_light_effect_to_code(config, effect_id):
|
||||
async def adalight_light_effect_to_code(config, effect_id):
|
||||
effect = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
yield uart.register_uart_device(effect, config)
|
||||
|
||||
yield effect
|
||||
await uart.register_uart_device(effect, config)
|
||||
return effect
|
||||
|
|
|
@ -129,35 +129,35 @@ validate_filters = cv.validate_registry("filter", FILTER_REGISTRY)
|
|||
|
||||
|
||||
@FILTER_REGISTRY.register("invert", InvertFilter, {})
|
||||
def invert_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id)
|
||||
async def invert_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"delayed_on_off", DelayedOnOffFilter, cv.positive_time_period_milliseconds
|
||||
)
|
||||
def delayed_on_off_filter_to_code(config, filter_id):
|
||||
async def delayed_on_off_filter_to_code(config, filter_id):
|
||||
var = cg.new_Pvariable(filter_id, config)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"delayed_on", DelayedOnFilter, cv.positive_time_period_milliseconds
|
||||
)
|
||||
def delayed_on_filter_to_code(config, filter_id):
|
||||
async def delayed_on_filter_to_code(config, filter_id):
|
||||
var = cg.new_Pvariable(filter_id, config)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"delayed_off", DelayedOffFilter, cv.positive_time_period_milliseconds
|
||||
)
|
||||
def delayed_off_filter_to_code(config, filter_id):
|
||||
async def delayed_off_filter_to_code(config, filter_id):
|
||||
var = cg.new_Pvariable(filter_id, config)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
CONF_TIME_OFF = "time_off"
|
||||
|
@ -187,7 +187,7 @@ DEFAULT_TIME_ON = "900ms"
|
|||
),
|
||||
),
|
||||
)
|
||||
def autorepeat_filter_to_code(config, filter_id):
|
||||
async def autorepeat_filter_to_code(config, filter_id):
|
||||
timings = []
|
||||
if len(config) > 0:
|
||||
for conf in config:
|
||||
|
@ -201,16 +201,16 @@ def autorepeat_filter_to_code(config, filter_id):
|
|||
)
|
||||
)
|
||||
var = cg.new_Pvariable(filter_id, timings)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("lambda", LambdaFilter, cv.returning_lambda)
|
||||
def lambda_filter_to_code(config, filter_id):
|
||||
lambda_ = yield cg.process_lambda(
|
||||
async def lambda_filter_to_code(config, filter_id):
|
||||
lambda_ = await cg.process_lambda(
|
||||
config, [(bool, "x")], return_type=cg.optional.template(bool)
|
||||
)
|
||||
yield cg.new_Pvariable(filter_id, lambda_)
|
||||
return cg.new_Pvariable(filter_id, lambda_)
|
||||
|
||||
|
||||
MULTI_CLICK_TIMING_SCHEMA = cv.Schema(
|
||||
|
@ -466,17 +466,17 @@ BINARY_SENSOR_CONDITION_SCHEMA = maybe_simple_id(
|
|||
@automation.register_condition(
|
||||
"binary_sensor.is_on", BinarySensorCondition, BINARY_SENSOR_CONDITION_SCHEMA
|
||||
)
|
||||
def binary_sensor_is_on_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(condition_id, template_arg, paren, True)
|
||||
async def binary_sensor_is_on_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(condition_id, template_arg, paren, True)
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
"binary_sensor.is_off", BinarySensorCondition, BINARY_SENSOR_CONDITION_SCHEMA
|
||||
)
|
||||
def binary_sensor_is_off_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(condition_id, template_arg, paren, False)
|
||||
async def binary_sensor_is_off_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(condition_id, template_arg, paren, False)
|
||||
|
||||
|
||||
@coroutine_with_priority(100.0)
|
||||
|
|
|
@ -9,7 +9,6 @@ from esphome.const import (
|
|||
CONF_ON_DISCONNECT,
|
||||
CONF_TRIGGER_ID,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
from esphome import automation
|
||||
|
||||
CODEOWNERS = ["@buxtronix"]
|
||||
|
@ -68,9 +67,8 @@ BLE_CLIENT_SCHEMA = cv.Schema(
|
|||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def register_ble_node(var, config):
|
||||
parent = yield cg.get_variable(config[CONF_BLE_CLIENT_ID])
|
||||
async def register_ble_node(var, config):
|
||||
parent = await cg.get_variable(config[CONF_BLE_CLIENT_ID])
|
||||
cg.add(parent.register_ble_node(var))
|
||||
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ from esphome.const import (
|
|||
ICON_THERMOMETER,
|
||||
ICON_WATER_PERCENT,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
from . import (
|
||||
BME680BSECComponent,
|
||||
CONF_BME680_BSEC_ID,
|
||||
|
@ -87,11 +86,10 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_conf(config, key, hub):
|
||||
async def setup_conf(config, key, hub):
|
||||
if key in config:
|
||||
conf = config[key]
|
||||
sens = yield sensor.new_sensor(conf)
|
||||
sens = await sensor.new_sensor(conf)
|
||||
cg.add(getattr(hub, f"set_{key}_sensor")(sens))
|
||||
if CONF_SAMPLE_RATE in conf:
|
||||
cg.add(getattr(hub, f"set_{key}_sample_rate")(conf[CONF_SAMPLE_RATE]))
|
||||
|
|
|
@ -2,7 +2,6 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import CONF_ID, CONF_ICON
|
||||
from esphome.core import coroutine
|
||||
from . import BME680BSECComponent, CONF_BME680_BSEC_ID
|
||||
|
||||
DEPENDENCIES = ["bme680_bsec"]
|
||||
|
@ -25,12 +24,11 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_conf(config, key, hub):
|
||||
async def setup_conf(config, key, hub):
|
||||
if key in config:
|
||||
conf = config[key]
|
||||
sens = cg.new_Pvariable(conf[CONF_ID])
|
||||
yield text_sensor.register_text_sensor(sens, conf)
|
||||
await text_sensor.register_text_sensor(sens, conf)
|
||||
cg.add(getattr(hub, f"set_{key}_text_sensor")(sens))
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome import automation
|
||||
from esphome.core import CORE, coroutine
|
||||
from esphome.core import CORE
|
||||
from esphome.const import CONF_ID, CONF_TRIGGER_ID, CONF_DATA
|
||||
|
||||
CODEOWNERS = ["@mvturnho", "@danielschramm"]
|
||||
|
@ -82,10 +82,9 @@ CANBUS_SCHEMA = cv.Schema(
|
|||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_canbus_core_(var, config):
|
||||
async def setup_canbus_core_(var, config):
|
||||
validate_id(config[CONF_CAN_ID], config[CONF_USE_EXTENDED_ID])
|
||||
yield cg.register_component(var, config)
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_can_id([config[CONF_CAN_ID]]))
|
||||
cg.add(var.set_use_extended_id([config[CONF_USE_EXTENDED_ID]]))
|
||||
cg.add(var.set_bitrate(CAN_SPEEDS[config[CONF_BIT_RATE]]))
|
||||
|
@ -95,17 +94,16 @@ def setup_canbus_core_(var, config):
|
|||
ext_id = conf[CONF_USE_EXTENDED_ID]
|
||||
validate_id(can_id, ext_id)
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var, can_id, ext_id)
|
||||
yield cg.register_component(trigger, conf)
|
||||
yield automation.build_automation(
|
||||
await cg.register_component(trigger, conf)
|
||||
await automation.build_automation(
|
||||
trigger, [(cg.std_vector.template(cg.uint8), "x")], conf
|
||||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def register_canbus(var, config):
|
||||
async def register_canbus(var, config):
|
||||
if not CORE.has_id(config[CONF_ID]):
|
||||
var = cg.new_Pvariable(config[CONF_ID], var)
|
||||
yield setup_canbus_core_(var, config)
|
||||
await setup_canbus_core_(var, config)
|
||||
|
||||
|
||||
# Actions
|
||||
|
@ -122,16 +120,16 @@ def register_canbus(var, config):
|
|||
key=CONF_DATA,
|
||||
),
|
||||
)
|
||||
def canbus_action_to_code(config, action_id, template_arg, args):
|
||||
async def canbus_action_to_code(config, action_id, template_arg, args):
|
||||
validate_id(config[CONF_CAN_ID], config[CONF_USE_EXTENDED_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_CANBUS_ID])
|
||||
await cg.register_parented(var, config[CONF_CANBUS_ID])
|
||||
|
||||
if CONF_CAN_ID in config:
|
||||
can_id = yield cg.templatable(config[CONF_CAN_ID], args, cg.uint32)
|
||||
can_id = await cg.templatable(config[CONF_CAN_ID], args, cg.uint32)
|
||||
cg.add(var.set_can_id(can_id))
|
||||
|
||||
use_extended_id = yield cg.templatable(
|
||||
use_extended_id = await cg.templatable(
|
||||
config[CONF_USE_EXTENDED_ID], args, cg.uint32
|
||||
)
|
||||
cg.add(var.set_use_extended_id(use_extended_id))
|
||||
|
@ -140,8 +138,8 @@ def canbus_action_to_code(config, action_id, template_arg, args):
|
|||
if isinstance(data, bytes):
|
||||
data = [int(x) for x in data]
|
||||
if cg.is_template(data):
|
||||
templ = yield cg.templatable(data, args, cg.std_vector.template(cg.uint8))
|
||||
templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8))
|
||||
cg.add(var.set_data_template(templ))
|
||||
else:
|
||||
cg.add(var.set_data_static(data))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -125,18 +125,18 @@ DEEP_SLEEP_PREVENT_SCHEMA = automation.maybe_simple_id(
|
|||
@automation.register_action(
|
||||
"deep_sleep.enter", EnterDeepSleepAction, DEEP_SLEEP_ENTER_SCHEMA
|
||||
)
|
||||
def deep_sleep_enter_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def deep_sleep_enter_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)
|
||||
if CONF_SLEEP_DURATION in config:
|
||||
template_ = yield cg.templatable(config[CONF_SLEEP_DURATION], args, cg.int32)
|
||||
template_ = await cg.templatable(config[CONF_SLEEP_DURATION], args, cg.int32)
|
||||
cg.add(var.set_sleep_duration(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"deep_sleep.prevent", PreventDeepSleepAction, DEEP_SLEEP_PREVENT_SCHEMA
|
||||
)
|
||||
def deep_sleep_prevent_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 deep_sleep_prevent_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)
|
||||
|
|
|
@ -87,10 +87,10 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_next_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_next_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -102,10 +102,10 @@ def dfplayer_next_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_previous_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_previous_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -120,15 +120,15 @@ def dfplayer_previous_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_FILE,
|
||||
),
|
||||
)
|
||||
def dfplayer_play_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_play_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_FILE], args, float)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_FILE], args, float)
|
||||
cg.add(var.set_file(template_))
|
||||
if CONF_LOOP in config:
|
||||
template_ = yield cg.templatable(config[CONF_LOOP], args, float)
|
||||
template_ = await cg.templatable(config[CONF_LOOP], args, float)
|
||||
cg.add(var.set_loop(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -143,18 +143,18 @@ def dfplayer_play_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_play_folder_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_play_folder_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_FOLDER], args, float)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_FOLDER], args, float)
|
||||
cg.add(var.set_folder(template_))
|
||||
if CONF_FILE in config:
|
||||
template_ = yield cg.templatable(config[CONF_FILE], args, float)
|
||||
template_ = await cg.templatable(config[CONF_FILE], args, float)
|
||||
cg.add(var.set_file(template_))
|
||||
if CONF_LOOP in config:
|
||||
template_ = yield cg.templatable(config[CONF_LOOP], args, float)
|
||||
template_ = await cg.templatable(config[CONF_LOOP], args, float)
|
||||
cg.add(var.set_loop(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -168,12 +168,12 @@ def dfplayer_play_folder_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_DEVICE,
|
||||
),
|
||||
)
|
||||
def dfplayer_set_device_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_set_device_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_DEVICE], args, Device)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_DEVICE], args, Device)
|
||||
cg.add(var.set_device(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -187,12 +187,12 @@ def dfplayer_set_device_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_VOLUME,
|
||||
),
|
||||
)
|
||||
def dfplayer_set_volume_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_set_volume_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_VOLUME], args, float)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_VOLUME], args, float)
|
||||
cg.add(var.set_volume(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -206,12 +206,12 @@ def dfplayer_set_volume_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_EQ_PRESET,
|
||||
),
|
||||
)
|
||||
def dfplayer_set_eq_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_set_eq_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_EQ_PRESET], args, EqPreset)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_EQ_PRESET], args, EqPreset)
|
||||
cg.add(var.set_eq(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -223,10 +223,10 @@ def dfplayer_set_eq_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_sleep_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_sleep_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -238,10 +238,10 @@ def dfplayer_sleep_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_reset_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_reset_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -253,10 +253,10 @@ def dfplayer_reset_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_start_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_start_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -268,10 +268,10 @@ def dfplayer_start_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_pause_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_pause_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -283,10 +283,10 @@ def dfplayer_pause_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_stop_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_stop_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -298,10 +298,10 @@ def dfplayer_stop_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplayer_random_to_code(config, action_id, template_arg, args):
|
||||
async def dfplayer_random_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
|
@ -313,7 +313,7 @@ def dfplayer_random_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def dfplyaer_is_playing_to_code(config, condition_id, template_arg, args):
|
||||
async def dfplyaer_is_playing_to_code(config, condition_id, template_arg, args):
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
|
|
@ -169,13 +169,13 @@ async def display_page_show_previous_to_code(config, action_id, template_arg, ar
|
|||
key=CONF_PAGE_ID,
|
||||
),
|
||||
)
|
||||
def display_is_displaying_page_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
page = yield cg.get_variable(config[CONF_PAGE_ID])
|
||||
async def display_is_displaying_page_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
page = await cg.get_variable(config[CONF_PAGE_ID])
|
||||
var = cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
cg.add(var.set_page(page))
|
||||
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@coroutine_with_priority(100.0)
|
||||
|
|
|
@ -29,10 +29,10 @@ CONFIG_SCHEMA = time.TIME_SCHEMA.extend(
|
|||
}
|
||||
),
|
||||
)
|
||||
def ds1307_write_time_to_code(config, action_id, template_arg, args):
|
||||
async def ds1307_write_time_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -44,10 +44,10 @@ def ds1307_write_time_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def ds1307_read_time_to_code(config, action_id, template_arg, args):
|
||||
async def ds1307_read_time_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
|
|
@ -45,11 +45,11 @@ async def to_code(config):
|
|||
cv.Optional(CONF_CHANNELS, default="RGB"): cv.one_of(*CHANNELS, upper=True),
|
||||
},
|
||||
)
|
||||
def e131_light_effect_to_code(config, effect_id):
|
||||
parent = yield cg.get_variable(config[CONF_E131_ID])
|
||||
async def e131_light_effect_to_code(config, effect_id):
|
||||
parent = await cg.get_variable(config[CONF_E131_ID])
|
||||
|
||||
effect = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(effect.set_first_universe(config[CONF_UNIVERSE]))
|
||||
cg.add(effect.set_channels(CHANNELS[config[CONF_CHANNELS]]))
|
||||
cg.add(effect.set_e131(parent))
|
||||
yield effect
|
||||
return effect
|
||||
|
|
|
@ -15,7 +15,6 @@ from esphome.const import (
|
|||
CONF_ON_BLE_SERVICE_DATA_ADVERTISE,
|
||||
CONF_ON_BLE_MANUFACTURER_DATA_ADVERTISE,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
AUTO_LOAD = ["xiaomi_ble", "ruuvi_ble"]
|
||||
|
@ -216,15 +215,13 @@ async def to_code(config):
|
|||
await automation.build_automation(trigger, [(adv_data_t_const_ref, "x")], conf)
|
||||
|
||||
|
||||
@coroutine
|
||||
def register_ble_device(var, config):
|
||||
paren = yield cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
async def register_ble_device(var, config):
|
||||
paren = await cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
cg.add(paren.register_listener(var))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@coroutine
|
||||
def register_client(var, config):
|
||||
paren = yield cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
async def register_client(var, config):
|
||||
paren = await cg.get_variable(config[CONF_ESP32_BLE_ID])
|
||||
cg.add(paren.register_client(var))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -56,9 +56,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def esp8266_set_frequency_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def esp8266_set_frequency_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_FREQUENCY], args, float)
|
||||
template_ = await cg.templatable(config[CONF_FREQUENCY], args, float)
|
||||
cg.add(var.set_frequency(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -7,7 +7,6 @@ from esphome.const import (
|
|||
CONF_RGB_ORDER,
|
||||
CONF_MAX_REFRESH_RATE,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@OttoWinter"]
|
||||
fastled_base_ns = cg.esphome_ns.namespace("fastled_base")
|
||||
|
@ -34,17 +33,16 @@ BASE_SCHEMA = light.ADDRESSABLE_LIGHT_SCHEMA.extend(
|
|||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
@coroutine
|
||||
def new_fastled_light(config):
|
||||
async def new_fastled_light(config):
|
||||
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
||||
yield cg.register_component(var, config)
|
||||
await cg.register_component(var, config)
|
||||
|
||||
if CONF_MAX_REFRESH_RATE in config:
|
||||
cg.add(var.set_max_refresh_rate(config[CONF_MAX_REFRESH_RATE]))
|
||||
|
||||
yield light.register_light(var, config)
|
||||
await light.register_light(var, config)
|
||||
# https://github.com/FastLED/FastLED/blob/master/library.json
|
||||
# 3.3.3 has an issue on ESP32 with RMT and fastled_clockless:
|
||||
# https://github.com/esphome/issues/issues/1375
|
||||
cg.add_library("FastLED", "3.3.2")
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -185,16 +185,16 @@ async def to_code(config):
|
|||
key=CONF_FINGER_ID,
|
||||
),
|
||||
)
|
||||
def fingerprint_grow_enroll_to_code(config, action_id, template_arg, args):
|
||||
async def fingerprint_grow_enroll_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
|
||||
template_ = yield cg.templatable(config[CONF_FINGER_ID], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_FINGER_ID], args, cg.uint16)
|
||||
cg.add(var.set_finger_id(template_))
|
||||
if CONF_NUM_SCANS in config:
|
||||
template_ = yield cg.templatable(config[CONF_NUM_SCANS], args, cg.uint8)
|
||||
template_ = await cg.templatable(config[CONF_NUM_SCANS], args, cg.uint8)
|
||||
cg.add(var.set_num_scans(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -206,10 +206,10 @@ def fingerprint_grow_enroll_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def fingerprint_grow_cancel_enroll_to_code(config, action_id, template_arg, args):
|
||||
async def fingerprint_grow_cancel_enroll_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -223,13 +223,13 @@ def fingerprint_grow_cancel_enroll_to_code(config, action_id, template_arg, args
|
|||
key=CONF_FINGER_ID,
|
||||
),
|
||||
)
|
||||
def fingerprint_grow_delete_to_code(config, action_id, template_arg, args):
|
||||
async def fingerprint_grow_delete_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
|
||||
template_ = yield cg.templatable(config[CONF_FINGER_ID], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_FINGER_ID], args, cg.uint16)
|
||||
cg.add(var.set_finger_id(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -241,10 +241,10 @@ def fingerprint_grow_delete_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def fingerprint_grow_delete_all_to_code(config, action_id, template_arg, args):
|
||||
async def fingerprint_grow_delete_all_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
FINGERPRINT_GROW_LED_CONTROL_ACTION_SCHEMA = cv.maybe_simple_value(
|
||||
|
@ -261,13 +261,13 @@ FINGERPRINT_GROW_LED_CONTROL_ACTION_SCHEMA = cv.maybe_simple_value(
|
|||
LEDControlAction,
|
||||
FINGERPRINT_GROW_LED_CONTROL_ACTION_SCHEMA,
|
||||
)
|
||||
def fingerprint_grow_led_control_to_code(config, action_id, template_arg, args):
|
||||
async def fingerprint_grow_led_control_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
|
||||
template_ = yield cg.templatable(config[CONF_STATE], args, cg.bool_)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, cg.bool_)
|
||||
cg.add(var.set_state(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -283,11 +283,13 @@ def fingerprint_grow_led_control_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def fingerprint_grow_aura_led_control_to_code(config, action_id, template_arg, args):
|
||||
async def fingerprint_grow_aura_led_control_to_code(
|
||||
config, action_id, template_arg, args
|
||||
):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
|
||||
for key in [CONF_STATE, CONF_SPEED, CONF_COLOR, CONF_COUNT]:
|
||||
template_ = yield cg.templatable(config[key], args, cg.uint8)
|
||||
template_ = await cg.templatable(config[key], args, cg.uint8)
|
||||
cg.add(getattr(var, f"set_{key}")(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -171,28 +171,28 @@ HTTP_REQUEST_SEND_ACTION_SCHEMA = HTTP_REQUEST_ACTION_SCHEMA.extend(
|
|||
@automation.register_action(
|
||||
"http_request.send", HttpRequestSendAction, HTTP_REQUEST_SEND_ACTION_SCHEMA
|
||||
)
|
||||
def http_request_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def http_request_action_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_URL], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_URL], args, cg.std_string)
|
||||
cg.add(var.set_url(template_))
|
||||
cg.add(var.set_method(config[CONF_METHOD]))
|
||||
if CONF_BODY in config:
|
||||
template_ = yield cg.templatable(config[CONF_BODY], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_BODY], args, cg.std_string)
|
||||
cg.add(var.set_body(template_))
|
||||
if CONF_JSON in config:
|
||||
json_ = config[CONF_JSON]
|
||||
if isinstance(json_, Lambda):
|
||||
args_ = args + [(cg.JsonObjectRef, "root")]
|
||||
lambda_ = yield cg.process_lambda(json_, args_, return_type=cg.void)
|
||||
lambda_ = await cg.process_lambda(json_, args_, return_type=cg.void)
|
||||
cg.add(var.set_json(lambda_))
|
||||
else:
|
||||
for key in json_:
|
||||
template_ = yield cg.templatable(json_[key], args, cg.std_string)
|
||||
template_ = await cg.templatable(json_[key], args, cg.std_string)
|
||||
cg.add(var.add_json(key, template_))
|
||||
for key in config.get(CONF_HEADERS, []):
|
||||
template_ = yield cg.templatable(
|
||||
template_ = await cg.templatable(
|
||||
config[CONF_HEADERS][key], args, cg.const_char_ptr
|
||||
)
|
||||
cg.add(var.add_header(key, template_))
|
||||
|
@ -200,6 +200,6 @@ def http_request_action_to_code(config, action_id, template_arg, args):
|
|||
for conf in config.get(CONF_ON_RESPONSE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
cg.add(var.register_response_trigger(trigger))
|
||||
yield automation.build_automation(trigger, [(int, "status_code")], conf)
|
||||
await automation.build_automation(trigger, [(int, "status_code")], conf)
|
||||
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -63,6 +63,6 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def sensor_integration_reset_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 sensor_integration_reset_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)
|
||||
|
|
|
@ -2,7 +2,6 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome.components import display
|
||||
from esphome.const import CONF_DIMENSIONS
|
||||
from esphome.core import coroutine
|
||||
|
||||
lcd_base_ns = cg.esphome_ns.namespace("lcd_base")
|
||||
LCDDisplay = lcd_base_ns.class_("LCDDisplay", cg.PollingComponent)
|
||||
|
@ -24,8 +23,7 @@ LCD_SCHEMA = display.BASIC_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_lcd_display(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_lcd_display(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
cg.add(var.set_dimensions(config[CONF_DIMENSIONS][0], config[CONF_DIMENSIONS][1]))
|
||||
|
|
|
@ -78,9 +78,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def ledc_set_frequency_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def ledc_set_frequency_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_FREQUENCY], args, float)
|
||||
template_ = await cg.templatable(config[CONF_FREQUENCY], args, float)
|
||||
cg.add(var.set_frequency(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -40,15 +40,15 @@ from .types import (
|
|||
}
|
||||
),
|
||||
)
|
||||
def light_toggle_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def light_toggle_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)
|
||||
if CONF_TRANSITION_LENGTH in config:
|
||||
template_ = yield cg.templatable(
|
||||
template_ = await cg.templatable(
|
||||
config[CONF_TRANSITION_LENGTH], args, cg.uint32
|
||||
)
|
||||
cg.add(var.set_transition_length(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
LIGHT_CONTROL_ACTION_SCHEMA = cv.Schema(
|
||||
|
@ -97,42 +97,42 @@ LIGHT_TURN_ON_ACTION_SCHEMA = automation.maybe_simple_id(
|
|||
@automation.register_action(
|
||||
"light.control", LightControlAction, LIGHT_CONTROL_ACTION_SCHEMA
|
||||
)
|
||||
def light_control_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def light_control_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)
|
||||
if CONF_STATE in config:
|
||||
template_ = yield cg.templatable(config[CONF_STATE], args, bool)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, bool)
|
||||
cg.add(var.set_state(template_))
|
||||
if CONF_TRANSITION_LENGTH in config:
|
||||
template_ = yield cg.templatable(
|
||||
template_ = await cg.templatable(
|
||||
config[CONF_TRANSITION_LENGTH], args, cg.uint32
|
||||
)
|
||||
cg.add(var.set_transition_length(template_))
|
||||
if CONF_FLASH_LENGTH in config:
|
||||
template_ = yield cg.templatable(config[CONF_FLASH_LENGTH], args, cg.uint32)
|
||||
template_ = await cg.templatable(config[CONF_FLASH_LENGTH], args, cg.uint32)
|
||||
cg.add(var.set_flash_length(template_))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
template_ = yield cg.templatable(config[CONF_BRIGHTNESS], args, float)
|
||||
template_ = await cg.templatable(config[CONF_BRIGHTNESS], args, float)
|
||||
cg.add(var.set_brightness(template_))
|
||||
if CONF_RED in config:
|
||||
template_ = yield cg.templatable(config[CONF_RED], args, float)
|
||||
template_ = await cg.templatable(config[CONF_RED], args, float)
|
||||
cg.add(var.set_red(template_))
|
||||
if CONF_GREEN in config:
|
||||
template_ = yield cg.templatable(config[CONF_GREEN], args, float)
|
||||
template_ = await cg.templatable(config[CONF_GREEN], args, float)
|
||||
cg.add(var.set_green(template_))
|
||||
if CONF_BLUE in config:
|
||||
template_ = yield cg.templatable(config[CONF_BLUE], args, float)
|
||||
template_ = await cg.templatable(config[CONF_BLUE], args, float)
|
||||
cg.add(var.set_blue(template_))
|
||||
if CONF_WHITE in config:
|
||||
template_ = yield cg.templatable(config[CONF_WHITE], args, float)
|
||||
template_ = await cg.templatable(config[CONF_WHITE], args, float)
|
||||
cg.add(var.set_white(template_))
|
||||
if CONF_COLOR_TEMPERATURE in config:
|
||||
template_ = yield cg.templatable(config[CONF_COLOR_TEMPERATURE], args, float)
|
||||
template_ = await cg.templatable(config[CONF_COLOR_TEMPERATURE], args, float)
|
||||
cg.add(var.set_color_temperature(template_))
|
||||
if CONF_EFFECT in config:
|
||||
template_ = yield cg.templatable(config[CONF_EFFECT], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_EFFECT], args, cg.std_string)
|
||||
cg.add(var.set_effect(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
CONF_RELATIVE_BRIGHTNESS = "relative_brightness"
|
||||
|
@ -152,15 +152,15 @@ LIGHT_DIM_RELATIVE_ACTION_SCHEMA = cv.Schema(
|
|||
@automation.register_action(
|
||||
"light.dim_relative", DimRelativeAction, LIGHT_DIM_RELATIVE_ACTION_SCHEMA
|
||||
)
|
||||
def light_dim_relative_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def light_dim_relative_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)
|
||||
templ = yield cg.templatable(config[CONF_RELATIVE_BRIGHTNESS], args, float)
|
||||
templ = await cg.templatable(config[CONF_RELATIVE_BRIGHTNESS], args, float)
|
||||
cg.add(var.set_relative_brightness(templ))
|
||||
if CONF_TRANSITION_LENGTH in config:
|
||||
templ = yield cg.templatable(config[CONF_TRANSITION_LENGTH], args, cg.uint32)
|
||||
templ = await cg.templatable(config[CONF_TRANSITION_LENGTH], args, cg.uint32)
|
||||
cg.add(var.set_transition_length(templ))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
LIGHT_ADDRESSABLE_SET_ACTION_SCHEMA = cv.Schema(
|
||||
|
@ -179,40 +179,40 @@ LIGHT_ADDRESSABLE_SET_ACTION_SCHEMA = cv.Schema(
|
|||
@automation.register_action(
|
||||
"light.addressable_set", AddressableSet, LIGHT_ADDRESSABLE_SET_ACTION_SCHEMA
|
||||
)
|
||||
def light_addressable_set_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def light_addressable_set_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)
|
||||
if CONF_RANGE_FROM in config:
|
||||
templ = yield cg.templatable(config[CONF_RANGE_FROM], args, cg.int32)
|
||||
templ = await cg.templatable(config[CONF_RANGE_FROM], args, cg.int32)
|
||||
cg.add(var.set_range_from(templ))
|
||||
if CONF_RANGE_TO in config:
|
||||
templ = yield cg.templatable(config[CONF_RANGE_TO], args, cg.int32)
|
||||
templ = await cg.templatable(config[CONF_RANGE_TO], args, cg.int32)
|
||||
cg.add(var.set_range_to(templ))
|
||||
|
||||
def rgbw_to_exp(x):
|
||||
return int(round(x * 255))
|
||||
|
||||
if CONF_RED in config:
|
||||
templ = yield cg.templatable(
|
||||
templ = await cg.templatable(
|
||||
config[CONF_RED], args, cg.uint8, to_exp=rgbw_to_exp
|
||||
)
|
||||
cg.add(var.set_red(templ))
|
||||
if CONF_GREEN in config:
|
||||
templ = yield cg.templatable(
|
||||
templ = await cg.templatable(
|
||||
config[CONF_GREEN], args, cg.uint8, to_exp=rgbw_to_exp
|
||||
)
|
||||
cg.add(var.set_green(templ))
|
||||
if CONF_BLUE in config:
|
||||
templ = yield cg.templatable(
|
||||
templ = await cg.templatable(
|
||||
config[CONF_BLUE], args, cg.uint8, to_exp=rgbw_to_exp
|
||||
)
|
||||
cg.add(var.set_blue(templ))
|
||||
if CONF_WHITE in config:
|
||||
templ = yield cg.templatable(
|
||||
templ = await cg.templatable(
|
||||
config[CONF_WHITE], args, cg.uint8, to_exp=rgbw_to_exp
|
||||
)
|
||||
cg.add(var.set_white(templ))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
|
@ -233,6 +233,6 @@ def light_addressable_set_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def light_is_on_off_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
async def light_is_on_off_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
|
|
@ -133,9 +133,9 @@ def register_addressable_effect(
|
|||
cv.Optional(CONF_UPDATE_INTERVAL, default="0ms"): cv.update_interval,
|
||||
},
|
||||
)
|
||||
def lambda_effect_to_code(config, effect_id):
|
||||
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], [], return_type=cg.void)
|
||||
yield cg.new_Pvariable(
|
||||
async def lambda_effect_to_code(config, effect_id):
|
||||
lambda_ = await cg.process_lambda(config[CONF_LAMBDA], [], return_type=cg.void)
|
||||
return cg.new_Pvariable(
|
||||
effect_id, config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL]
|
||||
)
|
||||
|
||||
|
@ -148,10 +148,10 @@ def lambda_effect_to_code(config, effect_id):
|
|||
cv.Required(CONF_SEQUENCE): automation.validate_automation(single=True),
|
||||
},
|
||||
)
|
||||
def automation_effect_to_code(config, effect_id):
|
||||
var = yield cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
yield automation.build_automation(var.get_trig(), [], config[CONF_SEQUENCE])
|
||||
yield var
|
||||
async def automation_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
await automation.build_automation(var.get_trig(), [], config[CONF_SEQUENCE])
|
||||
return var
|
||||
|
||||
|
||||
@register_monochromatic_effect(
|
||||
|
@ -167,11 +167,11 @@ def automation_effect_to_code(config, effect_id):
|
|||
): cv.positive_time_period_milliseconds,
|
||||
},
|
||||
)
|
||||
def pulse_effect_to_code(config, effect_id):
|
||||
async def pulse_effect_to_code(config, effect_id):
|
||||
effect = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(effect.set_transition_length(config[CONF_TRANSITION_LENGTH]))
|
||||
cg.add(effect.set_update_interval(config[CONF_UPDATE_INTERVAL]))
|
||||
yield effect
|
||||
return effect
|
||||
|
||||
|
||||
@register_monochromatic_effect(
|
||||
|
@ -187,11 +187,11 @@ def pulse_effect_to_code(config, effect_id):
|
|||
): cv.positive_time_period_milliseconds,
|
||||
},
|
||||
)
|
||||
def random_effect_to_code(config, effect_id):
|
||||
async def random_effect_to_code(config, effect_id):
|
||||
effect = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(effect.set_transition_length(config[CONF_TRANSITION_LENGTH]))
|
||||
cg.add(effect.set_update_interval(config[CONF_UPDATE_INTERVAL]))
|
||||
yield effect
|
||||
return effect
|
||||
|
||||
|
||||
@register_binary_effect(
|
||||
|
@ -233,7 +233,7 @@ def random_effect_to_code(config, effect_id):
|
|||
),
|
||||
},
|
||||
)
|
||||
def strobe_effect_to_code(config, effect_id):
|
||||
async def strobe_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
colors = []
|
||||
for color in config.get(CONF_COLORS, []):
|
||||
|
@ -255,7 +255,7 @@ def strobe_effect_to_code(config, effect_id):
|
|||
)
|
||||
)
|
||||
cg.add(var.set_colors(colors))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_monochromatic_effect(
|
||||
|
@ -267,11 +267,11 @@ def strobe_effect_to_code(config, effect_id):
|
|||
cv.Optional(CONF_INTENSITY, default=0.015): cv.percentage,
|
||||
},
|
||||
)
|
||||
def flicker_effect_to_code(config, effect_id):
|
||||
async def flicker_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_alpha(config[CONF_ALPHA]))
|
||||
cg.add(var.set_intensity(config[CONF_INTENSITY]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -285,17 +285,17 @@ def flicker_effect_to_code(config, effect_id):
|
|||
): cv.positive_time_period_milliseconds,
|
||||
},
|
||||
)
|
||||
def addressable_lambda_effect_to_code(config, effect_id):
|
||||
async def addressable_lambda_effect_to_code(config, effect_id):
|
||||
args = [
|
||||
(AddressableLightRef, "it"),
|
||||
(Color, "current_color"),
|
||||
(bool, "initial_run"),
|
||||
]
|
||||
lambda_ = yield cg.process_lambda(config[CONF_LAMBDA], args, return_type=cg.void)
|
||||
lambda_ = await cg.process_lambda(config[CONF_LAMBDA], args, return_type=cg.void)
|
||||
var = cg.new_Pvariable(
|
||||
effect_id, config[CONF_NAME], lambda_, config[CONF_UPDATE_INTERVAL]
|
||||
)
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -307,11 +307,11 @@ def addressable_lambda_effect_to_code(config, effect_id):
|
|||
cv.Optional(CONF_WIDTH, default=50): cv.uint32_t,
|
||||
},
|
||||
)
|
||||
def addressable_rainbow_effect_to_code(config, effect_id):
|
||||
async def addressable_rainbow_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_speed(config[CONF_SPEED]))
|
||||
cg.add(var.set_width(config[CONF_WIDTH]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -337,7 +337,7 @@ def addressable_rainbow_effect_to_code(config, effect_id):
|
|||
cv.Optional(CONF_REVERSE, default=False): cv.boolean,
|
||||
},
|
||||
)
|
||||
def addressable_color_wipe_effect_to_code(config, effect_id):
|
||||
async def addressable_color_wipe_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_add_led_interval(config[CONF_ADD_LED_INTERVAL]))
|
||||
cg.add(var.set_reverse(config[CONF_REVERSE]))
|
||||
|
@ -355,7 +355,7 @@ def addressable_color_wipe_effect_to_code(config, effect_id):
|
|||
)
|
||||
)
|
||||
cg.add(var.set_colors(colors))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -369,11 +369,11 @@ def addressable_color_wipe_effect_to_code(config, effect_id):
|
|||
cv.Optional(CONF_SCAN_WIDTH, default=1): cv.int_range(min=1),
|
||||
},
|
||||
)
|
||||
def addressable_scan_effect_to_code(config, effect_id):
|
||||
async def addressable_scan_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_move_interval(config[CONF_MOVE_INTERVAL]))
|
||||
cg.add(var.set_scan_width(config[CONF_SCAN_WIDTH]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -387,11 +387,11 @@ def addressable_scan_effect_to_code(config, effect_id):
|
|||
): cv.positive_time_period_milliseconds,
|
||||
},
|
||||
)
|
||||
def addressable_twinkle_effect_to_code(config, effect_id):
|
||||
async def addressable_twinkle_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_twinkle_probability(config[CONF_TWINKLE_PROBABILITY]))
|
||||
cg.add(var.set_progress_interval(config[CONF_PROGRESS_INTERVAL]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -405,11 +405,11 @@ def addressable_twinkle_effect_to_code(config, effect_id):
|
|||
): cv.positive_time_period_milliseconds,
|
||||
},
|
||||
)
|
||||
def addressable_random_twinkle_effect_to_code(config, effect_id):
|
||||
async def addressable_random_twinkle_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_twinkle_probability(config[CONF_TWINKLE_PROBABILITY]))
|
||||
cg.add(var.set_progress_interval(config[CONF_PROGRESS_INTERVAL]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -425,13 +425,13 @@ def addressable_random_twinkle_effect_to_code(config, effect_id):
|
|||
cv.Optional(CONF_FADE_OUT_RATE, default=120): cv.uint8_t,
|
||||
},
|
||||
)
|
||||
def addressable_fireworks_effect_to_code(config, effect_id):
|
||||
async def addressable_fireworks_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_update_interval(config[CONF_UPDATE_INTERVAL]))
|
||||
cg.add(var.set_spark_probability(config[CONF_SPARK_PROBABILITY]))
|
||||
cg.add(var.set_use_random_color(config[CONF_USE_RANDOM_COLOR]))
|
||||
cg.add(var.set_fade_out_rate(config[CONF_FADE_OUT_RATE]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@register_addressable_effect(
|
||||
|
@ -445,11 +445,11 @@ def addressable_fireworks_effect_to_code(config, effect_id):
|
|||
cv.Optional(CONF_INTENSITY, default="5%"): cv.percentage,
|
||||
},
|
||||
)
|
||||
def addressable_flicker_effect_to_code(config, effect_id):
|
||||
async def addressable_flicker_effect_to_code(config, effect_id):
|
||||
var = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(var.set_update_interval(config[CONF_UPDATE_INTERVAL]))
|
||||
cg.add(var.set_intensity(config[CONF_INTENSITY]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
def validate_effects(allowed_effects):
|
||||
|
|
|
@ -60,8 +60,8 @@ MCP23016_INPUT_PIN_SCHEMA = cv.Schema(
|
|||
@pins.PIN_SCHEMA_REGISTRY.register(
|
||||
CONF_MCP23016, (MCP23016_OUTPUT_PIN_SCHEMA, MCP23016_INPUT_PIN_SCHEMA)
|
||||
)
|
||||
def mcp23016_pin_to_code(config):
|
||||
parent = yield cg.get_variable(config[CONF_MCP23016])
|
||||
yield MCP23016GPIOPin.new(
|
||||
async def mcp23016_pin_to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_MCP23016])
|
||||
return MCP23016GPIOPin.new(
|
||||
parent, config[CONF_NUMBER], config[CONF_MODE], config[CONF_INVERTED]
|
||||
)
|
||||
|
|
|
@ -40,9 +40,9 @@ MCP23XXX_CONFIG_SCHEMA = cv.Schema(
|
|||
|
||||
|
||||
@coroutine
|
||||
def register_mcp23xxx(config):
|
||||
async def register_mcp23xxx(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
await cg.register_component(var, config)
|
||||
cg.add(var.set_open_drain_ints(config[CONF_OPEN_DRAIN_INTERRUPT]))
|
||||
return var
|
||||
|
||||
|
@ -79,9 +79,9 @@ MCP23XXX_INPUT_PIN_SCHEMA = cv.Schema(
|
|||
@pins.PIN_SCHEMA_REGISTRY.register(
|
||||
CONF_MCP23XXX, (MCP23XXX_OUTPUT_PIN_SCHEMA, MCP23XXX_INPUT_PIN_SCHEMA)
|
||||
)
|
||||
def mcp23xxx_pin_to_code(config):
|
||||
parent = yield cg.get_variable(config[CONF_MCP23XXX])
|
||||
yield MCP23XXXGPIOPin.new(
|
||||
async def mcp23xxx_pin_to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_MCP23XXX])
|
||||
return MCP23XXXGPIOPin.new(
|
||||
parent,
|
||||
config[CONF_NUMBER],
|
||||
config[CONF_MODE],
|
||||
|
|
|
@ -78,6 +78,6 @@ CALIBRATION_ACTION_SCHEMA = maybe_simple_id(
|
|||
@automation.register_action(
|
||||
"mhz19.abc_disable", MHZ19ABCDisableAction, CALIBRATION_ACTION_SCHEMA
|
||||
)
|
||||
def mhz19_calibration_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 mhz19_calibration_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)
|
||||
|
|
|
@ -2,7 +2,6 @@ import esphome.codegen as cg
|
|||
import esphome.config_validation as cv
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID, CONF_ADDRESS
|
||||
from esphome.core import coroutine
|
||||
|
||||
DEPENDENCIES = ["uart"]
|
||||
|
||||
|
@ -42,9 +41,8 @@ def modbus_device_schema(default_address):
|
|||
return cv.Schema(schema)
|
||||
|
||||
|
||||
@coroutine
|
||||
def register_modbus_device(var, config):
|
||||
parent = yield cg.get_variable(config[CONF_MODBUS_ID])
|
||||
async def register_modbus_device(var, config):
|
||||
parent = await cg.get_variable(config[CONF_MODBUS_ID])
|
||||
cg.add(var.set_parent(parent))
|
||||
cg.add(var.set_address(config[CONF_ADDRESS]))
|
||||
cg.add(parent.register_device(var))
|
||||
|
|
|
@ -69,8 +69,8 @@ PCF8574_INPUT_PIN_SCHEMA = cv.Schema(
|
|||
@pins.PIN_SCHEMA_REGISTRY.register(
|
||||
"pcf8574", (PCF8574_OUTPUT_PIN_SCHEMA, PCF8574_INPUT_PIN_SCHEMA)
|
||||
)
|
||||
def pcf8574_pin_to_code(config):
|
||||
parent = yield cg.get_variable(config[CONF_PCF8574])
|
||||
yield PCF8574GPIOPin.new(
|
||||
async def pcf8574_pin_to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_PCF8574])
|
||||
return PCF8574GPIOPin.new(
|
||||
parent, config[CONF_NUMBER], config[CONF_MODE], config[CONF_INVERTED]
|
||||
)
|
||||
|
|
|
@ -86,9 +86,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def pid_reset_integral_term(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 pid_reset_integral_term(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(
|
||||
|
@ -107,13 +107,13 @@ def pid_reset_integral_term(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def esp8266_set_frequency_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def esp8266_set_frequency_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)
|
||||
cg.add(var.set_noiseband(config[CONF_NOISEBAND]))
|
||||
cg.add(var.set_positive_output(config[CONF_POSITIVE_OUTPUT]))
|
||||
cg.add(var.set_negative_output(config[CONF_NEGATIVE_OUTPUT]))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -128,16 +128,16 @@ def esp8266_set_frequency_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def set_control_parameters(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def set_control_parameters(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
kp_template_ = yield cg.templatable(config[CONF_KP], args, float)
|
||||
kp_template_ = await cg.templatable(config[CONF_KP], args, float)
|
||||
cg.add(var.set_kp(kp_template_))
|
||||
|
||||
ki_template_ = yield cg.templatable(config[CONF_KI], args, float)
|
||||
ki_template_ = await cg.templatable(config[CONF_KI], args, float)
|
||||
cg.add(var.set_ki(ki_template_))
|
||||
|
||||
kd_template_ = yield cg.templatable(config[CONF_KD], args, float)
|
||||
kd_template_ = await cg.templatable(config[CONF_KD], args, float)
|
||||
cg.add(var.set_kd(kd_template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -3,7 +3,6 @@ import esphome.config_validation as cv
|
|||
from esphome import automation
|
||||
from esphome.components import nfc
|
||||
from esphome.const import CONF_ID, CONF_ON_TAG_REMOVED, CONF_ON_TAG, CONF_TRIGGER_ID
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@OttoWinter", "@jesserockz"]
|
||||
AUTO_LOAD = ["binary_sensor", "nfc"]
|
||||
|
@ -58,27 +57,26 @@ def CONFIG_SCHEMA(conf):
|
|||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_pn532(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
async def setup_pn532(var, config):
|
||||
await cg.register_component(var, config)
|
||||
|
||||
for conf in config.get(CONF_ON_TAG, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
cg.add(var.register_ontag_trigger(trigger))
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
trigger, [(cg.std_string, "x"), (nfc.NfcTag, "tag")], conf
|
||||
)
|
||||
|
||||
for conf in config.get(CONF_ON_TAG_REMOVED, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
cg.add(var.register_ontagremoved_trigger(trigger))
|
||||
yield automation.build_automation(
|
||||
await automation.build_automation(
|
||||
trigger, [(cg.std_string, "x"), (nfc.NfcTag, "tag")], conf
|
||||
)
|
||||
|
||||
for conf in config.get(CONF_ON_FINISHED_WRITE, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||
yield automation.build_automation(trigger, [], conf)
|
||||
await automation.build_automation(trigger, [], conf)
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
|
@ -90,7 +88,7 @@ def setup_pn532(var, config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def pn532_is_writing_to_code(config, condition_id, template_arg, args):
|
||||
async def pn532_is_writing_to_code(config, condition_id, template_arg, args):
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
|
|
@ -88,9 +88,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def set_total_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def set_total_action_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_VALUE], args, int)
|
||||
template_ = await cg.templatable(config[CONF_VALUE], args, int)
|
||||
cg.add(var.set_total_pulses(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -3,7 +3,6 @@ import esphome.config_validation as cv
|
|||
from esphome import automation, pins
|
||||
from esphome.components import i2c
|
||||
from esphome.const import CONF_ON_TAG, CONF_TRIGGER_ID, CONF_RESET_PIN
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@glmnet"]
|
||||
AUTO_LOAD = ["binary_sensor"]
|
||||
|
@ -29,15 +28,14 @@ RC522_SCHEMA = cv.Schema(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_rc522(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
async def setup_rc522(var, config):
|
||||
await cg.register_component(var, config)
|
||||
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
|
||||
for conf in config.get(CONF_ON_TAG, []):
|
||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
|
||||
cg.add(var.register_trigger(trigger))
|
||||
yield automation.build_automation(trigger, [(cg.std_string, "x")], conf)
|
||||
await automation.build_automation(trigger, [(cg.std_string, "x")], conf)
|
||||
|
|
|
@ -63,9 +63,8 @@ def templatize(value):
|
|||
return cv.Schema(ret)
|
||||
|
||||
|
||||
@coroutine
|
||||
def register_listener(var, config):
|
||||
receiver = yield cg.get_variable(config[CONF_RECEIVER_ID])
|
||||
async def register_listener(var, config):
|
||||
receiver = await cg.get_variable(config[CONF_RECEIVER_ID])
|
||||
cg.add(receiver.register_listener(var))
|
||||
|
||||
|
||||
|
@ -83,13 +82,12 @@ def register_trigger(name, type, data_type):
|
|||
registerer = TRIGGER_REGISTRY.register(f"on_{name}", validator)
|
||||
|
||||
def decorator(func):
|
||||
@coroutine
|
||||
def new_func(config):
|
||||
async def new_func(config):
|
||||
var = cg.new_Pvariable(config[CONF_TRIGGER_ID])
|
||||
yield register_listener(var, config)
|
||||
yield coroutine(func)(var, config)
|
||||
yield automation.build_automation(var, [(data_type, "x")], config)
|
||||
yield var
|
||||
await register_listener(var, config)
|
||||
await coroutine(func)(var, config)
|
||||
await automation.build_automation(var, [(data_type, "x")], config)
|
||||
return var
|
||||
|
||||
return registerer(new_func)
|
||||
|
||||
|
@ -100,11 +98,10 @@ def register_dumper(name, type):
|
|||
registerer = DUMPER_REGISTRY.register(name, type, {})
|
||||
|
||||
def decorator(func):
|
||||
@coroutine
|
||||
def new_func(config, dumper_id):
|
||||
async def new_func(config, dumper_id):
|
||||
var = cg.new_Pvariable(dumper_id)
|
||||
yield coroutine(func)(var, config)
|
||||
yield var
|
||||
await coroutine(func)(var, config)
|
||||
return var
|
||||
|
||||
return registerer(new_func)
|
||||
|
||||
|
@ -139,19 +136,18 @@ def register_action(name, type_, schema):
|
|||
)
|
||||
|
||||
def decorator(func):
|
||||
@coroutine
|
||||
def new_func(config, action_id, template_arg, args):
|
||||
transmitter = yield cg.get_variable(config[CONF_TRANSMITTER_ID])
|
||||
async def new_func(config, action_id, template_arg, args):
|
||||
transmitter = await cg.get_variable(config[CONF_TRANSMITTER_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
cg.add(var.set_parent(transmitter))
|
||||
if CONF_REPEAT in config:
|
||||
conf = config[CONF_REPEAT]
|
||||
template_ = yield cg.templatable(conf[CONF_TIMES], args, cg.uint32)
|
||||
template_ = await cg.templatable(conf[CONF_TIMES], args, cg.uint32)
|
||||
cg.add(var.set_send_times(template_))
|
||||
template_ = yield cg.templatable(conf[CONF_WAIT_TIME], args, cg.uint32)
|
||||
template_ = await cg.templatable(conf[CONF_WAIT_TIME], args, cg.uint32)
|
||||
cg.add(var.set_send_wait(template_))
|
||||
yield coroutine(func)(var, config, args)
|
||||
yield var
|
||||
await coroutine(func)(var, config, args)
|
||||
return var
|
||||
|
||||
return registerer(new_func)
|
||||
|
||||
|
@ -208,37 +204,34 @@ def validate_triggers(base_schema):
|
|||
return validator
|
||||
|
||||
|
||||
@coroutine
|
||||
def build_binary_sensor(full_config):
|
||||
async def build_binary_sensor(full_config):
|
||||
registry_entry, config = cg.extract_registry_entry_config(
|
||||
BINARY_SENSOR_REGISTRY, full_config
|
||||
)
|
||||
type_id = full_config[CONF_TYPE_ID]
|
||||
builder = registry_entry.coroutine_fun
|
||||
var = cg.new_Pvariable(type_id)
|
||||
yield cg.register_component(var, full_config)
|
||||
yield register_listener(var, full_config)
|
||||
yield builder(var, config)
|
||||
yield var
|
||||
await cg.register_component(var, full_config)
|
||||
await register_listener(var, full_config)
|
||||
await builder(var, config)
|
||||
return var
|
||||
|
||||
|
||||
@coroutine
|
||||
def build_triggers(full_config):
|
||||
async def build_triggers(full_config):
|
||||
for key in TRIGGER_REGISTRY:
|
||||
for config in full_config.get(key, []):
|
||||
func = TRIGGER_REGISTRY[key][0]
|
||||
yield func(config)
|
||||
await func(config)
|
||||
|
||||
|
||||
@coroutine
|
||||
def build_dumpers(config):
|
||||
async def build_dumpers(config):
|
||||
dumpers = []
|
||||
for conf in config:
|
||||
dumper = yield cg.build_registry_entry(DUMPER_REGISTRY, conf)
|
||||
receiver = yield cg.get_variable(conf[CONF_RECEIVER_ID])
|
||||
dumper = await cg.build_registry_entry(DUMPER_REGISTRY, conf)
|
||||
receiver = await cg.get_variable(conf[CONF_RECEIVER_ID])
|
||||
cg.add(receiver.register_dumper(dumper))
|
||||
dumpers.append(dumper)
|
||||
yield dumpers
|
||||
return dumpers
|
||||
|
||||
|
||||
# JVC
|
||||
|
@ -269,8 +262,8 @@ def jvc_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("jvc", JVCAction, JVC_SCHEMA)
|
||||
def jvc_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_DATA], args, cg.uint32)
|
||||
async def jvc_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32)
|
||||
cg.add(var.set_data(template_))
|
||||
|
||||
|
||||
|
@ -308,10 +301,10 @@ def lg_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("lg", LGAction, LG_SCHEMA)
|
||||
def lg_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_DATA], args, cg.uint32)
|
||||
async def lg_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32)
|
||||
cg.add(var.set_data(template_))
|
||||
template_ = yield cg.templatable(config[CONF_NBITS], args, cg.uint8)
|
||||
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint8)
|
||||
cg.add(var.set_nbits(template_))
|
||||
|
||||
|
||||
|
@ -349,10 +342,10 @@ def nec_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("nec", NECAction, NEC_SCHEMA)
|
||||
def nec_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
async def nec_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
cg.add(var.set_address(template_))
|
||||
template_ = yield cg.templatable(config[CONF_COMMAND], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_COMMAND], args, cg.uint16)
|
||||
cg.add(var.set_command(template_))
|
||||
|
||||
|
||||
|
@ -396,10 +389,10 @@ def pioneer_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("pioneer", PioneerAction, PIONEER_SCHEMA)
|
||||
def pioneer_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_RC_CODE_1], args, cg.uint16)
|
||||
async def pioneer_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_RC_CODE_1], args, cg.uint16)
|
||||
cg.add(var.set_rc_code_1(template_))
|
||||
template_ = yield cg.templatable(config[CONF_RC_CODE_2], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_RC_CODE_2], args, cg.uint16)
|
||||
cg.add(var.set_rc_code_2(template_))
|
||||
|
||||
|
||||
|
@ -439,10 +432,10 @@ def sony_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("sony", SonyAction, SONY_SCHEMA)
|
||||
def sony_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_DATA], args, cg.uint16)
|
||||
async def sony_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint16)
|
||||
cg.add(var.set_data(template_))
|
||||
template_ = yield cg.templatable(config[CONF_NBITS], args, cg.uint32)
|
||||
template_ = await cg.templatable(config[CONF_NBITS], args, cg.uint32)
|
||||
cg.add(var.set_nbits(template_))
|
||||
|
||||
|
||||
|
@ -506,16 +499,16 @@ def raw_dumper(var, config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def raw_action(var, config, args):
|
||||
async def raw_action(var, config, args):
|
||||
code_ = config[CONF_CODE]
|
||||
if cg.is_template(code_):
|
||||
template_ = yield cg.templatable(code_, args, cg.std_vector.template(cg.int32))
|
||||
template_ = await cg.templatable(code_, args, cg.std_vector.template(cg.int32))
|
||||
cg.add(var.set_code_template(template_))
|
||||
else:
|
||||
code_ = config[CONF_CODE]
|
||||
arr = cg.progmem_array(config[CONF_CODE_STORAGE_ID], code_)
|
||||
cg.add(var.set_code_static(arr, len(code_)))
|
||||
templ = yield cg.templatable(config[CONF_CARRIER_FREQUENCY], args, cg.uint32)
|
||||
templ = await cg.templatable(config[CONF_CARRIER_FREQUENCY], args, cg.uint32)
|
||||
cg.add(var.set_carrier_frequency(templ))
|
||||
|
||||
|
||||
|
@ -553,10 +546,10 @@ def rc5_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("rc5", RC5Action, RC5_SCHEMA)
|
||||
def rc5_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_ADDRESS], args, cg.uint8)
|
||||
async def rc5_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_ADDRESS], args, cg.uint8)
|
||||
cg.add(var.set_address(template_))
|
||||
template_ = yield cg.templatable(config[CONF_COMMAND], args, cg.uint8)
|
||||
template_ = await cg.templatable(config[CONF_COMMAND], args, cg.uint8)
|
||||
cg.add(var.set_command(template_))
|
||||
|
||||
|
||||
|
@ -729,12 +722,12 @@ def rc_switch_raw_binary_sensor(var, config):
|
|||
RCSwitchRawAction,
|
||||
RC_SWITCH_RAW_SCHEMA.extend(RC_SWITCH_TRANSMITTER),
|
||||
)
|
||||
def rc_switch_raw_action(var, config, args):
|
||||
proto = yield cg.templatable(
|
||||
async def rc_switch_raw_action(var, config, args):
|
||||
proto = await cg.templatable(
|
||||
config[CONF_PROTOCOL], args, RCSwitchBase, to_exp=build_rc_switch_protocol
|
||||
)
|
||||
cg.add(var.set_protocol(proto))
|
||||
cg.add(var.set_code((yield cg.templatable(config[CONF_CODE], args, cg.std_string))))
|
||||
cg.add(var.set_code((await cg.templatable(config[CONF_CODE], args, cg.std_string))))
|
||||
|
||||
|
||||
@register_binary_sensor(
|
||||
|
@ -750,18 +743,18 @@ def rc_switch_type_a_binary_sensor(var, config):
|
|||
RCSwitchTypeAAction,
|
||||
RC_SWITCH_TYPE_A_SCHEMA.extend(RC_SWITCH_TRANSMITTER),
|
||||
)
|
||||
def rc_switch_type_a_action(var, config, args):
|
||||
proto = yield cg.templatable(
|
||||
async def rc_switch_type_a_action(var, config, args):
|
||||
proto = await cg.templatable(
|
||||
config[CONF_PROTOCOL], args, RCSwitchBase, to_exp=build_rc_switch_protocol
|
||||
)
|
||||
cg.add(var.set_protocol(proto))
|
||||
cg.add(
|
||||
var.set_group((yield cg.templatable(config[CONF_GROUP], args, cg.std_string)))
|
||||
var.set_group((await cg.templatable(config[CONF_GROUP], args, cg.std_string)))
|
||||
)
|
||||
cg.add(
|
||||
var.set_device((yield cg.templatable(config[CONF_DEVICE], args, cg.std_string)))
|
||||
var.set_device((await cg.templatable(config[CONF_DEVICE], args, cg.std_string)))
|
||||
)
|
||||
cg.add(var.set_state((yield cg.templatable(config[CONF_STATE], args, bool))))
|
||||
cg.add(var.set_state((await cg.templatable(config[CONF_STATE], args, bool))))
|
||||
|
||||
|
||||
@register_binary_sensor(
|
||||
|
@ -779,18 +772,18 @@ def rc_switch_type_b_binary_sensor(var, config):
|
|||
RCSwitchTypeBAction,
|
||||
RC_SWITCH_TYPE_B_SCHEMA.extend(RC_SWITCH_TRANSMITTER),
|
||||
)
|
||||
def rc_switch_type_b_action(var, config, args):
|
||||
proto = yield cg.templatable(
|
||||
async def rc_switch_type_b_action(var, config, args):
|
||||
proto = await cg.templatable(
|
||||
config[CONF_PROTOCOL], args, RCSwitchBase, to_exp=build_rc_switch_protocol
|
||||
)
|
||||
cg.add(var.set_protocol(proto))
|
||||
cg.add(
|
||||
var.set_address((yield cg.templatable(config[CONF_ADDRESS], args, cg.uint8)))
|
||||
var.set_address((await cg.templatable(config[CONF_ADDRESS], args, cg.uint8)))
|
||||
)
|
||||
cg.add(
|
||||
var.set_channel((yield cg.templatable(config[CONF_CHANNEL], args, cg.uint8)))
|
||||
var.set_channel((await cg.templatable(config[CONF_CHANNEL], args, cg.uint8)))
|
||||
)
|
||||
cg.add(var.set_state((yield cg.templatable(config[CONF_STATE], args, bool))))
|
||||
cg.add(var.set_state((await cg.templatable(config[CONF_STATE], args, bool))))
|
||||
|
||||
|
||||
@register_binary_sensor(
|
||||
|
@ -813,17 +806,17 @@ def rc_switch_type_c_binary_sensor(var, config):
|
|||
RCSwitchTypeCAction,
|
||||
RC_SWITCH_TYPE_C_SCHEMA.extend(RC_SWITCH_TRANSMITTER),
|
||||
)
|
||||
def rc_switch_type_c_action(var, config, args):
|
||||
proto = yield cg.templatable(
|
||||
async def rc_switch_type_c_action(var, config, args):
|
||||
proto = await cg.templatable(
|
||||
config[CONF_PROTOCOL], args, RCSwitchBase, to_exp=build_rc_switch_protocol
|
||||
)
|
||||
cg.add(var.set_protocol(proto))
|
||||
cg.add(
|
||||
var.set_family((yield cg.templatable(config[CONF_FAMILY], args, cg.std_string)))
|
||||
var.set_family((await cg.templatable(config[CONF_FAMILY], args, cg.std_string)))
|
||||
)
|
||||
cg.add(var.set_group((yield cg.templatable(config[CONF_GROUP], args, cg.uint8))))
|
||||
cg.add(var.set_device((yield cg.templatable(config[CONF_DEVICE], args, cg.uint8))))
|
||||
cg.add(var.set_state((yield cg.templatable(config[CONF_STATE], args, bool))))
|
||||
cg.add(var.set_group((await cg.templatable(config[CONF_GROUP], args, cg.uint8))))
|
||||
cg.add(var.set_device((await cg.templatable(config[CONF_DEVICE], args, cg.uint8))))
|
||||
cg.add(var.set_state((await cg.templatable(config[CONF_STATE], args, bool))))
|
||||
|
||||
|
||||
@register_binary_sensor(
|
||||
|
@ -841,16 +834,16 @@ def rc_switch_type_d_binary_sensor(var, config):
|
|||
RCSwitchTypeDAction,
|
||||
RC_SWITCH_TYPE_D_SCHEMA.extend(RC_SWITCH_TRANSMITTER),
|
||||
)
|
||||
def rc_switch_type_d_action(var, config, args):
|
||||
proto = yield cg.templatable(
|
||||
async def rc_switch_type_d_action(var, config, args):
|
||||
proto = await cg.templatable(
|
||||
config[CONF_PROTOCOL], args, RCSwitchBase, to_exp=build_rc_switch_protocol
|
||||
)
|
||||
cg.add(var.set_protocol(proto))
|
||||
cg.add(
|
||||
var.set_group((yield cg.templatable(config[CONF_GROUP], args, cg.std_string)))
|
||||
var.set_group((await cg.templatable(config[CONF_GROUP], args, cg.std_string)))
|
||||
)
|
||||
cg.add(var.set_device((yield cg.templatable(config[CONF_DEVICE], args, cg.uint8))))
|
||||
cg.add(var.set_state((yield cg.templatable(config[CONF_STATE], args, bool))))
|
||||
cg.add(var.set_device((await cg.templatable(config[CONF_DEVICE], args, cg.uint8))))
|
||||
cg.add(var.set_state((await cg.templatable(config[CONF_STATE], args, bool))))
|
||||
|
||||
|
||||
@register_trigger("rc_switch", RCSwitchTrigger, RCSwitchData)
|
||||
|
@ -901,8 +894,8 @@ def samsung_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("samsung", SamsungAction, SAMSUNG_SCHEMA)
|
||||
def samsung_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_DATA], args, cg.uint32)
|
||||
async def samsung_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_DATA], args, cg.uint32)
|
||||
cg.add(var.set_data(template_))
|
||||
|
||||
|
||||
|
@ -946,10 +939,10 @@ def samsung36_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("samsung36", Samsung36Action, SAMSUNG36_SCHEMA)
|
||||
def samsung36_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
async def samsung36_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
cg.add(var.set_address(template_))
|
||||
template_ = yield cg.templatable(config[CONF_COMMAND], args, cg.uint32)
|
||||
template_ = await cg.templatable(config[CONF_COMMAND], args, cg.uint32)
|
||||
cg.add(var.set_command(template_))
|
||||
|
||||
|
||||
|
@ -993,8 +986,8 @@ def panasonic_dumper(var, config):
|
|||
|
||||
|
||||
@register_action("panasonic", PanasonicAction, PANASONIC_SCHEMA)
|
||||
def panasonic_action(var, config, args):
|
||||
template_ = yield cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
async def panasonic_action(var, config, args):
|
||||
template_ = await cg.templatable(config[CONF_ADDRESS], args, cg.uint16)
|
||||
cg.add(var.set_address(template_))
|
||||
template_ = yield cg.templatable(config[CONF_COMMAND], args, cg.uint32)
|
||||
template_ = await cg.templatable(config[CONF_COMMAND], args, cg.uint32)
|
||||
cg.add(var.set_command(template_))
|
||||
|
|
|
@ -109,28 +109,28 @@ RFBRIDGE_SEND_CODE_SCHEMA = cv.Schema(
|
|||
@automation.register_action(
|
||||
"rf_bridge.send_code", RFBridgeSendCodeAction, RFBRIDGE_SEND_CODE_SCHEMA
|
||||
)
|
||||
def rf_bridge_send_code_to_code(config, action_id, template_args, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rf_bridge_send_code_to_code(config, action_id, template_args, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_args, paren)
|
||||
template_ = yield cg.templatable(config[CONF_SYNC], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_SYNC], args, cg.uint16)
|
||||
cg.add(var.set_sync(template_))
|
||||
template_ = yield cg.templatable(config[CONF_LOW], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_LOW], args, cg.uint16)
|
||||
cg.add(var.set_low(template_))
|
||||
template_ = yield cg.templatable(config[CONF_HIGH], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_HIGH], args, cg.uint16)
|
||||
cg.add(var.set_high(template_))
|
||||
template_ = yield cg.templatable(config[CONF_CODE], args, cg.uint32)
|
||||
template_ = await cg.templatable(config[CONF_CODE], args, cg.uint32)
|
||||
cg.add(var.set_code(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
RFBRIDGE_ID_SCHEMA = cv.Schema({cv.GenerateID(): cv.use_id(RFBridgeComponent)})
|
||||
|
||||
|
||||
@automation.register_action("rf_bridge.learn", RFBridgeLearnAction, RFBRIDGE_ID_SCHEMA)
|
||||
def rf_bridge_learnx_to_code(config, action_id, template_args, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rf_bridge_learnx_to_code(config, action_id, template_args, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_args, paren)
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -138,10 +138,12 @@ def rf_bridge_learnx_to_code(config, action_id, template_args, args):
|
|||
RFBridgeStartAdvancedSniffingAction,
|
||||
RFBRIDGE_ID_SCHEMA,
|
||||
)
|
||||
def rf_bridge_start_advanced_sniffing_to_code(config, action_id, template_args, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rf_bridge_start_advanced_sniffing_to_code(
|
||||
config, action_id, template_args, args
|
||||
):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_args, paren)
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -149,10 +151,12 @@ def rf_bridge_start_advanced_sniffing_to_code(config, action_id, template_args,
|
|||
RFBridgeStopAdvancedSniffingAction,
|
||||
RFBRIDGE_ID_SCHEMA,
|
||||
)
|
||||
def rf_bridge_stop_advanced_sniffing_to_code(config, action_id, template_args, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rf_bridge_stop_advanced_sniffing_to_code(
|
||||
config, action_id, template_args, args
|
||||
):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_args, paren)
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
RFBRIDGE_SEND_ADVANCED_CODE_SCHEMA = cv.Schema(
|
||||
|
@ -170,16 +174,16 @@ RFBRIDGE_SEND_ADVANCED_CODE_SCHEMA = cv.Schema(
|
|||
RFBridgeSendAdvancedCodeAction,
|
||||
RFBRIDGE_SEND_ADVANCED_CODE_SCHEMA,
|
||||
)
|
||||
def rf_bridge_send_advanced_code_to_code(config, action_id, template_args, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rf_bridge_send_advanced_code_to_code(config, action_id, template_args, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_args, paren)
|
||||
template_ = yield cg.templatable(config[CONF_LENGTH], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_LENGTH], args, cg.uint16)
|
||||
cg.add(var.set_length(template_))
|
||||
template_ = yield cg.templatable(config[CONF_PROTOCOL], args, cg.uint16)
|
||||
template_ = await cg.templatable(config[CONF_PROTOCOL], args, cg.uint16)
|
||||
cg.add(var.set_protocol(template_))
|
||||
template_ = yield cg.templatable(config[CONF_CODE], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_CODE], args, cg.std_string)
|
||||
cg.add(var.set_code(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
RFBRIDGE_SEND_RAW_SCHEMA = cv.Schema(
|
||||
|
@ -193,9 +197,9 @@ RFBRIDGE_SEND_RAW_SCHEMA = cv.Schema(
|
|||
@automation.register_action(
|
||||
"rf_bridge.send_raw", RFBridgeSendRawAction, RFBRIDGE_SEND_RAW_SCHEMA
|
||||
)
|
||||
def rf_bridge_send_raw_to_code(config, action_id, template_args, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rf_bridge_send_raw_to_code(config, action_id, template_args, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_args, paren)
|
||||
template_ = yield cg.templatable(config[CONF_RAW], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_RAW], args, cg.std_string)
|
||||
cg.add(var.set_raw(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -127,9 +127,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def sensor_template_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def sensor_template_publish_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_VALUE], args, int)
|
||||
template_ = await cg.templatable(config[CONF_VALUE], args, int)
|
||||
cg.add(var.set_value(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -56,12 +56,12 @@ async def to_code(config):
|
|||
key=CONF_RTTTL,
|
||||
),
|
||||
)
|
||||
def rtttl_play_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def rtttl_play_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_RTTTL], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_RTTTL], args, cg.std_string)
|
||||
cg.add(var.set_value(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -73,10 +73,10 @@ def rtttl_play_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def rtttl_stop_to_code(config, action_id, template_arg, args):
|
||||
async def rtttl_stop_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
|
@ -88,7 +88,7 @@ def rtttl_stop_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def rtttl_is_playing_to_code(config, condition_id, template_arg, args):
|
||||
async def rtttl_is_playing_to_code(config, condition_id, template_arg, args):
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
|
|
@ -90,9 +90,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def script_execute_action_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 script_execute_action_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(
|
||||
|
@ -100,9 +100,9 @@ def script_execute_action_to_code(config, action_id, template_arg, args):
|
|||
ScriptStopAction,
|
||||
maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
)
|
||||
def script_stop_action_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 script_stop_action_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(
|
||||
|
@ -110,11 +110,11 @@ def script_stop_action_to_code(config, action_id, template_arg, args):
|
|||
ScriptWaitAction,
|
||||
maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
)
|
||||
def script_wait_action_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
var = yield cg.new_Pvariable(action_id, template_arg, paren)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
async def script_wait_action_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)
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
|
@ -122,6 +122,6 @@ def script_wait_action_to_code(config, action_id, template_arg, args):
|
|||
IsRunningCondition,
|
||||
automation.maybe_simple_id({cv.Required(CONF_ID): cv.use_id(Script)}),
|
||||
)
|
||||
def script_is_running_to_code(config, condition_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
yield cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
async def script_is_running_to_code(config, condition_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
|
|
@ -83,6 +83,6 @@ CALIBRATION_ACTION_SCHEMA = maybe_simple_id(
|
|||
@automation.register_action(
|
||||
"senseair.abc_get_period", SenseAirABCGetPeriodAction, CALIBRATION_ACTION_SCHEMA
|
||||
)
|
||||
def senseair_action_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 senseair_action_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)
|
||||
|
|
|
@ -214,18 +214,18 @@ def sensor_schema(
|
|||
|
||||
|
||||
@FILTER_REGISTRY.register("offset", OffsetFilter, cv.float_)
|
||||
def offset_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id, config)
|
||||
async def offset_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("multiply", MultiplyFilter, cv.float_)
|
||||
def multiply_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id, config)
|
||||
async def multiply_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("filter_out", FilterOutValueFilter, cv.float_)
|
||||
def filter_out_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id, config)
|
||||
async def filter_out_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
MEDIAN_SCHEMA = cv.All(
|
||||
|
@ -241,8 +241,8 @@ MEDIAN_SCHEMA = cv.All(
|
|||
|
||||
|
||||
@FILTER_REGISTRY.register("median", MedianFilter, MEDIAN_SCHEMA)
|
||||
def median_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(
|
||||
async def median_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(
|
||||
filter_id,
|
||||
config[CONF_WINDOW_SIZE],
|
||||
config[CONF_SEND_EVERY],
|
||||
|
@ -263,8 +263,8 @@ MIN_SCHEMA = cv.All(
|
|||
|
||||
|
||||
@FILTER_REGISTRY.register("min", MinFilter, MIN_SCHEMA)
|
||||
def min_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(
|
||||
async def min_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(
|
||||
filter_id,
|
||||
config[CONF_WINDOW_SIZE],
|
||||
config[CONF_SEND_EVERY],
|
||||
|
@ -285,8 +285,8 @@ MAX_SCHEMA = cv.All(
|
|||
|
||||
|
||||
@FILTER_REGISTRY.register("max", MaxFilter, MAX_SCHEMA)
|
||||
def max_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(
|
||||
async def max_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(
|
||||
filter_id,
|
||||
config[CONF_WINDOW_SIZE],
|
||||
config[CONF_SEND_EVERY],
|
||||
|
@ -311,8 +311,8 @@ SLIDING_AVERAGE_SCHEMA = cv.All(
|
|||
SlidingWindowMovingAverageFilter,
|
||||
SLIDING_AVERAGE_SCHEMA,
|
||||
)
|
||||
def sliding_window_moving_average_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(
|
||||
async def sliding_window_moving_average_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(
|
||||
filter_id,
|
||||
config[CONF_WINDOW_SIZE],
|
||||
config[CONF_SEND_EVERY],
|
||||
|
@ -330,52 +330,52 @@ def sliding_window_moving_average_filter_to_code(config, filter_id):
|
|||
}
|
||||
),
|
||||
)
|
||||
def exponential_moving_average_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id, config[CONF_ALPHA], config[CONF_SEND_EVERY])
|
||||
async def exponential_moving_average_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config[CONF_ALPHA], config[CONF_SEND_EVERY])
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("lambda", LambdaFilter, cv.returning_lambda)
|
||||
def lambda_filter_to_code(config, filter_id):
|
||||
lambda_ = yield cg.process_lambda(
|
||||
async def lambda_filter_to_code(config, filter_id):
|
||||
lambda_ = await cg.process_lambda(
|
||||
config, [(float, "x")], return_type=cg.optional.template(float)
|
||||
)
|
||||
yield cg.new_Pvariable(filter_id, lambda_)
|
||||
return cg.new_Pvariable(filter_id, lambda_)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("delta", DeltaFilter, cv.float_)
|
||||
def delta_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id, config)
|
||||
async def delta_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register("or", OrFilter, validate_filters)
|
||||
def or_filter_to_code(config, filter_id):
|
||||
filters = yield build_filters(config)
|
||||
yield cg.new_Pvariable(filter_id, filters)
|
||||
async def or_filter_to_code(config, filter_id):
|
||||
filters = await build_filters(config)
|
||||
return cg.new_Pvariable(filter_id, filters)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"throttle", ThrottleFilter, cv.positive_time_period_milliseconds
|
||||
)
|
||||
def throttle_filter_to_code(config, filter_id):
|
||||
yield cg.new_Pvariable(filter_id, config)
|
||||
async def throttle_filter_to_code(config, filter_id):
|
||||
return cg.new_Pvariable(filter_id, config)
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"heartbeat", HeartbeatFilter, cv.positive_time_period_milliseconds
|
||||
)
|
||||
def heartbeat_filter_to_code(config, filter_id):
|
||||
async def heartbeat_filter_to_code(config, filter_id):
|
||||
var = cg.new_Pvariable(filter_id, config)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
@FILTER_REGISTRY.register(
|
||||
"debounce", DebounceFilter, cv.positive_time_period_milliseconds
|
||||
)
|
||||
def debounce_filter_to_code(config, filter_id):
|
||||
async def debounce_filter_to_code(config, filter_id):
|
||||
var = cg.new_Pvariable(filter_id, config)
|
||||
yield cg.register_component(var, {})
|
||||
yield var
|
||||
await cg.register_component(var, {})
|
||||
return var
|
||||
|
||||
|
||||
def validate_not_all_from_same(config):
|
||||
|
@ -394,11 +394,11 @@ def validate_not_all_from_same(config):
|
|||
cv.ensure_list(validate_datapoint), cv.Length(min=2), validate_not_all_from_same
|
||||
),
|
||||
)
|
||||
def calibrate_linear_filter_to_code(config, filter_id):
|
||||
async def calibrate_linear_filter_to_code(config, filter_id):
|
||||
x = [conf[CONF_FROM] for conf in config]
|
||||
y = [conf[CONF_TO] for conf in config]
|
||||
k, b = fit_linear(x, y)
|
||||
yield cg.new_Pvariable(filter_id, k, b)
|
||||
return cg.new_Pvariable(filter_id, k, b)
|
||||
|
||||
|
||||
CONF_DATAPOINTS = "datapoints"
|
||||
|
@ -430,7 +430,7 @@ def validate_calibrate_polynomial(config):
|
|||
validate_calibrate_polynomial,
|
||||
),
|
||||
)
|
||||
def calibrate_polynomial_filter_to_code(config, filter_id):
|
||||
async def calibrate_polynomial_filter_to_code(config, filter_id):
|
||||
x = [conf[CONF_FROM] for conf in config[CONF_DATAPOINTS]]
|
||||
y = [conf[CONF_TO] for conf in config[CONF_DATAPOINTS]]
|
||||
degree = config[CONF_DEGREE]
|
||||
|
@ -438,7 +438,7 @@ def calibrate_polynomial_filter_to_code(config, filter_id):
|
|||
# Column vector
|
||||
b = [[v] for v in y]
|
||||
res = [v[0] for v in _lstsq(a, b)]
|
||||
yield cg.new_Pvariable(filter_id, res)
|
||||
return cg.new_Pvariable(filter_id, res)
|
||||
|
||||
|
||||
async def build_filters(config):
|
||||
|
|
|
@ -63,12 +63,12 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def servo_write_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def servo_write_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_value(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -80,6 +80,6 @@ def servo_write_to_code(config, action_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def servo_detach_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 servo_detach_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)
|
||||
|
|
|
@ -66,14 +66,14 @@ SIM800L_SEND_SMS_SCHEMA = cv.Schema(
|
|||
@automation.register_action(
|
||||
"sim800l.send_sms", Sim800LSendSmsAction, SIM800L_SEND_SMS_SCHEMA
|
||||
)
|
||||
def sim800l_send_sms_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def sim800l_send_sms_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_RECIPIENT], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_RECIPIENT], args, cg.std_string)
|
||||
cg.add(var.set_recipient(template_))
|
||||
template_ = yield cg.templatable(config[CONF_MESSAGE], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_MESSAGE], args, cg.std_string)
|
||||
cg.add(var.set_message(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
SIM800L_DIAL_SCHEMA = cv.Schema(
|
||||
|
@ -85,9 +85,9 @@ SIM800L_DIAL_SCHEMA = cv.Schema(
|
|||
|
||||
|
||||
@automation.register_action("sim800l.dial", Sim800LDialAction, SIM800L_DIAL_SCHEMA)
|
||||
def sim800l_dial_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def sim800l_dial_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_RECIPIENT], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_RECIPIENT], args, cg.std_string)
|
||||
cg.add(var.set_recipient(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -61,6 +61,6 @@ SN74HC595_INPUT_PIN_SCHEMA = cv.Schema({})
|
|||
@pins.PIN_SCHEMA_REGISTRY.register(
|
||||
CONF_SN74HC595, (SN74HC595_OUTPUT_PIN_SCHEMA, SN74HC595_INPUT_PIN_SCHEMA)
|
||||
)
|
||||
def sn74hc595_pin_to_code(config):
|
||||
parent = yield cg.get_variable(config[CONF_SN74HC595])
|
||||
yield SN74HC595GPIOPin.new(parent, config[CONF_NUMBER], config[CONF_INVERTED])
|
||||
async def sn74hc595_pin_to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_SN74HC595])
|
||||
return SN74HC595GPIOPin.new(parent, config[CONF_NUMBER], config[CONF_INVERTED])
|
||||
|
|
|
@ -9,7 +9,6 @@ from esphome.const import (
|
|||
CONF_RESET_PIN,
|
||||
CONF_BRIGHTNESS,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
|
||||
ssd1306_base_ns = cg.esphome_ns.namespace("ssd1306_base")
|
||||
SSD1306 = ssd1306_base_ns.class_("SSD1306", cg.PollingComponent, display.DisplayBuffer)
|
||||
|
@ -38,21 +37,20 @@ SSD1306_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_ssd1036(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_ssd1036(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
cg.add(var.init_brightness(config[CONF_BRIGHTNESS]))
|
||||
if CONF_EXTERNAL_VCC in config:
|
||||
cg.add(var.set_external_vcc(config[CONF_EXTERNAL_VCC]))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -9,7 +9,6 @@ from esphome.const import (
|
|||
CONF_MODEL,
|
||||
CONF_RESET_PIN,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@kbx81"]
|
||||
|
||||
|
@ -33,21 +32,20 @@ SSD1322_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_ssd1322(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_ssd1322(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
cg.add(var.init_brightness(config[CONF_BRIGHTNESS]))
|
||||
if CONF_EXTERNAL_VCC in config:
|
||||
cg.add(var.set_external_vcc(config[CONF_EXTERNAL_VCC]))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -9,7 +9,6 @@ from esphome.const import (
|
|||
CONF_MODEL,
|
||||
CONF_RESET_PIN,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@kbx81"]
|
||||
|
||||
|
@ -37,21 +36,20 @@ SSD1325_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_ssd1325(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_ssd1325(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
cg.add(var.init_brightness(config[CONF_BRIGHTNESS]))
|
||||
if CONF_EXTERNAL_VCC in config:
|
||||
cg.add(var.set_external_vcc(config[CONF_EXTERNAL_VCC]))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -3,7 +3,6 @@ import esphome.config_validation as cv
|
|||
from esphome import pins
|
||||
from esphome.components import display
|
||||
from esphome.const import CONF_BRIGHTNESS, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@kbx81"]
|
||||
|
||||
|
@ -26,19 +25,18 @@ SSD1327_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_ssd1327(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_ssd1327(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
cg.add(var.init_brightness(config[CONF_BRIGHTNESS]))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -3,7 +3,6 @@ import esphome.config_validation as cv
|
|||
from esphome import pins
|
||||
from esphome.components import display
|
||||
from esphome.const import CONF_BRIGHTNESS, CONF_LAMBDA, CONF_RESET_PIN
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@kbx81"]
|
||||
|
||||
|
@ -18,18 +17,17 @@ SSD1331_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_ssd1331(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_ssd1331(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
cg.add(var.init_brightness(config[CONF_BRIGHTNESS]))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -3,7 +3,6 @@ import esphome.config_validation as cv
|
|||
from esphome import pins
|
||||
from esphome.components import display
|
||||
from esphome.const import CONF_BRIGHTNESS, CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN
|
||||
from esphome.core import coroutine
|
||||
|
||||
CODEOWNERS = ["@kbx81"]
|
||||
|
||||
|
@ -27,19 +26,18 @@ SSD1351_SCHEMA = display.FULL_DISPLAY_SCHEMA.extend(
|
|||
).extend(cv.polling_component_schema("1s"))
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_ssd1351(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_ssd1351(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
cg.add(var.set_model(config[CONF_MODEL]))
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_BRIGHTNESS in config:
|
||||
cg.add(var.init_brightness(config[CONF_BRIGHTNESS]))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -3,7 +3,6 @@ import esphome.config_validation as cv
|
|||
from esphome import pins
|
||||
from esphome.components import spi
|
||||
from esphome.components import display
|
||||
from esphome.core import coroutine
|
||||
from esphome.const import (
|
||||
CONF_DC_PIN,
|
||||
CONF_ID,
|
||||
|
@ -67,16 +66,15 @@ CONFIG_SCHEMA = cv.All(
|
|||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_st7735(var, config):
|
||||
yield cg.register_component(var, config)
|
||||
yield display.register_display(var, config)
|
||||
async def setup_st7735(var, config):
|
||||
await cg.register_component(var, config)
|
||||
await display.register_display(var, config)
|
||||
|
||||
if CONF_RESET_PIN in config:
|
||||
reset = yield cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
reset = await cg.gpio_pin_expression(config[CONF_RESET_PIN])
|
||||
cg.add(var.set_reset_pin(reset))
|
||||
if CONF_LAMBDA in config:
|
||||
lambda_ = yield cg.process_lambda(
|
||||
lambda_ = await cg.process_lambda(
|
||||
config[CONF_LAMBDA], [(display.DisplayBufferRef, "it")], return_type=cg.void
|
||||
)
|
||||
cg.add(var.set_writer(lambda_))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -151,13 +151,13 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def sun_above_horizon_to_code(config, condition_id, template_arg, args):
|
||||
async def sun_above_horizon_to_code(config, condition_id, template_arg, args):
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
templ = yield cg.templatable(config[CONF_ELEVATION], args, cg.double)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
templ = await cg.templatable(config[CONF_ELEVATION], args, cg.double)
|
||||
cg.add(var.set_elevation(templ))
|
||||
cg.add(var.set_above(True))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_condition(
|
||||
|
@ -172,10 +172,10 @@ def sun_above_horizon_to_code(config, condition_id, template_arg, args):
|
|||
}
|
||||
),
|
||||
)
|
||||
def sun_below_horizon_to_code(config, condition_id, template_arg, args):
|
||||
async def sun_below_horizon_to_code(config, condition_id, template_arg, args):
|
||||
var = cg.new_Pvariable(condition_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
templ = yield cg.templatable(config[CONF_ELEVATION], args, cg.double)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
templ = await cg.templatable(config[CONF_ELEVATION], args, cg.double)
|
||||
cg.add(var.set_elevation(templ))
|
||||
cg.add(var.set_above(False))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -90,8 +90,8 @@ SX1509_INPUT_PIN_SCHEMA = cv.Schema(
|
|||
@pins.PIN_SCHEMA_REGISTRY.register(
|
||||
CONF_SX1509, (SX1509_OUTPUT_PIN_SCHEMA, SX1509_INPUT_PIN_SCHEMA)
|
||||
)
|
||||
def sx1509_pin_to_code(config):
|
||||
parent = yield cg.get_variable(config[CONF_SX1509])
|
||||
yield SX1509GPIOPin.new(
|
||||
async def sx1509_pin_to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_SX1509])
|
||||
return SX1509GPIOPin.new(
|
||||
parent, config[CONF_NUMBER], config[CONF_MODE], config[CONF_INVERTED]
|
||||
)
|
||||
|
|
|
@ -39,9 +39,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def binary_sensor_template_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def binary_sensor_template_publish_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_STATE], args, bool)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, bool)
|
||||
cg.add(var.set_state(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -111,21 +111,21 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def cover_template_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def cover_template_publish_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)
|
||||
if CONF_STATE in config:
|
||||
template_ = yield cg.templatable(config[CONF_STATE], args, float)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, float)
|
||||
cg.add(var.set_position(template_))
|
||||
if CONF_POSITION in config:
|
||||
template_ = yield cg.templatable(config[CONF_POSITION], args, float)
|
||||
template_ = await cg.templatable(config[CONF_POSITION], args, float)
|
||||
cg.add(var.set_position(template_))
|
||||
if CONF_TILT in config:
|
||||
template_ = yield cg.templatable(config[CONF_TILT], args, float)
|
||||
template_ = await cg.templatable(config[CONF_TILT], args, float)
|
||||
cg.add(var.set_tilt(template_))
|
||||
if CONF_CURRENT_OPERATION in config:
|
||||
template_ = yield cg.templatable(
|
||||
template_ = await cg.templatable(
|
||||
config[CONF_CURRENT_OPERATION], args, cover.CoverOperation
|
||||
)
|
||||
cg.add(var.set_current_operation(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -50,9 +50,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def sensor_template_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def sensor_template_publish_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_STATE], args, float)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, float)
|
||||
cg.add(var.set_state(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -62,9 +62,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def switch_template_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def switch_template_publish_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_STATE], args, bool)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, bool)
|
||||
cg.add(var.set_state(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -40,9 +40,9 @@ async def to_code(config):
|
|||
}
|
||||
),
|
||||
)
|
||||
def text_sensor_template_publish_to_code(config, action_id, template_arg, args):
|
||||
paren = yield cg.get_variable(config[CONF_ID])
|
||||
async def text_sensor_template_publish_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_STATE], args, cg.std_string)
|
||||
template_ = await cg.templatable(config[CONF_STATE], args, cg.std_string)
|
||||
cg.add(var.set_state(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -61,19 +61,19 @@ BINARY_OUTPUT_ACTION_SCHEMA = maybe_simple_id(
|
|||
|
||||
|
||||
@automation.register_action("tm1651.turn_on", TurnOnAction, BINARY_OUTPUT_ACTION_SCHEMA)
|
||||
def output_turn_on_to_code(config, action_id, template_arg, args):
|
||||
async def output_turn_on_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"tm1651.turn_off", TurnOffAction, BINARY_OUTPUT_ACTION_SCHEMA
|
||||
)
|
||||
def output_turn_off_to_code(config, action_id, template_arg, args):
|
||||
async def output_turn_off_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
yield var
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -87,12 +87,12 @@ def output_turn_off_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_LEVEL_PERCENT,
|
||||
),
|
||||
)
|
||||
def tm1651_set_level_percent_to_code(config, action_id, template_arg, args):
|
||||
async def tm1651_set_level_percent_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_LEVEL_PERCENT], args, cg.uint8)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_LEVEL_PERCENT], args, cg.uint8)
|
||||
cg.add(var.set_level_percent(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -106,12 +106,12 @@ def tm1651_set_level_percent_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_LEVEL,
|
||||
),
|
||||
)
|
||||
def tm1651_set_level_to_code(config, action_id, template_arg, args):
|
||||
async def tm1651_set_level_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_LEVEL], args, cg.uint8)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_LEVEL], args, cg.uint8)
|
||||
cg.add(var.set_level(template_))
|
||||
yield var
|
||||
return var
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
|
@ -125,9 +125,9 @@ def tm1651_set_level_to_code(config, action_id, template_arg, args):
|
|||
key=CONF_BRIGHTNESS,
|
||||
),
|
||||
)
|
||||
def tm1651_set_brightness_to_code(config, action_id, template_arg, args):
|
||||
async def tm1651_set_brightness_to_code(config, action_id, template_arg, args):
|
||||
var = cg.new_Pvariable(action_id, template_arg)
|
||||
yield cg.register_parented(var, config[CONF_ID])
|
||||
template_ = yield cg.templatable(config[CONF_BRIGHTNESS], args, cg.uint8)
|
||||
await cg.register_parented(var, config[CONF_ID])
|
||||
template_ = await cg.templatable(config[CONF_BRIGHTNESS], args, cg.uint8)
|
||||
cg.add(var.set_brightness(template_))
|
||||
yield var
|
||||
return var
|
||||
|
|
|
@ -8,7 +8,6 @@ from esphome.const import (
|
|||
CONF_SSID,
|
||||
CONF_MAC_ADDRESS,
|
||||
)
|
||||
from esphome.core import coroutine
|
||||
|
||||
DEPENDENCIES = ["wifi"]
|
||||
|
||||
|
@ -50,13 +49,12 @@ CONFIG_SCHEMA = cv.Schema(
|
|||
)
|
||||
|
||||
|
||||
@coroutine
|
||||
def setup_conf(config, key):
|
||||
async def setup_conf(config, key):
|
||||
if key in config:
|
||||
conf = config[key]
|
||||
var = cg.new_Pvariable(conf[CONF_ID])
|
||||
yield cg.register_component(var, conf)
|
||||
yield text_sensor.register_text_sensor(var, conf)
|
||||
await cg.register_component(var, conf)
|
||||
await text_sensor.register_text_sensor(var, conf)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
|
|
|
@ -18,8 +18,8 @@ CONFIG_SCHEMA = cv.Schema({})
|
|||
cv.Optional(CONF_PORT, default=21324): cv.port,
|
||||
},
|
||||
)
|
||||
def wled_light_effect_to_code(config, effect_id):
|
||||
async def wled_light_effect_to_code(config, effect_id):
|
||||
effect = cg.new_Pvariable(effect_id, config[CONF_NAME])
|
||||
cg.add(effect.set_port(config[CONF_PORT]))
|
||||
|
||||
yield effect
|
||||
return effect
|
||||
|
|
|
@ -354,7 +354,7 @@ def safe_exp(obj: SafeExpType) -> Expression:
|
|||
if inspect.isgenerator(obj):
|
||||
raise ValueError(
|
||||
"Object {} is a coroutine. Did you forget to await the expression with "
|
||||
"'yield'?".format(obj)
|
||||
"'await'?".format(obj)
|
||||
)
|
||||
raise ValueError("Object is not an expression", obj)
|
||||
|
||||
|
@ -573,7 +573,7 @@ async def get_variable(id_: ID) -> "MockObj":
|
|||
Wait for the given ID to be defined in the code generation and
|
||||
return it as a MockObj.
|
||||
|
||||
This is a coroutine, you need to await it with a 'yield' expression!
|
||||
This is a coroutine, you need to await it with a 'await' expression!
|
||||
|
||||
:param id_: The ID to retrieve
|
||||
:return: The variable as a MockObj.
|
||||
|
@ -586,7 +586,7 @@ async def get_variable_with_full_id(id_: ID) -> Tuple[ID, "MockObj"]:
|
|||
Wait for the given ID to be defined in the code generation and
|
||||
return it as a MockObj.
|
||||
|
||||
This is a coroutine, you need to await it with a 'yield' expression!
|
||||
This is a coroutine, you need to await it with a 'await' expression!
|
||||
|
||||
:param id_: The ID to retrieve
|
||||
:return: The variable as a MockObj.
|
||||
|
@ -603,7 +603,7 @@ async def process_lambda(
|
|||
"""Process the given lambda value into a LambdaExpression.
|
||||
|
||||
This is a coroutine because lambdas can depend on other IDs,
|
||||
you need to await it with 'yield'!
|
||||
you need to await it with 'await'!
|
||||
|
||||
:param value: The lambda to process.
|
||||
:param parameters: The parameters to pass to the Lambda, list of tuples
|
||||
|
|
|
@ -17,7 +17,7 @@ from esphome.util import Registry, RegistryEntry
|
|||
async def gpio_pin_expression(conf):
|
||||
"""Generate an expression for the given pin option.
|
||||
|
||||
This is a coroutine, you must await it with a 'yield' expression!
|
||||
This is a coroutine, you must await it with a 'await' expression!
|
||||
"""
|
||||
if conf is None:
|
||||
return
|
||||
|
@ -36,7 +36,7 @@ async def gpio_pin_expression(conf):
|
|||
async def register_component(var, config):
|
||||
"""Register the given obj as a component.
|
||||
|
||||
This is a coroutine, you must await it with a 'yield' expression!
|
||||
This is a coroutine, you must await it with a 'await' expression!
|
||||
|
||||
:param var: The variable representing the component.
|
||||
:param config: The configuration for the component.
|
||||
|
|
Loading…
Reference in a new issue