-
Notifications
You must be signed in to change notification settings - Fork 2
/
script_controller_status.yaml
28 lines (25 loc) · 1.01 KB
/
script_controller_status.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# SPDX-License-Identifier: Apache-1.0
# Copyright (c) 2023 Ilia Sotnikov
---
!lambda |-
#include <esphome/components/sprinkler/sprinkler.h>
#define PAUSED_STR "Paused: "
#define PAUSED_STR_LEN sizeof(PAUSED_STR) - 1
auto paused_valve = id(${sprinkler}).paused_valve();
if (paused_valve.has_value()) {
auto paused_valve_name = id(${sprinkler}).valve_name(paused_valve.value());
auto st = str_snprintf(
PAUSED_STR "%s", PAUSED_STR_LEN + strlen(paused_valve_name),
paused_valve_name);
return {st.c_str()};
}
if (id(${sprinkler}).standby())
return {"Standby"};
switch(id(${sprinkler}).controller_state()) {
case esphome::sprinkler::SprinklerState::IDLE: return {"Idle"};
case esphome::sprinkler::SprinklerState::STARTING: return {"Starting"};
case esphome::sprinkler::SprinklerState::ACTIVE: return {"Active"};
case esphome::sprinkler::SprinklerState::STOPPING: return {"Stopping"};
case esphome::sprinkler::SprinklerState::BYPASS: return {"Bypass"};
};
return {"N/A"};