mirror of
https://github.com/esphome/esphome.git
synced 2026-08-22 22:26:21 +00:00
[sprinkler] Inline the trivial Sprinkler accessors
This commit is contained in:
@@ -211,8 +211,6 @@ uint32_t SprinklerValveOperator::time_remaining() {
|
|||||||
return 0; // run completed
|
return 0; // run completed
|
||||||
}
|
}
|
||||||
|
|
||||||
SprinklerState SprinklerValveOperator::state() { return this->state_; }
|
|
||||||
|
|
||||||
switch_::Switch *SprinklerValveOperator::pump_switch() {
|
switch_::Switch *SprinklerValveOperator::pump_switch() {
|
||||||
if ((this->controller_ == nullptr) || (this->valve_ == nullptr)) {
|
if ((this->controller_ == nullptr) || (this->valve_ == nullptr)) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@@ -288,11 +286,8 @@ SprinklerValveRunRequest::SprinklerValveRunRequest(size_t valve_number, uint32_t
|
|||||||
SprinklerValveOperator *valve_op)
|
SprinklerValveOperator *valve_op)
|
||||||
: valve_number_(valve_number), run_duration_(run_duration), valve_op_(valve_op) {}
|
: valve_number_(valve_number), run_duration_(run_duration), valve_op_(valve_op) {}
|
||||||
|
|
||||||
bool SprinklerValveRunRequest::has_request() { return this->has_valve_; }
|
|
||||||
bool SprinklerValveRunRequest::has_valve_operator() { return !(this->valve_op_ == nullptr); }
|
bool SprinklerValveRunRequest::has_valve_operator() { return !(this->valve_op_ == nullptr); }
|
||||||
|
|
||||||
void SprinklerValveRunRequest::set_request_from(SprinklerValveRunRequestOrigin origin) { this->origin_ = origin; }
|
|
||||||
|
|
||||||
void SprinklerValveRunRequest::set_run_duration(uint32_t run_duration) { this->run_duration_ = run_duration; }
|
void SprinklerValveRunRequest::set_run_duration(uint32_t run_duration) { this->run_duration_ = run_duration; }
|
||||||
|
|
||||||
void SprinklerValveRunRequest::set_valve(size_t valve_number) {
|
void SprinklerValveRunRequest::set_valve(size_t valve_number) {
|
||||||
@@ -317,8 +312,6 @@ void SprinklerValveRunRequest::reset() {
|
|||||||
|
|
||||||
uint32_t SprinklerValveRunRequest::run_duration() { return this->run_duration_; }
|
uint32_t SprinklerValveRunRequest::run_duration() { return this->run_duration_; }
|
||||||
|
|
||||||
size_t SprinklerValveRunRequest::valve() { return this->valve_number_; }
|
|
||||||
|
|
||||||
optional<size_t> SprinklerValveRunRequest::valve_as_opt() {
|
optional<size_t> SprinklerValveRunRequest::valve_as_opt() {
|
||||||
if (this->has_valve_) {
|
if (this->has_valve_) {
|
||||||
return this->valve_number_;
|
return this->valve_number_;
|
||||||
@@ -328,8 +321,6 @@ optional<size_t> SprinklerValveRunRequest::valve_as_opt() {
|
|||||||
|
|
||||||
SprinklerValveOperator *SprinklerValveRunRequest::valve_operator() { return this->valve_op_; }
|
SprinklerValveOperator *SprinklerValveRunRequest::valve_operator() { return this->valve_op_; }
|
||||||
|
|
||||||
SprinklerValveRunRequestOrigin SprinklerValveRunRequest::request_is_from() { return this->origin_; }
|
|
||||||
|
|
||||||
Sprinkler::Sprinkler() : Sprinkler("") {}
|
Sprinkler::Sprinkler() : Sprinkler("") {}
|
||||||
Sprinkler::Sprinkler(const char *name) : name_(name) {
|
Sprinkler::Sprinkler(const char *name) : name_(name) {
|
||||||
// The `name` is stored for dump_config logging
|
// The `name` is stored for dump_config logging
|
||||||
@@ -414,18 +405,6 @@ void Sprinkler::set_controller_main_switch(SprinklerControllerSwitch *controller
|
|||||||
this->sprinkler_turn_on_automation_->add_actions({sprinkler_resumeorstart_action_.get()});
|
this->sprinkler_turn_on_automation_->add_actions({sprinkler_resumeorstart_action_.get()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprinkler::set_controller_auto_adv_switch(SprinklerControllerSwitch *auto_adv_switch) {
|
|
||||||
this->auto_adv_sw_ = auto_adv_switch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::set_controller_queue_enable_switch(SprinklerControllerSwitch *queue_enable_switch) {
|
|
||||||
this->queue_enable_sw_ = queue_enable_switch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::set_controller_reverse_switch(SprinklerControllerSwitch *reverse_switch) {
|
|
||||||
this->reverse_sw_ = reverse_switch;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::set_controller_standby_switch(SprinklerControllerSwitch *standby_switch) {
|
void Sprinkler::set_controller_standby_switch(SprinklerControllerSwitch *standby_switch) {
|
||||||
this->standby_sw_ = standby_switch;
|
this->standby_sw_ = standby_switch;
|
||||||
|
|
||||||
@@ -434,14 +413,6 @@ void Sprinkler::set_controller_standby_switch(SprinklerControllerSwitch *standby
|
|||||||
this->sprinkler_standby_turn_on_automation_->add_actions({sprinkler_standby_shutdown_action_.get()});
|
this->sprinkler_standby_turn_on_automation_->add_actions({sprinkler_standby_shutdown_action_.get()});
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprinkler::set_controller_multiplier_number(SprinklerControllerNumber *multiplier_number) {
|
|
||||||
this->multiplier_number_ = multiplier_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::set_controller_repeat_number(SprinklerControllerNumber *repeat_number) {
|
|
||||||
this->repeat_number_ = repeat_number;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::configure_valve_switch(size_t valve_number, switch_::Switch *valve_switch, uint32_t run_duration) {
|
void Sprinkler::configure_valve_switch(size_t valve_number, switch_::Switch *valve_switch, uint32_t run_duration) {
|
||||||
if (this->is_a_valid_valve(valve_number)) {
|
if (this->is_a_valid_valve(valve_number)) {
|
||||||
this->valve_[valve_number].valve_switch = valve_switch;
|
this->valve_[valve_number].valve_switch = valve_switch;
|
||||||
@@ -498,10 +469,6 @@ void Sprinkler::set_multiplier(const optional<float> multiplier) {
|
|||||||
call.perform();
|
call.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprinkler::set_next_prev_ignore_disabled_valves(bool ignore_disabled) {
|
|
||||||
this->next_prev_ignore_disabled_ = ignore_disabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::set_pump_start_delay(uint32_t start_delay) {
|
void Sprinkler::set_pump_start_delay(uint32_t start_delay) {
|
||||||
this->start_delay_is_valve_delay_ = false;
|
this->start_delay_is_valve_delay_ = false;
|
||||||
this->start_delay_ = start_delay;
|
this->start_delay_ = start_delay;
|
||||||
@@ -522,10 +489,6 @@ void Sprinkler::set_valve_stop_delay(uint32_t stop_delay) {
|
|||||||
this->stop_delay_ = stop_delay;
|
this->stop_delay_ = stop_delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprinkler::set_pump_switch_off_during_valve_open_delay(bool pump_switch_off_during_valve_open_delay) {
|
|
||||||
this->pump_switch_off_during_valve_open_delay_ = pump_switch_off_during_valve_open_delay;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Sprinkler::set_valve_open_delay(const uint32_t valve_open_delay) {
|
void Sprinkler::set_valve_open_delay(const uint32_t valve_open_delay) {
|
||||||
if (valve_open_delay > 0) {
|
if (valve_open_delay > 0) {
|
||||||
this->valve_overlap_ = false;
|
this->valve_overlap_ = false;
|
||||||
@@ -945,8 +908,6 @@ optional<size_t> Sprinkler::active_valve() {
|
|||||||
return this->active_req_.valve_as_opt();
|
return this->active_req_.valve_as_opt();
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<size_t> Sprinkler::paused_valve() { return this->paused_valve_; }
|
|
||||||
|
|
||||||
optional<size_t> Sprinkler::queued_valve() {
|
optional<size_t> Sprinkler::queued_valve() {
|
||||||
if (!this->queued_valves_.empty()) {
|
if (!this->queued_valves_.empty()) {
|
||||||
return this->queued_valves_.back().valve_number;
|
return this->queued_valves_.back().valve_number;
|
||||||
@@ -954,10 +915,6 @@ optional<size_t> Sprinkler::queued_valve() {
|
|||||||
return nullopt;
|
return nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<size_t> Sprinkler::manual_valve() { return this->manual_valve_; }
|
|
||||||
|
|
||||||
size_t Sprinkler::number_of_valves() { return this->valve_.size(); }
|
|
||||||
|
|
||||||
bool Sprinkler::is_a_valid_valve(const size_t valve_number) { return (valve_number < this->number_of_valves()); }
|
bool Sprinkler::is_a_valid_valve(const size_t valve_number) { return (valve_number < this->number_of_valves()); }
|
||||||
|
|
||||||
bool Sprinkler::pump_in_use(switch_::Switch *pump_switch) {
|
bool Sprinkler::pump_in_use(switch_::Switch *pump_switch) {
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ class SprinklerValveOperator {
|
|||||||
void stop();
|
void stop();
|
||||||
uint32_t run_duration(); // returns the desired run duration in seconds
|
uint32_t run_duration(); // returns the desired run duration in seconds
|
||||||
uint32_t time_remaining(); // returns seconds remaining (does not include stop_delay_)
|
uint32_t time_remaining(); // returns seconds remaining (does not include stop_delay_)
|
||||||
SprinklerState state(); // returns the valve's state/status
|
SprinklerState state() { return this->state_; }
|
||||||
switch_::Switch *pump_switch(); // returns this SprinklerValveOperator's pump switch
|
switch_::Switch *pump_switch(); // returns this SprinklerValveOperator's pump switch
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -152,18 +152,18 @@ class SprinklerValveRunRequest {
|
|||||||
public:
|
public:
|
||||||
SprinklerValveRunRequest();
|
SprinklerValveRunRequest();
|
||||||
SprinklerValveRunRequest(size_t valve_number, uint32_t run_duration, SprinklerValveOperator *valve_op);
|
SprinklerValveRunRequest(size_t valve_number, uint32_t run_duration, SprinklerValveOperator *valve_op);
|
||||||
bool has_request();
|
bool has_request() { return this->has_valve_; }
|
||||||
bool has_valve_operator();
|
bool has_valve_operator();
|
||||||
void set_request_from(SprinklerValveRunRequestOrigin origin);
|
void set_request_from(SprinklerValveRunRequestOrigin origin) { this->origin_ = origin; }
|
||||||
void set_run_duration(uint32_t run_duration);
|
void set_run_duration(uint32_t run_duration);
|
||||||
void set_valve(size_t valve_number);
|
void set_valve(size_t valve_number);
|
||||||
void set_valve_operator(SprinklerValveOperator *valve_op);
|
void set_valve_operator(SprinklerValveOperator *valve_op);
|
||||||
void reset();
|
void reset();
|
||||||
uint32_t run_duration();
|
uint32_t run_duration();
|
||||||
size_t valve();
|
size_t valve() { return this->valve_number_; }
|
||||||
optional<size_t> valve_as_opt();
|
optional<size_t> valve_as_opt();
|
||||||
SprinklerValveOperator *valve_operator();
|
SprinklerValveOperator *valve_operator();
|
||||||
SprinklerValveRunRequestOrigin request_is_from();
|
SprinklerValveRunRequestOrigin request_is_from() { return this->origin_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool has_valve_{false};
|
bool has_valve_{false};
|
||||||
@@ -189,14 +189,20 @@ class Sprinkler final : public Component {
|
|||||||
|
|
||||||
/// configure important controller switches
|
/// configure important controller switches
|
||||||
void set_controller_main_switch(SprinklerControllerSwitch *controller_switch);
|
void set_controller_main_switch(SprinklerControllerSwitch *controller_switch);
|
||||||
void set_controller_auto_adv_switch(SprinklerControllerSwitch *auto_adv_switch);
|
void set_controller_auto_adv_switch(SprinklerControllerSwitch *auto_adv_switch) {
|
||||||
void set_controller_queue_enable_switch(SprinklerControllerSwitch *queue_enable_switch);
|
this->auto_adv_sw_ = auto_adv_switch;
|
||||||
void set_controller_reverse_switch(SprinklerControllerSwitch *reverse_switch);
|
}
|
||||||
|
void set_controller_queue_enable_switch(SprinklerControllerSwitch *queue_enable_switch) {
|
||||||
|
this->queue_enable_sw_ = queue_enable_switch;
|
||||||
|
}
|
||||||
|
void set_controller_reverse_switch(SprinklerControllerSwitch *reverse_switch) { this->reverse_sw_ = reverse_switch; }
|
||||||
void set_controller_standby_switch(SprinklerControllerSwitch *standby_switch);
|
void set_controller_standby_switch(SprinklerControllerSwitch *standby_switch);
|
||||||
|
|
||||||
/// configure important controller number components
|
/// configure important controller number components
|
||||||
void set_controller_multiplier_number(SprinklerControllerNumber *multiplier_number);
|
void set_controller_multiplier_number(SprinklerControllerNumber *multiplier_number) {
|
||||||
void set_controller_repeat_number(SprinklerControllerNumber *repeat_number);
|
this->multiplier_number_ = multiplier_number;
|
||||||
|
}
|
||||||
|
void set_controller_repeat_number(SprinklerControllerNumber *repeat_number) { this->repeat_number_ = repeat_number; }
|
||||||
|
|
||||||
/// configure a valve's switch object and run duration. run_duration is time in seconds.
|
/// configure a valve's switch object and run duration. run_duration is time in seconds.
|
||||||
void configure_valve_switch(size_t valve_number, switch_::Switch *valve_switch, uint32_t run_duration);
|
void configure_valve_switch(size_t valve_number, switch_::Switch *valve_switch, uint32_t run_duration);
|
||||||
@@ -214,7 +220,9 @@ class Sprinkler final : public Component {
|
|||||||
void set_multiplier(optional<float> multiplier);
|
void set_multiplier(optional<float> multiplier);
|
||||||
|
|
||||||
/// enable/disable skipping of disabled valves by the next and previous actions
|
/// enable/disable skipping of disabled valves by the next and previous actions
|
||||||
void set_next_prev_ignore_disabled_valves(bool ignore_disabled);
|
void set_next_prev_ignore_disabled_valves(bool ignore_disabled) {
|
||||||
|
this->next_prev_ignore_disabled_ = ignore_disabled;
|
||||||
|
}
|
||||||
|
|
||||||
/// set how long the pump should start after the valve (when the pump is starting)
|
/// set how long the pump should start after the valve (when the pump is starting)
|
||||||
void set_pump_start_delay(uint32_t start_delay);
|
void set_pump_start_delay(uint32_t start_delay);
|
||||||
@@ -230,7 +238,9 @@ class Sprinkler final : public Component {
|
|||||||
|
|
||||||
/// if pump_switch_off_during_valve_open_delay is true, the controller will switch off the pump during the
|
/// if pump_switch_off_during_valve_open_delay is true, the controller will switch off the pump during the
|
||||||
/// valve_open_delay interval
|
/// valve_open_delay interval
|
||||||
void set_pump_switch_off_during_valve_open_delay(bool pump_switch_off_during_valve_open_delay);
|
void set_pump_switch_off_during_valve_open_delay(bool pump_switch_off_during_valve_open_delay) {
|
||||||
|
this->pump_switch_off_during_valve_open_delay_ = pump_switch_off_during_valve_open_delay;
|
||||||
|
}
|
||||||
|
|
||||||
/// set how long the controller should wait to open/switch on the valve after it becomes active
|
/// set how long the controller should wait to open/switch on the valve after it becomes active
|
||||||
void set_valve_open_delay(uint32_t valve_open_delay);
|
void set_valve_open_delay(uint32_t valve_open_delay);
|
||||||
@@ -335,17 +345,17 @@ class Sprinkler final : public Component {
|
|||||||
optional<size_t> active_valve();
|
optional<size_t> active_valve();
|
||||||
|
|
||||||
/// returns the number of the valve that is paused, if any. check with 'has_value()'
|
/// returns the number of the valve that is paused, if any. check with 'has_value()'
|
||||||
optional<size_t> paused_valve();
|
optional<size_t> paused_valve() { return this->paused_valve_; }
|
||||||
|
|
||||||
/// returns the number of the next valve in the queue, if any. check with 'has_value()'
|
/// returns the number of the next valve in the queue, if any. check with 'has_value()'
|
||||||
optional<size_t> queued_valve();
|
optional<size_t> queued_valve();
|
||||||
|
|
||||||
/// returns the number of the valve that is manually selected, if any. check with 'has_value()'
|
/// returns the number of the valve that is manually selected, if any. check with 'has_value()'
|
||||||
/// this is set by next_valve() and previous_valve() when manual_selection_delay_ > 0
|
/// this is set by next_valve() and previous_valve() when manual_selection_delay_ > 0
|
||||||
optional<size_t> manual_valve();
|
optional<size_t> manual_valve() { return this->manual_valve_; }
|
||||||
|
|
||||||
/// returns the number of valves the controller is configured with
|
/// returns the number of valves the controller is configured with
|
||||||
size_t number_of_valves();
|
size_t number_of_valves() { return this->valve_.size(); }
|
||||||
|
|
||||||
/// returns true if valve number is valid
|
/// returns true if valve number is valid
|
||||||
bool is_a_valid_valve(size_t valve_number);
|
bool is_a_valid_valve(size_t valve_number);
|
||||||
|
|||||||
Reference in New Issue
Block a user