Sprinkler shutdown doesn't reset paused valve information
- Dominant language
- No language data
- Stars
- 313
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
### The problem
When the controller is paused, calling the shutdown action does not reset the paused valve information. To reset the paused value information, the controller has to be resumed and shutdown again.
IMO, this is counter-intuitive as I would expect the shutdown action to clear the controller state. I think of it as a media player, pressing "stop" while a track is paused generally clears the current track position.
The current implementation cause an issue if `paused_valve()` is used to determine the [controller state](https://esphome.io/components/sprinkler.html#how-do-i).
e.g. In this sensor, if the controller is paused, it will never transition to idle unless resumed and shutdown again.
```yaml
text_sensor:
- platform: template
name: Controller State
lambda: |-
if (id(sprinkler_controller).paused_valve().has_value())
return {"Paused"};
else if (id(sprinkler_controller).active_valve().has_value())
return {"Running"};
else
return {"Idle"};
```
**Possible fix**
Update `shutdown()` to clear the paused valve info.
```c++
void Sprinkler::shutdown(bool clear_queue) {
this->cancel_timer_(sprinkler::TIMER_VALVE_SELECTION);
this->active_req_.reset();
this->manual_valve_.reset();
this->next_req_.reset();
this->reset_resume();
...
```
However, since `pause()` calls `shutdown()` to stop the valves.
https://github.com/esphome/esphome/blob/0ef73c6dd6b6a02b51f0effa9f509cb9dc7189d7/esphome/components/sprinkler/sprinkler.cpp#L936-L960
It would need to be updated to stash the active valve information, call shutdown, and then assign the paused valve state.
```c++
// Save active valve state
auto valve = this->active_valve();
auto duration = this->time_remaining_active_valve();
// Shutdown controller
this->shutdown(false);
// Update paused valve information
this->paused_valve_ = valve;
this->resume_duration_ = duration;
ESP_LOGD(TAG, "Paused valve %zu with %" PRIu32 " seconds remaining", this->paused_valve_.value_or(0),
this->resume_duration_.value_or(0));
```
**Workaround**
This can be worked around by defining a lambda that manually calls `reset_resume()` and `shutdown()`.
```yaml
- lambda: |-
id(sprinkler_controller).reset_resume();
id(sprinkler_controller).shutdown();
```
### Which version of ESPHome has the issue?
2024.7.0
### What type of installation are you using?
Docker
### Which version of Home Assistant has the issue?
N/A
### What platform are you using?
ESP8266
### Board
https://devices.esphome.io/devices/ESP-12F-Relay-X8
### Component causing the issue
Sprinkler
### Example YAML snippet
_No response_
### Anything in the logs that might be useful for us?
_No response_
### Additional information
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.