12 static const char *
const TAG =
"mqtt.valve";
22 call.set_command(payload.c_str());
25 if (traits.get_supports_position()) {
26 this->
subscribe(this->get_position_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
27 auto value = parse_number<float>(payload);
28 if (!value.has_value()) {
29 ESP_LOGW(TAG,
"Invalid position value: '%s'", payload.c_str());
33 call.set_position(*value / 100.0f);
43 LOG_MQTT_COMPONENT(
true, has_command_topic)
44 if (traits.get_supports_position()) {
45 ESP_LOGCONFIG(TAG,
" Position State Topic: '%s'", this->get_position_state_topic().c_str());
46 ESP_LOGCONFIG(TAG,
" Position Command Topic: '%s'", this->get_position_command_topic().c_str());
54 if (traits.get_is_assumed_state()) {
57 if (traits.get_supports_position()) {
70 if (traits.get_supports_position()) {
72 if (!this->
publish(this->get_position_state_topic(), pos))
79 : traits.get_supports_position() ?
"open" void dump_config() override
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals)
Create a string from a value and an accuracy in decimals.
std::string get_device_class()
Get the device class, using the manual override if set.
float position
The position of the valve from 0.0 (fully closed) to 1.0 (fully open).
void add_on_state_callback(std::function< void()> &&f)
MQTTValveComponent(valve::Valve *valve)
constexpr const char *const MQTT_OPTIMISTIC
virtual ValveTraits get_traits()=0
The valve is currently opening.
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
ValveCall make_call()
Construct a new valve call used to control the valve.
constexpr const char *const MQTT_SET_POSITION_TOPIC
The valve is currently closing.
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
Simple Helper struct used for Home Assistant MQTT send_discovery().
bool get_supports_position() const
state bool send_initial_state() override
constexpr const char * c_str() const
const EntityBase * get_entity() const override
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
Implementation of SPI Controller mode.
Base class for all valve devices.
ValveOperation current_operation
The current operation of the valve (idle, opening, closing).
std::string component_type() const override
constexpr const char *const MQTT_DEVICE_CLASS
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
constexpr const char *const MQTT_POSITION_TOPIC
std::string get_command_topic_() const
Get the MQTT topic for listening to commands.
const StringRef & get_name() const