diff --git a/esphome/components/scd30/automation.h b/esphome/components/scd30/automation.h deleted file mode 100644 index a816ae1f26..0000000000 --- a/esphome/components/scd30/automation.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "esphome/core/component.h" -#include "esphome/core/automation.h" -#include "scd30.h" - -namespace esphome::scd30 { - -template -class ForceRecalibrationWithReference final : public Action, public Parented { - 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 diff --git a/esphome/components/scd30/sensor.py b/esphome/components/scd30/sensor.py index 37789100f7..aadc85ddb7 100644 --- a/esphome/components/scd30/sensor.py +++ b/esphome/components/scd30/sensor.py @@ -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 diff --git a/tests/components/scd30/common-actions.yaml b/tests/components/scd30/common-actions.yaml new file mode 100644 index 0000000000..ed88e566da --- /dev/null +++ b/tests/components/scd30/common-actions.yaml @@ -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; diff --git a/tests/components/scd30/common.yaml b/tests/components/scd30/common.yaml index f21d8944dc..4d15e83c65 100644 --- a/tests/components/scd30/common.yaml +++ b/tests/components/scd30/common.yaml @@ -1,5 +1,6 @@ sensor: - platform: scd30 + id: co2_scd30 i2c_id: i2c_bus co2: name: SCD30 CO2 diff --git a/tests/components/scd30/test-actions.esp8266-ard.yaml b/tests/components/scd30/test-actions.esp8266-ard.yaml new file mode 100644 index 0000000000..eccbb90cc7 --- /dev/null +++ b/tests/components/scd30/test-actions.esp8266-ard.yaml @@ -0,0 +1,4 @@ +packages: + i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml + scd30: !include common.yaml + actions: !include common-actions.yaml