mirror of
https://github.com/esphome/esphome.git
synced 2026-09-27 23:10:21 +00:00
[scd30] Use register_apply_action for scd30.force_recalibration_with_reference (#19652)
This commit is contained in:
@@ -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
|
||||
@@ -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,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
|
||||
Reference in New Issue
Block a user