mirror of
https://github.com/esphome/esphome.git
synced 2024-11-10 09:17:46 +01:00
Housecleaning: Use walrus operator in fan (#6555)
Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
This commit is contained in:
parent
77ade12ee9
commit
214c237c8d
1 changed files with 28 additions and 34 deletions
|
@ -180,40 +180,34 @@ async def setup_fan_core_(var, config):
|
||||||
|
|
||||||
cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
if CONF_OSCILLATION_STATE_TOPIC in config:
|
if (
|
||||||
|
oscillation_state_topic := config.get(CONF_OSCILLATION_STATE_TOPIC)
|
||||||
|
) is not None:
|
||||||
|
cg.add(mqtt_.set_custom_oscillation_state_topic(oscillation_state_topic))
|
||||||
|
if (
|
||||||
|
oscillation_command_topic := config.get(CONF_OSCILLATION_COMMAND_TOPIC)
|
||||||
|
) is not None:
|
||||||
cg.add(
|
cg.add(
|
||||||
mqtt_.set_custom_oscillation_state_topic(
|
mqtt_.set_custom_oscillation_command_topic(oscillation_command_topic)
|
||||||
config[CONF_OSCILLATION_STATE_TOPIC]
|
|
||||||
)
|
)
|
||||||
)
|
if (
|
||||||
if CONF_OSCILLATION_COMMAND_TOPIC in config:
|
speed_level_state_topic := config.get(CONF_SPEED_LEVEL_STATE_TOPIC)
|
||||||
|
) is not None:
|
||||||
|
cg.add(mqtt_.set_custom_speed_level_state_topic(speed_level_state_topic))
|
||||||
|
if (
|
||||||
|
speed_level_command_topic := config.get(CONF_SPEED_LEVEL_COMMAND_TOPIC)
|
||||||
|
) is not None:
|
||||||
cg.add(
|
cg.add(
|
||||||
mqtt_.set_custom_oscillation_command_topic(
|
mqtt_.set_custom_speed_level_command_topic(speed_level_command_topic)
|
||||||
config[CONF_OSCILLATION_COMMAND_TOPIC]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if CONF_SPEED_LEVEL_STATE_TOPIC in config:
|
|
||||||
cg.add(
|
|
||||||
mqtt_.set_custom_speed_level_state_topic(
|
|
||||||
config[CONF_SPEED_LEVEL_STATE_TOPIC]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if CONF_SPEED_LEVEL_COMMAND_TOPIC in config:
|
|
||||||
cg.add(
|
|
||||||
mqtt_.set_custom_speed_level_command_topic(
|
|
||||||
config[CONF_SPEED_LEVEL_COMMAND_TOPIC]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
if CONF_SPEED_STATE_TOPIC in config:
|
|
||||||
cg.add(mqtt_.set_custom_speed_state_topic(config[CONF_SPEED_STATE_TOPIC]))
|
|
||||||
if CONF_SPEED_COMMAND_TOPIC in config:
|
|
||||||
cg.add(
|
|
||||||
mqtt_.set_custom_speed_command_topic(config[CONF_SPEED_COMMAND_TOPIC])
|
|
||||||
)
|
)
|
||||||
|
if (speed_state_topic := config.get(CONF_SPEED_STATE_TOPIC)) is not None:
|
||||||
|
cg.add(mqtt_.set_custom_speed_state_topic(speed_state_topic))
|
||||||
|
if (speed_command_topic := config.get(CONF_SPEED_COMMAND_TOPIC)) is not None:
|
||||||
|
cg.add(mqtt_.set_custom_speed_command_topic(speed_command_topic))
|
||||||
|
|
||||||
for conf in config.get(CONF_ON_STATE, []):
|
for conf in config.get(CONF_ON_STATE, []):
|
||||||
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
|
||||||
|
@ -288,14 +282,14 @@ async def fan_turn_off_to_code(config, action_id, template_arg, args):
|
||||||
async def fan_turn_on_to_code(config, action_id, template_arg, args):
|
async def fan_turn_on_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_OSCILLATING in config:
|
if (oscillating := config.get(CONF_OSCILLATING)) is not None:
|
||||||
template_ = await cg.templatable(config[CONF_OSCILLATING], args, bool)
|
template_ = await cg.templatable(oscillating, args, bool)
|
||||||
cg.add(var.set_oscillating(template_))
|
cg.add(var.set_oscillating(template_))
|
||||||
if CONF_SPEED in config:
|
if (speed := config.get(CONF_SPEED)) is not None:
|
||||||
template_ = await cg.templatable(config[CONF_SPEED], args, int)
|
template_ = await cg.templatable(speed, args, int)
|
||||||
cg.add(var.set_speed(template_))
|
cg.add(var.set_speed(template_))
|
||||||
if CONF_DIRECTION in config:
|
if (direction := config.get(CONF_DIRECTION)) is not None:
|
||||||
template_ = await cg.templatable(config[CONF_DIRECTION], args, FanDirection)
|
template_ = await cg.templatable(direction, args, FanDirection)
|
||||||
cg.add(var.set_direction(template_))
|
cg.add(var.set_direction(template_))
|
||||||
return var
|
return var
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue