mirror of
https://github.com/esphome/esphome.git
synced 2025-02-26 03:24:43 +01:00
Change sleep to idle to match sensor documentation
This commit is contained in:
parent
8af524e2d8
commit
fa2758ad5d
@ -42,7 +42,7 @@ StartMeasurementAction = sps30_ns.class_("StartMeasurementAction", automation.Ac
|
||||
StopMeasurementAction = sps30_ns.class_("StopMeasurementAction", automation.Action)
|
||||
|
||||
CONF_AUTO_CLEANING_INTERVAL = "auto_cleaning_interval"
|
||||
CONF_SLEEP_INTERVAL = "sleep_interval"
|
||||
CONF_IDLE_INTERVAL = "idle_interval"
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
@ -112,7 +112,7 @@ CONFIG_SCHEMA = (
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
),
|
||||
cv.Optional(CONF_AUTO_CLEANING_INTERVAL): cv.update_interval,
|
||||
cv.Optional(CONF_SLEEP_INTERVAL): cv.update_interval,
|
||||
cv.Optional(CONF_IDLE_INTERVAL): cv.update_interval,
|
||||
}
|
||||
)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
@ -168,8 +168,8 @@ async def to_code(config):
|
||||
if CONF_AUTO_CLEANING_INTERVAL in config:
|
||||
cg.add(var.set_auto_cleaning_interval(config[CONF_AUTO_CLEANING_INTERVAL]))
|
||||
|
||||
if CONF_SLEEP_INTERVAL in config:
|
||||
cg.add(var.set_sleep_interval(config[CONF_SLEEP_INTERVAL]))
|
||||
if CONF_IDLE_INTERVAL in config:
|
||||
cg.add(var.set_idle_interval(config[CONF_IDLE_INTERVAL]))
|
||||
|
||||
|
||||
SPS30_ACTION_SCHEMA = maybe_simple_id(
|
||||
|
@ -143,11 +143,11 @@ void SPS30Component::update() {
|
||||
case WAKE:
|
||||
this->start_measurement();
|
||||
return;
|
||||
case SLEEP:
|
||||
// Sleep happens at the end of reading, so go through another read.
|
||||
case IDLE:
|
||||
// Idle happens at the end of reading, so go through another read.
|
||||
case READ:
|
||||
if (this->sleep_interval_.has_value()) {
|
||||
this->next_state_ = SLEEP;
|
||||
if (this->idle_interval_.has_value()) {
|
||||
this->next_state_ = IDLE;
|
||||
}
|
||||
break;
|
||||
case NONE:
|
||||
@ -234,10 +234,10 @@ void SPS30Component::update() {
|
||||
this->status_clear_warning();
|
||||
this->skipped_data_read_cycles_ = 0;
|
||||
|
||||
// Sleep if we got a reading and our next state is to sleep
|
||||
if(this->next_state_ == SLEEP && millis() >= this->next_state_ms_) {
|
||||
// Idle if we got a reading and our next state is to idle
|
||||
if(this->next_state_ == IDLE && millis() >= this->next_state_ms_) {
|
||||
this->stop_measurement();
|
||||
this->next_state_ms_ = millis() + this->sleep_interval_.value();
|
||||
this->next_state_ms_ = millis() + this->idle_interval_.value();
|
||||
this->next_state_ = WAKE;
|
||||
}
|
||||
});
|
||||
|
@ -23,7 +23,7 @@ class SPS30Component : public PollingComponent, public sensirion_common::Sensiri
|
||||
|
||||
void set_pm_size_sensor(sensor::Sensor *pm_size) { pm_size_sensor_ = pm_size; }
|
||||
void set_auto_cleaning_interval(uint32_t auto_cleaning_interval) { fan_interval_ = auto_cleaning_interval; }
|
||||
void set_sleep_interval(uint32_t sleep_interval) { sleep_interval_ = sleep_interval; }
|
||||
void set_idle_interval(uint32_t idle_interval) { idle_interval_ = idle_interval; }
|
||||
void setup() override;
|
||||
void update() override;
|
||||
void dump_config() override;
|
||||
@ -41,7 +41,7 @@ class SPS30Component : public PollingComponent, public sensirion_common::Sensiri
|
||||
uint32_t next_state_ms_ = 0;
|
||||
|
||||
enum NextState {
|
||||
SLEEP,
|
||||
IDLE,
|
||||
WAKE,
|
||||
READ,
|
||||
NONE
|
||||
@ -68,7 +68,7 @@ class SPS30Component : public PollingComponent, public sensirion_common::Sensiri
|
||||
sensor::Sensor *pmc_10_0_sensor_{nullptr};
|
||||
sensor::Sensor *pm_size_sensor_{nullptr};
|
||||
optional<uint32_t> fan_interval_;
|
||||
optional<uint32_t> sleep_interval_;
|
||||
optional<uint32_t> idle_interval_;
|
||||
};
|
||||
|
||||
} // namespace sps30
|
||||
|
Loading…
Reference in New Issue
Block a user