mirror of
https://github.com/esphome/esphome.git
synced 2024-11-21 22:48:10 +01:00
Housecleaning: Use walrus operator in number (#6561)
This commit is contained in:
parent
8eff3435e7
commit
21e3faad38
1 changed files with 20 additions and 19 deletions
|
@ -239,13 +239,14 @@ async def setup_number_core_(
|
||||||
cg.add(trigger.set_max(template_))
|
cg.add(trigger.set_max(template_))
|
||||||
await automation.build_automation(trigger, [(float, "x")], conf)
|
await automation.build_automation(trigger, [(float, "x")], conf)
|
||||||
|
|
||||||
if CONF_UNIT_OF_MEASUREMENT in config:
|
if (unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)) is not None:
|
||||||
cg.add(var.traits.set_unit_of_measurement(config[CONF_UNIT_OF_MEASUREMENT]))
|
cg.add(var.traits.set_unit_of_measurement(unit_of_measurement))
|
||||||
if CONF_MQTT_ID in config:
|
if (device_class := config.get(CONF_DEVICE_CLASS)) is not None:
|
||||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
cg.add(var.traits.set_device_class(device_class))
|
||||||
|
|
||||||
|
if (mqtt_id := config.get(CONF_MQTT_ID)) is not None:
|
||||||
|
mqtt_ = cg.new_Pvariable(mqtt_id, var)
|
||||||
await mqtt.register_mqtt_component(mqtt_, config)
|
await mqtt.register_mqtt_component(mqtt_, config)
|
||||||
if CONF_DEVICE_CLASS in config:
|
|
||||||
cg.add(var.traits.set_device_class(config[CONF_DEVICE_CLASS]))
|
|
||||||
|
|
||||||
|
|
||||||
async def register_number(
|
async def register_number(
|
||||||
|
@ -284,10 +285,10 @@ async def number_in_range_to_code(config, condition_id, template_arg, args):
|
||||||
paren = await cg.get_variable(config[CONF_ID])
|
paren = await cg.get_variable(config[CONF_ID])
|
||||||
var = cg.new_Pvariable(condition_id, template_arg, paren)
|
var = cg.new_Pvariable(condition_id, template_arg, paren)
|
||||||
|
|
||||||
if CONF_ABOVE in config:
|
if (above := config.get(CONF_ABOVE)) is not None:
|
||||||
cg.add(var.set_min(config[CONF_ABOVE]))
|
cg.add(var.set_min(above))
|
||||||
if CONF_BELOW in config:
|
if (below := config.get(CONF_BELOW)) is not None:
|
||||||
cg.add(var.set_max(config[CONF_BELOW]))
|
cg.add(var.set_max(below))
|
||||||
|
|
||||||
return var
|
return var
|
||||||
|
|
||||||
|
@ -391,14 +392,14 @@ async def number_set_to_code(config, action_id, template_arg, args):
|
||||||
async def number_to_to_code(config, action_id, template_arg, args):
|
async def number_to_to_code(config, action_id, template_arg, args):
|
||||||
paren = await cg.get_variable(config[CONF_ID])
|
paren = await cg.get_variable(config[CONF_ID])
|
||||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||||
if CONF_OPERATION in config:
|
if (operation := config.get(CONF_OPERATION)) is not None:
|
||||||
to_ = await cg.templatable(config[CONF_OPERATION], args, NumberOperation)
|
to_ = await cg.templatable(operation, args, NumberOperation)
|
||||||
cg.add(var.set_operation(to_))
|
cg.add(var.set_operation(to_))
|
||||||
if CONF_CYCLE in config:
|
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||||
cycle_ = await cg.templatable(config[CONF_CYCLE], args, bool)
|
template_ = await cg.templatable(cycle, args, bool)
|
||||||
cg.add(var.set_cycle(cycle_))
|
cg.add(var.set_cycle(template_))
|
||||||
if CONF_MODE in config:
|
if (mode := config.get(CONF_MODE)) is not None:
|
||||||
cg.add(var.set_operation(NUMBER_OPERATION_OPTIONS[config[CONF_MODE]]))
|
cg.add(var.set_operation(NUMBER_OPERATION_OPTIONS[mode]))
|
||||||
if CONF_CYCLE in config:
|
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||||
cg.add(var.set_cycle(config[CONF_CYCLE]))
|
cg.add(var.set_cycle(cycle))
|
||||||
return var
|
return var
|
||||||
|
|
Loading…
Reference in a new issue