12 static const char *
const TAG =
"mqtt.number";
20 auto val = parse_number<float>(
state);
21 if (!
val.has_value()) {
22 ESP_LOGW(TAG,
"Can't convert '%s' to number!", state.c_str());
34 LOG_MQTT_COMPONENT(
true,
false)
44 root[
MQTT_MAX] = traits.get_max_value();
72 snprintf(buffer,
sizeof(buffer),
"%f", value);
constexpr const char *const MQTT_MIN
bool has_state() const
Return whether this number has gotten a full state yet.
void add_on_state_callback(std::function< void(float)> &&callback)
std::string get_device_class()
Get the device class, using the manual override if set.
void setup() override
Override setup.
bool command_topic
If the command topic should be included. Default to true.
bool publish(const std::string &topic, const std::string &payload)
Send a MQTT message.
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
void subscribe(const std::string &topic, mqtt_callback_t callback, uint8_t qos=0)
Subscribe to a MQTT topic.
constexpr const char *const MQTT_STEP
MQTTNumberComponent(number::Number *number)
Construct this MQTTNumberComponent instance with the provided friendly_name and number.
Base-class for all numbers.
constexpr const char *const MQTT_UNIT_OF_MEASUREMENT
Simple Helper struct used for Home Assistant MQTT send_discovery().
std::string get_unit_of_measurement()
Get the unit of measurement, using the manual override if set.
std::string component_type() const override
Override for MQTTComponent, returns "number".
constexpr const char *const MQTT_MAX
constexpr const char *const MQTT_MODE
void dump_config() override
constexpr const char * c_str() const
bool send_initial_state() override
bool publish_state(float value)
Implementation of SPI Controller mode.
float get_min_value() const
NumberMode get_mode() const
constexpr const char *const MQTT_DEVICE_CLASS
std::string get_state_topic_() const
Get the MQTT topic that new states will be shared to.
const EntityBase * get_entity() const override
std::string get_command_topic_() const
Get the MQTT topic for listening to commands.
const StringRef & get_name() const