mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 15:04:54 +01:00
simplify to_code
This commit is contained in:
parent
f448db79d5
commit
84d4372c36
1 changed files with 7 additions and 6 deletions
|
@ -28,11 +28,12 @@ CONFIG_SCHEMA = cv.Schema(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
async def new_number(config, id, setter, min_value, max_value, step):
|
||||||
|
if c := config.get(id):
|
||||||
|
n = await number.new_number(c, min_value=min_value, max_value=max_value, step=step)
|
||||||
|
await cg.register_parented(n, config[CONF_KT0803_ID])
|
||||||
|
cg.add(setter(n))
|
||||||
|
|
||||||
async def to_code(config):
|
async def to_code(config):
|
||||||
kt0803_component = await cg.get_variable(config[CONF_KT0803_ID])
|
kt0803_component = await cg.get_variable(config[CONF_KT0803_ID])
|
||||||
if frequency_config := config.get(CONF_FREQUENCY):
|
await new_number(config, CONF_FREQUENCY, kt0803_component.set_frequency_number, 70, 108, 0.05)
|
||||||
n = await number.new_number(
|
|
||||||
frequency_config, min_value=70, max_value=108, step=0.05
|
|
||||||
)
|
|
||||||
await cg.register_parented(n, config[CONF_KT0803_ID])
|
|
||||||
cg.add(kt0803_component.set_frequency_number(n))
|
|
Loading…
Reference in a new issue