From f60b2b754dfc066d3b96c6c35f6ff2869eafa869 Mon Sep 17 00:00:00 2001 From: Keith Burzinski Date: Sun, 30 Apr 2023 14:52:05 -0500 Subject: [PATCH] Fix sprinkler switch restore_mode (#4756) --- esphome/components/sprinkler/__init__.py | 20 +++++++++++++++----- esphome/components/sprinkler/sprinkler.cpp | 15 +++++++++++++++ esphome/components/sprinkler/sprinkler.h | 7 ++++++- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/esphome/components/sprinkler/__init__.py b/esphome/components/sprinkler/__init__.py index d49b1ba381..6aa76dcd2f 100644 --- a/esphome/components/sprinkler/__init__.py +++ b/esphome/components/sprinkler/__init__.py @@ -286,7 +286,9 @@ SPRINKLER_VALVE_SCHEMA = cv.Schema( { cv.Optional(CONF_ENABLE_SWITCH): cv.maybe_simple_value( switch.switch_schema( - SprinklerControllerSwitch, entity_category=ENTITY_CATEGORY_CONFIG + SprinklerControllerSwitch, + entity_category=ENTITY_CATEGORY_CONFIG, + default_restore_mode="RESTORE_DEFAULT_OFF", ), key=CONF_NAME, ), @@ -333,7 +335,9 @@ SPRINKLER_CONTROLLER_SCHEMA = cv.Schema( cv.Optional(CONF_NAME): cv.string, cv.Optional(CONF_AUTO_ADVANCE_SWITCH): cv.maybe_simple_value( switch.switch_schema( - SprinklerControllerSwitch, entity_category=ENTITY_CATEGORY_CONFIG + SprinklerControllerSwitch, + entity_category=ENTITY_CATEGORY_CONFIG, + default_restore_mode="RESTORE_DEFAULT_OFF", ), key=CONF_NAME, ), @@ -343,19 +347,25 @@ SPRINKLER_CONTROLLER_SCHEMA = cv.Schema( ), cv.Optional(CONF_QUEUE_ENABLE_SWITCH): cv.maybe_simple_value( switch.switch_schema( - SprinklerControllerSwitch, entity_category=ENTITY_CATEGORY_CONFIG + SprinklerControllerSwitch, + entity_category=ENTITY_CATEGORY_CONFIG, + default_restore_mode="RESTORE_DEFAULT_OFF", ), key=CONF_NAME, ), cv.Optional(CONF_REVERSE_SWITCH): cv.maybe_simple_value( switch.switch_schema( - SprinklerControllerSwitch, entity_category=ENTITY_CATEGORY_CONFIG + SprinklerControllerSwitch, + entity_category=ENTITY_CATEGORY_CONFIG, + default_restore_mode="RESTORE_DEFAULT_OFF", ), key=CONF_NAME, ), cv.Optional(CONF_STANDBY_SWITCH): cv.maybe_simple_value( switch.switch_schema( - SprinklerControllerSwitch, entity_category=ENTITY_CATEGORY_CONFIG + SprinklerControllerSwitch, + entity_category=ENTITY_CATEGORY_CONFIG, + default_restore_mode="RESTORE_DEFAULT_OFF", ), key=CONF_NAME, ), diff --git a/esphome/components/sprinkler/sprinkler.cpp b/esphome/components/sprinkler/sprinkler.cpp index 6169185d60..52a6cd2af4 100644 --- a/esphome/components/sprinkler/sprinkler.cpp +++ b/esphome/components/sprinkler/sprinkler.cpp @@ -1176,6 +1176,21 @@ optional Sprinkler::time_remaining_current_operation() { return nullopt; } +bool Sprinkler::any_controller_is_active() { + if (this->state_ != IDLE) { + return true; + } + + for (auto &controller : this->other_controllers_) { + if (controller != this) { // dummy check + if (controller->controller_state() != IDLE) { + return true; + } + } + } + return false; +} + SprinklerControllerSwitch *Sprinkler::control_switch(size_t valve_number) { if (this->is_a_valid_valve(valve_number)) { return this->valve_[valve_number].controller_switch; diff --git a/esphome/components/sprinkler/sprinkler.h b/esphome/components/sprinkler/sprinkler.h index 7952c4533f..7a8285ae73 100644 --- a/esphome/components/sprinkler/sprinkler.h +++ b/esphome/components/sprinkler/sprinkler.h @@ -406,6 +406,12 @@ class Sprinkler : public Component { /// returns the amount of time remaining in seconds for all valves remaining, including the active valve, if any optional time_remaining_current_operation(); + /// returns true if this or any sprinkler controller this controller knows about is active + bool any_controller_is_active(); + + /// returns the current state of the sprinkler controller + SprinklerState controller_state() { return this->state_; }; + /// returns a pointer to a valve's control switch object SprinklerControllerSwitch *control_switch(size_t valve_number); @@ -503,7 +509,6 @@ class Sprinkler : public Component { /// callback functions for timers void valve_selection_callback_(); void sm_timer_callback_(); - void pump_stop_delay_callback_(); /// Maximum allowed queue size const uint8_t max_queue_size_{100};