mirror of
https://github.com/esphome/esphome.git
synced 2025-02-24 13:58:14 +00:00
31 lines
1.2 KiB
C++
31 lines
1.2 KiB
C++
#include "custom_mqtt_device.h"
|
|
#include "esphome/core/log.h"
|
|
|
|
namespace esphome {
|
|
namespace mqtt {
|
|
|
|
static const char *TAG = "mqtt.custom";
|
|
|
|
bool CustomMQTTDevice::publish(const std::string &topic, const std::string &payload, uint8_t qos, bool retain) {
|
|
return global_mqtt_client->publish(topic, payload, qos, retain);
|
|
}
|
|
bool CustomMQTTDevice::publish(const std::string &topic, float value, int8_t number_decimals) {
|
|
auto str = value_accuracy_to_string(value, number_decimals);
|
|
return this->publish(topic, str);
|
|
}
|
|
bool CustomMQTTDevice::publish(const std::string &topic, int value) {
|
|
char buffer[24];
|
|
sprintf(buffer, "%d", value);
|
|
return this->publish(topic, buffer);
|
|
}
|
|
bool CustomMQTTDevice::publish_json(const std::string &topic, const json::json_build_t &f, uint8_t qos, bool retain) {
|
|
return global_mqtt_client->publish_json(topic, f, qos, retain);
|
|
}
|
|
bool CustomMQTTDevice::publish_json(const std::string &topic, const json::json_build_t &f) {
|
|
return this->publish_json(topic, f, 0, false);
|
|
}
|
|
bool CustomMQTTDevice::is_connected() { return global_mqtt_client != nullptr && global_mqtt_client->is_connected(); }
|
|
|
|
} // namespace mqtt
|
|
} // namespace esphome
|