mirror of
https://github.com/esphome/esphome.git
synced 2026-09-28 15:30:21 +00:00
[sps30] Use register_apply_action for the three sps30 actions (#19644)
This commit is contained in:
@@ -1,24 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "sps30.h"
|
||||
|
||||
namespace esphome::sps30 {
|
||||
|
||||
template<typename... Ts> class StartFanAction final : public Action<Ts...>, public Parented<SPS30Component> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->start_fan_cleaning(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class StartMeasurementAction final : public Action<Ts...>, public Parented<SPS30Component> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->start_measurement(); }
|
||||
};
|
||||
|
||||
template<typename... Ts> class StopMeasurementAction final : public Action<Ts...>, public Parented<SPS30Component> {
|
||||
public:
|
||||
void play(const Ts &...x) override { this->parent_->stop_measurement(); }
|
||||
};
|
||||
|
||||
} // namespace esphome::sps30
|
||||
@@ -37,11 +37,6 @@ SPS30Component = sps30_ns.class_(
|
||||
"SPS30Component", cg.PollingComponent, sensirion_common.SensirionI2CDevice
|
||||
)
|
||||
|
||||
# Actions
|
||||
StartFanAction = sps30_ns.class_("StartFanAction", automation.Action)
|
||||
StartMeasurementAction = sps30_ns.class_("StartMeasurementAction", automation.Action)
|
||||
StopMeasurementAction = sps30_ns.class_("StopMeasurementAction", automation.Action)
|
||||
|
||||
CONF_AUTO_CLEANING_INTERVAL = "auto_cleaning_interval"
|
||||
CONF_IDLE_INTERVAL = "idle_interval"
|
||||
|
||||
@@ -180,25 +175,11 @@ SPS30_ACTION_SCHEMA = maybe_simple_id(
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sps30.start_fan_autoclean",
|
||||
StartFanAction,
|
||||
SPS30_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sps30.start_measurement",
|
||||
StartMeasurementAction,
|
||||
SPS30_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
|
||||
|
||||
automation.register_parented_action(
|
||||
"sps30.stop_measurement",
|
||||
StopMeasurementAction,
|
||||
SPS30_ACTION_SCHEMA,
|
||||
synchronous=True,
|
||||
)
|
||||
for _name, _call in (
|
||||
("sps30.start_fan_autoclean", "start_fan_cleaning()"),
|
||||
("sps30.start_measurement", "start_measurement()"),
|
||||
("sps30.stop_measurement", "stop_measurement()"),
|
||||
):
|
||||
automation.register_apply_action(
|
||||
_name, SPS30_ACTION_SCHEMA, automation.ApplyCall(_call)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
button:
|
||||
- platform: template
|
||||
name: SPS30 Actions
|
||||
on_press:
|
||||
- sps30.start_fan_autoclean: workshop_sps30
|
||||
- sps30.stop_measurement: workshop_sps30
|
||||
- sps30.start_measurement: workshop_sps30
|
||||
@@ -1,5 +1,6 @@
|
||||
sensor:
|
||||
- platform: sps30
|
||||
id: workshop_sps30
|
||||
i2c_id: i2c_bus
|
||||
pm_1_0:
|
||||
name: Workshop PM <1µm Weight concentration
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
packages:
|
||||
i2c: !include ../../test_build_components/common/i2c/esp8266-ard.yaml
|
||||
sps30: !include common.yaml
|
||||
actions: !include common-actions.yaml
|
||||
Reference in New Issue
Block a user