12static const char *
const TAG =
"mqtt.cover";
25 if (traits.get_supports_position()) {
26 this->
subscribe(this->get_position_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
28 if (!value.has_value()) {
29 ESP_LOGW(TAG,
"Invalid position value: '%s'", payload.c_str());
37 if (traits.get_supports_tilt()) {
38 this->
subscribe(this->get_tilt_command_topic(), [
this](
const std::string &topic,
const std::string &payload) {
40 if (!value.has_value()) {
41 ESP_LOGW(TAG,
"Invalid tilt value: '%s'", payload.c_str());
55 LOG_MQTT_COMPONENT(
true, has_command_topic)
56 if (traits.get_supports_position()) {
58 " Position State Topic: '%s'\n"
59 " Position Command Topic: '%s'",
60 this->get_position_state_topic().c_str(), this->get_position_command_topic().c_str());
62 if (traits.get_supports_tilt()) {
64 " Tilt State Topic: '%s'\n"
65 " Tilt Command Topic: '%s'",
66 this->get_tilt_state_topic().c_str(), this->get_tilt_command_topic().c_str());
74 if (traits.get_is_assumed_state()) {
77 if (traits.get_supports_position()) {
81 if (traits.get_supports_tilt()) {
85 if (traits.get_supports_tilt() && !traits.get_supports_position()) {
97 if (traits.get_supports_position()) {
99 if (!this->
publish(this->get_position_state_topic(), pos))
102 if (traits.get_supports_tilt()) {
104 if (!this->
publish(this->get_tilt_state_topic(), pos))
111 : traits.get_supports_position() ?
"open"
std::string get_device_class()
Get the device class, using the manual override if set.
const StringRef & get_name() const
constexpr const char * c_str() const
CoverCall & set_command(const char *command)
Set the command as a string, "STOP", "OPEN", "CLOSE", "TOGGLE".
void perform()
Perform the cover call.
CoverCall & set_position(float position)
Set the call to a certain target position.
CoverCall & set_tilt(float tilt)
Set the call to a certain target tilt.
Base class for all cover devices.
CoverOperation current_operation
The current operation of the cover (idle, opening, closing).
void add_on_state_callback(std::function< void()> &&f)
CoverCall make_call()
Construct a new cover call used to control the cover.
float tilt
The current tilt value of the cover from 0.0 to 1.0.
float position
The position of the cover from 0.0 (fully closed) to 1.0 (fully open).
virtual CoverTraits get_traits()=0
bool get_supports_position() const
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
std::string get_command_topic_() const
Get the MQTT topic for listening to commands.
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
MQTTCoverComponent(cover::Cover *cover)
const EntityBase * get_entity() const override
state state bool send_initial_state() override
std::string component_type() const override
void dump_config() override
@ COVER_OPERATION_OPENING
The cover is currently opening.
@ COVER_OPERATION_CLOSING
The cover is currently closing.
constexpr const char *const MQTT_POSITION_TOPIC
constexpr const char *const MQTT_OPTIMISTIC
constexpr const char *const MQTT_TILT_STATUS_TOPIC
constexpr const char *const MQTT_TILT_COMMAND_TOPIC
constexpr const char *const MQTT_DEVICE_CLASS
constexpr const char *const MQTT_SET_POSITION_TOPIC
Providing packet encoding functions for exchanging data with a remote host.
std::string value_accuracy_to_string(float value, int8_t accuracy_decimals)
Create a string from a value and an accuracy in decimals.
optional< T > parse_number(const char *str)
Parse an unsigned decimal number from a null-terminated string.
Simple Helper struct used for Home Assistant MQTT send_discovery().
bool command_topic
If the command topic should be included. Default to true.