mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Housecleaning: Use walrus operator in select (#6557)
This commit is contained in:
parent
3f015562d7
commit
8eff3435e7
1 changed files with 11 additions and 11 deletions
|
@ -95,8 +95,8 @@ async def setup_select_core_(var, config, *, options: list[str]):
|
|||
trigger, [(cg.std_string, "x"), (cg.size_t, "i")], conf
|
||||
)
|
||||
|
||||
if CONF_MQTT_ID in config:
|
||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
||||
if (mqtt_id := config.get(CONF_MQTT_ID)) is not None:
|
||||
mqtt_ = cg.new_Pvariable(mqtt_id, var)
|
||||
await mqtt.register_mqtt_component(mqtt_, config)
|
||||
|
||||
|
||||
|
@ -223,14 +223,14 @@ async def select_set_index_to_code(config, action_id, template_arg, args):
|
|||
async def select_operation_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_OPERATION in config:
|
||||
op_ = await cg.templatable(config[CONF_OPERATION], args, SelectOperation)
|
||||
if (operation := config.get(CONF_OPERATION)) is not None:
|
||||
op_ = await cg.templatable(operation, args, SelectOperation)
|
||||
cg.add(var.set_operation(op_))
|
||||
if CONF_CYCLE in config:
|
||||
cycle_ = await cg.templatable(config[CONF_CYCLE], args, bool)
|
||||
cg.add(var.set_cycle(cycle_))
|
||||
if CONF_MODE in config:
|
||||
cg.add(var.set_operation(SELECT_OPERATION_OPTIONS[config[CONF_MODE]]))
|
||||
if CONF_CYCLE in config:
|
||||
cg.add(var.set_cycle(config[CONF_CYCLE]))
|
||||
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||
template_ = await cg.templatable(cycle, args, bool)
|
||||
cg.add(var.set_cycle(template_))
|
||||
if (mode := config.get(CONF_MODE)) is not None:
|
||||
cg.add(var.set_operation(SELECT_OPERATION_OPTIONS[mode]))
|
||||
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||
cg.add(var.set_cycle(cycle))
|
||||
return var
|
||||
|
|
Loading…
Reference in a new issue