mirror of
https://github.com/esphome/esphome.git
synced 2026-06-24 11:25:35 +00:00
[at581x] Fix codegen crash when using lambdas for frequency/time/power (#15468)
This commit is contained in:
@@ -173,8 +173,10 @@ async def at581x_settings_to_code(config, action_id, template_arg, args):
|
||||
cg.add(var.set_hw_frontend_reset(template_))
|
||||
|
||||
if freq := config.get(CONF_FREQUENCY):
|
||||
template_ = await cg.templatable(freq, args, float)
|
||||
template_ = int(template_ / 1000000)
|
||||
if cg.is_template(freq):
|
||||
template_ = await cg.templatable(freq, args, cg.int32)
|
||||
else:
|
||||
template_ = int(freq / 1000000)
|
||||
cg.add(var.set_frequency(template_))
|
||||
|
||||
if (sens_dist := config.get(CONF_SENSING_DISTANCE)) is not None:
|
||||
@@ -182,31 +184,19 @@ async def at581x_settings_to_code(config, action_id, template_arg, args):
|
||||
cg.add(var.set_sensing_distance(template_))
|
||||
|
||||
if selfcheck := config.get(CONF_POWERON_SELFCHECK_TIME):
|
||||
template_ = await cg.templatable(selfcheck, args, float)
|
||||
if isinstance(template_, cv.TimePeriod):
|
||||
template_ = template_.total_milliseconds
|
||||
template_ = int(template_)
|
||||
template_ = await cg.templatable(selfcheck, args, cg.int32)
|
||||
cg.add(var.set_poweron_selfcheck_time(template_))
|
||||
|
||||
if protect := config.get(CONF_PROTECT_TIME):
|
||||
template_ = await cg.templatable(protect, args, float)
|
||||
if isinstance(template_, cv.TimePeriod):
|
||||
template_ = template_.total_milliseconds
|
||||
template_ = int(template_)
|
||||
template_ = await cg.templatable(protect, args, cg.int32)
|
||||
cg.add(var.set_protect_time(template_))
|
||||
|
||||
if trig_base := config.get(CONF_TRIGGER_BASE):
|
||||
template_ = await cg.templatable(trig_base, args, float)
|
||||
if isinstance(template_, cv.TimePeriod):
|
||||
template_ = template_.total_milliseconds
|
||||
template_ = int(template_)
|
||||
template_ = await cg.templatable(trig_base, args, cg.int32)
|
||||
cg.add(var.set_trigger_base(template_))
|
||||
|
||||
if trig_keep := config.get(CONF_TRIGGER_KEEP):
|
||||
template_ = await cg.templatable(trig_keep, args, float)
|
||||
if isinstance(template_, cv.TimePeriod):
|
||||
template_ = template_.total_milliseconds
|
||||
template_ = int(template_)
|
||||
template_ = await cg.templatable(trig_keep, args, cg.int32)
|
||||
cg.add(var.set_trigger_keep(template_))
|
||||
|
||||
if (stage_gain := config.get(CONF_STAGE_GAIN)) is not None:
|
||||
@@ -214,8 +204,10 @@ async def at581x_settings_to_code(config, action_id, template_arg, args):
|
||||
cg.add(var.set_stage_gain(template_))
|
||||
|
||||
if power := config.get(CONF_POWER_CONSUMPTION):
|
||||
template_ = await cg.templatable(power, args, float)
|
||||
template_ = int(template_ * 1000000)
|
||||
if cg.is_template(power):
|
||||
template_ = await cg.templatable(power, args, cg.int32)
|
||||
else:
|
||||
template_ = int(power * 1000000)
|
||||
cg.add(var.set_power_consumption(template_))
|
||||
|
||||
return var
|
||||
|
||||
@@ -12,6 +12,11 @@ esphome:
|
||||
trigger_keep: 10s
|
||||
stage_gain: 3
|
||||
power_consumption: 70uA
|
||||
- at581x.settings:
|
||||
id: waveradar
|
||||
frequency: !lambda "return 5800;"
|
||||
poweron_selfcheck_time: !lambda "return 2000;"
|
||||
power_consumption: !lambda "return 70;"
|
||||
- at581x.reset:
|
||||
id: waveradar
|
||||
|
||||
|
||||
Reference in New Issue
Block a user