mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-28 08:48:27 +02: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:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user