18 return LOG_STR(
"OPEN");
20 return LOG_STR(
"CLOSE");
22 return LOG_STR(
"UNKNOWN");
29 return ValveOperationStrings::get_log_str(
static_cast<uint8_t
>(op), ValveOperationStrings::LAST_INDEX);
36 if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"OPEN")) == 0) {
38 }
else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"CLOSE")) == 0) {
40 }
else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"STOP")) == 0) {
42 }
else if (ESPHOME_strcasecmp_P(command, ESPHOME_PSTR(
"TOGGLE")) == 0) {
45 ESP_LOGW(TAG,
"'%s' - Unrecognized command %s", LOG_STR_ARG(this->
parent_->
get_log_name()), command);
74 ESP_LOGV(TAG,
" Command: STOP");
77 if (traits.get_supports_position()) {
78 ESP_LOGV(TAG,
" Position: %.0f%%", *this->
position_ * 100.0f);
83 if (this->
toggle_.has_value()) {
84 ESP_LOGV(TAG,
" Command: TOGGLE");
95 ESP_LOGW(TAG,
"'%s' - This valve device does not support setting position!",
99 ESP_LOGW(TAG,
"'%s' - Position %.2f is out of range [0.0 - 1.0]", LOG_STR_ARG(this->
parent_->
get_log_name()),
104 if (this->
toggle_.has_value()) {
105 if (!traits.get_supports_toggle()) {
106 ESP_LOGW(TAG,
"'%s' - This valve device does not support toggle!", LOG_STR_ARG(this->
parent_->
get_log_name()));
112 ESP_LOGW(TAG,
"Cannot set position when stopping a valve!");
115 if (this->
toggle_.has_value()) {
116 ESP_LOGW(TAG,
"Cannot set toggle when stopping a valve!");
128 ESP_LOGV(TAG,
"'%s' >>", LOG_STR_ARG(this->
get_log_name()));
130 if (traits.get_supports_position()) {
131 ESP_LOGV(TAG,
" Position: %.0f%%", this->
position * 100.0f);
134 ESP_LOGV(TAG,
" State: OPEN");
135 }
else if (this->
position == VALVE_CLOSED) {
136 ESP_LOGV(TAG,
" State: CLOSED");
138 ESP_LOGV(TAG,
" State: UNKNOWN");
144#if defined(USE_VALVE) && defined(USE_CONTROLLER_REGISTRY)
145 ControllerRegistry::notify_valve_update(
this);
150 memset(&restore, 0,
sizeof(restore));
const LogString * get_log_name() const
Get the name for a "%s" log argument (LOG_STR_ARG).
ESPPreferenceObject make_entity_preference(uint32_t version=0)
Create a preference object for storing this entity's state/settings.
ValveCall & set_stop(bool stop)
Set whether this valve call should stop the valve.
ValveCall & set_command_close()
Set the command to close the valve.
ValveCall & set_position(float position)
Set the call to a certain target position.
const optional< bool > & get_toggle() const
ValveCall & set_command_toggle()
Set the command to toggle the valve.
ValveCall & set_command_stop()
Set the command to stop the valve.
const optional< float > & get_position() const
ValveCall & set_command(const char *command)
Set the command as a string, "STOP", "OPEN", "CLOSE", "TOGGLE".
optional< float > position_
ValveCall & set_command_open()
Set the command to open the valve.
void perform()
Perform the valve call.
Base class for all valve devices.
optional< ValveRestoreState > restore_state_()
void publish_state(bool save=true)
Publish the current state of the valve.
LazyCallbackManager< void()> state_callback_
float position
The position of the valve from 0.0 (fully closed) to 1.0 (fully open).
virtual void control(const ValveCall &call)=0
ValveCall make_call()
Construct a new valve call used to control the valve.
ValveOperation current_operation
The current operation of the valve (idle, opening, closing).
virtual ValveTraits get_traits()=0
ESPHOME_LOG_TAG(TAG, "valve")
const LogString * valve_command_to_str(float pos)
PROGMEM_STRING_TABLE(ValveOperationStrings, "IDLE", "OPENING", "CLOSING", "UNKNOWN")
ValveOperation
Enum encoding the current operation of a valve.
const LogString * valve_operation_to_str(ValveOperation op)
Struct used to store the restored state of a valve.
void apply(Valve *valve)
Apply these settings to the valve.
ValveCall to_call(Valve *valve)
Convert this struct to a valve call that can be performed.