Skip to content

Commit

Permalink
Fix templatable extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Ryl669 committed Mar 17, 2024
1 parent 583f64e commit 9693e4d
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 30 deletions.
75 changes: 49 additions & 26 deletions esphome/components/at581x/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,31 +177,54 @@ async def at581x_settings_to_code(config, action_id, template_arg, args):
await cg.register_parented(var, config[CONF_ID])

# Radar configuration
if CONF_HW_FRONTEND_RESET in config:
cg.add(var.set_hw_frontend_reset(1))

if CONF_FREQUENCY in config:
cg.add(var.set_frequency(config[CONF_FREQUENCY]))

if CONF_SENSING_DISTANCE in config:
cg.add(var.set_sensing_distance(config[CONF_SENSING_DISTANCE]))

if CONF_POWERON_SELFCHECK_TIME in config:
cg.add(var.set_poweron_selfcheck_time(config[CONF_POWERON_SELFCHECK_TIME]))

if CONF_PROTECT_TIME in config:
cg.add(var.set_protect_time(config[CONF_PROTECT_TIME]))

if CONF_TRIGGER_BASE in config:
cg.add(var.set_trigger_base(config[CONF_TRIGGER_BASE]))

if CONF_TRIGGER_KEEP in config:
cg.add(var.set_trigger_keep(config[CONF_TRIGGER_KEEP]))

if CONF_STAGE_GAIN in config:
cg.add(var.set_stage_gain(config[CONF_STAGE_GAIN]))

if CONF_POWER_CONSUMPTION in config:
cg.add(var.set_power_consumption(config[CONF_POWER_CONSUMPTION]))
if frontend_reset := config.get(CONF_HW_FRONTEND_RESET):
template_ = await cg.templatable(frontend_reset, args, int)
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)
cg.add(var.set_frequency(template_))

if sens_dist := config.get(CONF_SENSING_DISTANCE):
template_ = await cg.templatable(sens_dist, args, int)
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_)
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_)
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_)
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_)
cg.add(var.set_trigger_keep(template_))

if stage_gain := config.get(CONF_STAGE_GAIN):
template_ = await cg.templatable(stage_gain, args, int)
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)
cg.add(var.set_power_consumption(template_))

return var
5 changes: 1 addition & 4 deletions esphome/components/at581x/at581x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ bool AT581XComponent::i2c_read_reg(uint8_t addr, uint8_t &data) {
}

void AT581XComponent::setup() {
ESP_LOGCONFIG(TAG, "Setting up AT581X..."); //, this->id_.c_str());
ESP_LOGCONFIG(TAG, "Setting up AT581X...");
this->detection_pin_->setup();
if (!i2c_write_config()) {
ESP_LOGCONFIG(TAG, "Setting up AT581X failed..."); //, this->id_.c_str());
}
}
void AT581XComponent::loop() {
// The main operation is to detect the human presence
Expand Down

0 comments on commit 9693e4d

Please sign in to comment.