mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 10:00:36 +01:00
Housecleaning: Use walrus operator in select (#6557)
This commit is contained in:
parent
3f015562d7
commit
8eff3435e7
@ -95,8 +95,8 @@ async def setup_select_core_(var, config, *, options: list[str]):
|
|||||||
trigger, [(cg.std_string, "x"), (cg.size_t, "i")], conf
|
trigger, [(cg.std_string, "x"), (cg.size_t, "i")], conf
|
||||||
)
|
)
|
||||||
|
|
||||||
if CONF_MQTT_ID in config:
|
if (mqtt_id := config.get(CONF_MQTT_ID)) is not None:
|
||||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
mqtt_ = cg.new_Pvariable(mqtt_id, var)
|
||||||
await mqtt.register_mqtt_component(mqtt_, config)
|
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):
|
async def select_operation_to_code(config, action_id, template_arg, args):
|
||||||
paren = await cg.get_variable(config[CONF_ID])
|
paren = await cg.get_variable(config[CONF_ID])
|
||||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
if CONF_OPERATION in config:
|
if (operation := config.get(CONF_OPERATION)) is not None:
|
||||||
op_ = await cg.templatable(config[CONF_OPERATION], args, SelectOperation)
|
op_ = await cg.templatable(operation, args, SelectOperation)
|
||||||
cg.add(var.set_operation(op_))
|
cg.add(var.set_operation(op_))
|
||||||
if CONF_CYCLE in config:
|
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||||
cycle_ = await cg.templatable(config[CONF_CYCLE], args, bool)
|
template_ = await cg.templatable(cycle, args, bool)
|
||||||
cg.add(var.set_cycle(cycle_))
|
cg.add(var.set_cycle(template_))
|
||||||
if CONF_MODE in config:
|
if (mode := config.get(CONF_MODE)) is not None:
|
||||||
cg.add(var.set_operation(SELECT_OPERATION_OPTIONS[config[CONF_MODE]]))
|
cg.add(var.set_operation(SELECT_OPERATION_OPTIONS[mode]))
|
||||||
if CONF_CYCLE in config:
|
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||||
cg.add(var.set_cycle(config[CONF_CYCLE]))
|
cg.add(var.set_cycle(cycle))
|
||||||
return var
|
return var
|
||||||
|
Loading…
Reference in New Issue
Block a user