[cm1106] Use register_apply_action for cm1106.calibrate_zero (#19678)

This commit is contained in:
J. Nick Koston
2026-09-25 19:56:49 +00:00
committed by GitHub
parent 27ea1a90e3
commit d96d0b80f7
4 changed files with 15 additions and 18 deletions
-11
View File
@@ -1,7 +1,6 @@
#pragma once
#include "esphome/core/component.h"
#include "esphome/core/automation.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/uart/uart.h"
@@ -23,14 +22,4 @@ class CM1106Component final : public PollingComponent, public uart::UARTDevice {
bool cm1106_write_command_(const uint8_t *command, size_t command_len, uint8_t *response, size_t response_len);
};
template<typename... Ts> class CM1106CalibrateZeroAction final : public Action<Ts...> {
public:
CM1106CalibrateZeroAction(CM1106Component *cm1106) : cm1106_(cm1106) {}
void play(const Ts &...x) override { this->cm1106_->calibrate_zero(400); }
protected:
CM1106Component *cm1106_;
};
} // namespace esphome::cm1106
+2 -7
View File
@@ -22,10 +22,6 @@ cm1106_ns = cg.esphome_ns.namespace("cm1106")
CM1106Component = cm1106_ns.class_(
"CM1106Component", cg.PollingComponent, uart.UARTDevice
)
CM1106CalibrateZeroAction = cm1106_ns.class_(
"CM1106CalibrateZeroAction",
automation.Action,
)
CONFIG_SCHEMA = (
cv.Schema(
@@ -70,9 +66,8 @@ CALIBRATION_ACTION_SCHEMA = maybe_simple_id(
)
automation.register_simple_action(
automation.register_apply_action(
"cm1106.calibrate_zero",
CM1106CalibrateZeroAction,
CALIBRATION_ACTION_SCHEMA,
synchronous=True,
automation.ApplyCall("calibrate_zero(400)"),
)
@@ -0,0 +1,5 @@
button:
- platform: template
name: CM1106 Calibrate Zero
on_press:
- cm1106.calibrate_zero:
@@ -0,0 +1,8 @@
substitutions:
tx_pin: GPIO0
rx_pin: GPIO2
packages:
uart: !include ../../test_build_components/common/uart/esp8266-ard.yaml
cm1106: !include common.yaml
actions: !include common-actions.yaml