[scd30] Use register_apply_action for scd30.force_recalibration_with_reference (#19652)

This commit is contained in:
J. Nick Koston
2026-09-25 14:32:05 -04:00
committed by GitHub
parent 6a115e6b25
commit 11c8e8c0c0
5 changed files with 15 additions and 43 deletions
-22
View File
@@ -1,22 +0,0 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "scd30.h"
namespace esphome::scd30 {
template<typename... Ts>
class ForceRecalibrationWithReference final : public Action<Ts...>, public Parented<SCD30Component> {
public:
void play(const Ts &...x) override {
if (this->value_.has_value()) {
this->parent_->force_recalibration_with_reference(this->value_.value(x...));
}
}
protected:
TEMPLATABLE_VALUE(uint16_t, value)
};
} // namespace esphome::scd30
+2 -21
View File
@@ -22,8 +22,6 @@ from esphome.const import (
UNIT_PARTS_PER_MILLION,
UNIT_PERCENT,
)
from esphome.core import ID
from esphome.cpp_generator import MockObj, TemplateArgsType
from esphome.types import ConfigType
DEPENDENCIES = ["i2c"]
@@ -34,11 +32,6 @@ SCD30Component = scd30_ns.class_(
"SCD30Component", cg.Component, sensirion_common.SensirionI2CDevice
)
# Actions
ForceRecalibrationWithReference = scd30_ns.class_(
"ForceRecalibrationWithReference", automation.Action
)
CONFIG_SCHEMA = (
cv.Schema(
{
@@ -119,9 +112,8 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_temperature_sensor(sens))
@automation.register_action(
automation.register_apply_action(
"scd30.force_recalibration_with_reference",
ForceRecalibrationWithReference,
cv.maybe_simple_value(
{
cv.GenerateID(): cv.use_id(SCD30Component),
@@ -131,16 +123,5 @@ async def to_code(config: ConfigType) -> None:
},
key=CONF_VALUE,
),
synchronous=True,
automation.ApplyField(CONF_VALUE, "force_recalibration_with_reference", cg.uint16),
)
async def scd30_force_recalibration_with_reference_to_code(
config: ConfigType,
action_id: ID,
template_arg: cg.TemplateArguments,
args: TemplateArgsType,
) -> MockObj:
var = cg.new_Pvariable(action_id, template_arg)
await cg.register_parented(var, config[CONF_ID])
template_ = await cg.templatable(config[CONF_VALUE], args, cg.uint16)
cg.add(var.set_value(template_))
return var
@@ -0,0 +1,8 @@
button:
- platform: template
name: SCD30 Calibrate
on_press:
- scd30.force_recalibration_with_reference: 419
- scd30.force_recalibration_with_reference:
id: co2_scd30
value: !lambda return 420;
+1
View File
@@ -1,5 +1,6 @@
sensor:
- platform: scd30
id: co2_scd30
i2c_id: i2c_bus
co2:
name: SCD30 CO2
@@ -0,0 +1,4 @@
packages:
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
scd30: !include common.yaml
actions: !include common-actions.yaml