mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Housecleaning: Use walrus operator in light (#6556)
This commit is contained in:
parent
2fc2d5839f
commit
3f015562d7
1 changed files with 16 additions and 18 deletions
|
@ -137,18 +137,16 @@ async def setup_light_core_(light_var, output_var, config):
|
|||
|
||||
cg.add(light_var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
||||
|
||||
if CONF_DEFAULT_TRANSITION_LENGTH in config:
|
||||
cg.add(
|
||||
light_var.set_default_transition_length(
|
||||
config[CONF_DEFAULT_TRANSITION_LENGTH]
|
||||
)
|
||||
)
|
||||
if CONF_FLASH_TRANSITION_LENGTH in config:
|
||||
cg.add(
|
||||
light_var.set_flash_transition_length(config[CONF_FLASH_TRANSITION_LENGTH])
|
||||
)
|
||||
if CONF_GAMMA_CORRECT in config:
|
||||
cg.add(light_var.set_gamma_correct(config[CONF_GAMMA_CORRECT]))
|
||||
if (
|
||||
default_transition_length := config.get(CONF_DEFAULT_TRANSITION_LENGTH)
|
||||
) is not None:
|
||||
cg.add(light_var.set_default_transition_length(default_transition_length))
|
||||
if (
|
||||
flash_transition_length := config.get(CONF_FLASH_TRANSITION_LENGTH)
|
||||
) is not None:
|
||||
cg.add(light_var.set_flash_transition_length(flash_transition_length))
|
||||
if (gamma_correct := config.get(CONF_GAMMA_CORRECT)) is not None:
|
||||
cg.add(light_var.set_gamma_correct(gamma_correct))
|
||||
effects = await cg.build_registry_list(
|
||||
EFFECTS_REGISTRY, config.get(CONF_EFFECTS, [])
|
||||
)
|
||||
|
@ -164,15 +162,15 @@ async def setup_light_core_(light_var, output_var, config):
|
|||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], light_var)
|
||||
await auto.build_automation(trigger, [], conf)
|
||||
|
||||
if CONF_COLOR_CORRECT in config:
|
||||
cg.add(output_var.set_correction(*config[CONF_COLOR_CORRECT]))
|
||||
if (color_correct := config.get(CONF_COLOR_CORRECT)) is not None:
|
||||
cg.add(output_var.set_correction(*color_correct))
|
||||
|
||||
if CONF_POWER_SUPPLY in config:
|
||||
var_ = await cg.get_variable(config[CONF_POWER_SUPPLY])
|
||||
if (power_supply_id := config.get(CONF_POWER_SUPPLY)) is not None:
|
||||
var_ = await cg.get_variable(power_supply_id)
|
||||
cg.add(output_var.set_power_supply(var_))
|
||||
|
||||
if CONF_MQTT_ID in config:
|
||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], light_var)
|
||||
if (mqtt_id := config.get(CONF_MQTT_ID)) is not None:
|
||||
mqtt_ = cg.new_Pvariable(mqtt_id, light_var)
|
||||
await mqtt.register_mqtt_component(mqtt_, config)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue