Update components "if x in config" (#5181)

This commit is contained in:
Jesse Hills
2023-08-02 16:25:26 +12:00
committed by GitHub
parent ce8091c14e
commit f81c556b63
44 changed files with 325 additions and 413 deletions
+6 -5
View File
@@ -108,12 +108,13 @@ CONFIG_SCHEMA = cv.Schema(
async def setup_conf(config, key, hub):
if key in config:
conf = config[key]
sens = await sensor.new_sensor(conf)
if sensor_config := config.get(key):
sens = await sensor.new_sensor(sensor_config)
cg.add(getattr(hub, f"set_{key}_sensor")(sens))
if CONF_SAMPLE_RATE in conf:
cg.add(getattr(hub, f"set_{key}_sample_rate")(conf[CONF_SAMPLE_RATE]))
if CONF_SAMPLE_RATE in sensor_config:
cg.add(
getattr(hub, f"set_{key}_sample_rate")(sensor_config[CONF_SAMPLE_RATE])
)
async def to_code(config):