Skip to content

Commit

Permalink
Housecleaning: Use walrus operator in switch (esphome#6558)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesserockz authored Apr 17, 2024
1 parent 51ed6d6 commit c8cdb30
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions esphome/components/switch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,21 +138,21 @@ def switch_schema(
async def setup_switch_core_(var, config):
await setup_entity(var, config)

if CONF_INVERTED in config:
cg.add(var.set_inverted(config[CONF_INVERTED]))
if (inverted := config.get(CONF_INVERTED)) is not None:
cg.add(var.set_inverted(inverted))
for conf in config.get(CONF_ON_TURN_ON, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], conf)
for conf in config.get(CONF_ON_TURN_OFF, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], var)
await automation.build_automation(trigger, [], 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)

if CONF_DEVICE_CLASS in config:
cg.add(var.set_device_class(config[CONF_DEVICE_CLASS]))
if (device_class := config.get(CONF_DEVICE_CLASS)) is not None:
cg.add(var.set_device_class(device_class))

cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE]))

Expand Down

0 comments on commit c8cdb30

Please sign in to comment.