diff --git a/esphome/components/lps22/sensor.py b/esphome/components/lps22/sensor.py index afbbfd1c2f..5987667e58 100644 --- a/esphome/components/lps22/sensor.py +++ b/esphome/components/lps22/sensor.py @@ -53,6 +53,6 @@ async def to_code(config): sens = await sensor.new_sensor(config[CONF_TEMPERATURE]) cg.add(var.set_temperature_sensor(sens)) - if CONF_PRESSURE in config: - sens = await sensor.new_sensor(config[CONF_PRESSURE]) + if pressure_config := config.get(CONF_PRESSURE): + sens = await sensor.new_sensor(pressure_config) cg.add(var.set_pressure_sensor(sens))