From 84d4372c3689297768204775d89089ef626ec694 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Poczkodi?= Date: Fri, 11 Oct 2024 20:13:58 +0200 Subject: [PATCH] simplify to_code --- esphome/components/kt0803/number/__init__.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/esphome/components/kt0803/number/__init__.py b/esphome/components/kt0803/number/__init__.py index 68b84b0695..78841d31f9 100644 --- a/esphome/components/kt0803/number/__init__.py +++ b/esphome/components/kt0803/number/__init__.py @@ -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): kt0803_component = await cg.get_variable(config[CONF_KT0803_ID]) - if frequency_config := config.get(CONF_FREQUENCY): - 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)) + await new_number(config, CONF_FREQUENCY, kt0803_component.set_frequency_number, 70, 108, 0.05) \ No newline at end of file