11static const char *
const TAG =
"mqtt.select";
28 LOG_MQTT_COMPONENT(
true,
false);
38 JsonArray
options = root[MQTT_OPTIONS].to<JsonArray>();
39 for (
const auto &option : traits.get_options())
47 return this->
publish_state(std::string(option.c_str(), option.size()));
53 char topic_buf[MQTT_DEFAULT_TOPIC_MAX_LEN];
const StringRef & get_name() const
constexpr const char * c_str() const
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
StringRef get_state_topic_to_(std::span< char, MQTT_DEFAULT_TOPIC_MAX_LEN > buf) const
Get the MQTT state topic into a buffer (no heap allocation for non-lambda custom topics).
std::string get_command_topic_() const
Get the MQTT topic for listening to commands (allocates std::string).
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
void setup() override
Override setup.
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
void dump_config() override
bool publish_state(const std::string &value)
bool send_initial_state() override
MQTTSelectComponent(select::Select *select)
Construct this MQTTSelectComponent instance with the provided friendly_name and select.
SelectCall & set_option(const char *option, size_t len)
Base-class for all selects.
const char * option_at(size_t index) const
Return the option value at the provided index offset (as const char* from flash).
SelectCall make_call()
Instantiate a SelectCall object to modify this select component's state.
void add_on_state_callback(std::function< void(size_t)> &&callback)
StringRef current_option() const
Return the currently selected option, or empty StringRef if no state.
MQTT_COMPONENT_TYPE(MQTTAlarmControlPanelComponent, "alarm_control_panel") const EntityBase *MQTTAlarmControlPanelComponent
Simple Helper struct used for Home Assistant MQTT send_discovery().
bool command_topic
If the command topic should be included. Default to true.