1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-25 14:42:21 +01:00

Update some sensor schemas to be Optional (#8803)

This commit is contained in:
Jesse Hills
2025-05-15 14:40:11 +12:00
committed by GitHub
parent 730441c120
commit 1a651ce66d
14 changed files with 96 additions and 87 deletions

View File

@@ -38,7 +38,7 @@ CONFIG_SCHEMA = (
cv.Schema(
{
cv.GenerateID(): cv.declare_id(SenseAirComponent),
cv.Required(CONF_CO2): sensor.sensor_schema(
cv.Optional(CONF_CO2): sensor.sensor_schema(
unit_of_measurement=UNIT_PARTS_PER_MILLION,
icon=ICON_MOLECULE_CO2,
accuracy_decimals=0,
@@ -57,8 +57,8 @@ async def to_code(config):
await cg.register_component(var, config)
await uart.register_uart_device(var, config)
if CONF_CO2 in config:
sens = await sensor.new_sensor(config[CONF_CO2])
if co2 := config.get(CONF_CO2):
sens = await sensor.new_sensor(co2)
cg.add(var.set_co2_sensor(sens))