mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +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_))
|
||||
await automation.build_automation(trigger, [(float, "x")], conf)
|
||||
|
||||
if CONF_UNIT_OF_MEASUREMENT in config:
|
||||
cg.add(var.traits.set_unit_of_measurement(config[CONF_UNIT_OF_MEASUREMENT]))
|
||||
if CONF_MQTT_ID in config:
|
||||
mqtt_ = cg.new_Pvariable(config[CONF_MQTT_ID], var)
|
||||
if (unit_of_measurement := config.get(CONF_UNIT_OF_MEASUREMENT)) is not None:
|
||||
cg.add(var.traits.set_unit_of_measurement(unit_of_measurement))
|
||||
if (device_class := config.get(CONF_DEVICE_CLASS)) is not None:
|
||||
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)
|
||||
if CONF_DEVICE_CLASS in config:
|
||||
cg.add(var.traits.set_device_class(config[CONF_DEVICE_CLASS]))
|
||||
|
||||
|
||||
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])
|
||||
var = cg.new_Pvariable(condition_id, template_arg, paren)
|
||||
|
||||
if CONF_ABOVE in config:
|
||||
cg.add(var.set_min(config[CONF_ABOVE]))
|
||||
if CONF_BELOW in config:
|
||||
cg.add(var.set_max(config[CONF_BELOW]))
|
||||
if (above := config.get(CONF_ABOVE)) is not None:
|
||||
cg.add(var.set_min(above))
|
||||
if (below := config.get(CONF_BELOW)) is not None:
|
||||
cg.add(var.set_max(below))
|
||||
|
||||
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):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
if CONF_OPERATION in config:
|
||||
to_ = await cg.templatable(config[CONF_OPERATION], args, NumberOperation)
|
||||
if (operation := config.get(CONF_OPERATION)) is not None:
|
||||
to_ = await cg.templatable(operation, args, NumberOperation)
|
||||
cg.add(var.set_operation(to_))
|
||||
if CONF_CYCLE in config:
|
||||
cycle_ = await cg.templatable(config[CONF_CYCLE], args, bool)
|
||||
cg.add(var.set_cycle(cycle_))
|
||||
if CONF_MODE in config:
|
||||
cg.add(var.set_operation(NUMBER_OPERATION_OPTIONS[config[CONF_MODE]]))
|
||||
if CONF_CYCLE in config:
|
||||
cg.add(var.set_cycle(config[CONF_CYCLE]))
|
||||
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||
template_ = await cg.templatable(cycle, args, bool)
|
||||
cg.add(var.set_cycle(template_))
|
||||
if (mode := config.get(CONF_MODE)) is not None:
|
||||
cg.add(var.set_operation(NUMBER_OPERATION_OPTIONS[mode]))
|
||||
if (cycle := config.get(CONF_CYCLE)) is not None:
|
||||
cg.add(var.set_cycle(cycle))
|
||||
return var
|
||||
|
|
Loading…
Reference in a new issue