9 #ifdef USE_DATETIME_DATETIME 14 static const char *
const TAG =
"mqtt.datetime.datetime";
23 if (root.containsKey(
"year")) {
24 call.set_year(root[
"year"]);
26 if (root.containsKey(
"month")) {
27 call.set_month(root[
"month"]);
29 if (root.containsKey(
"day")) {
30 call.set_day(root[
"day"]);
32 if (root.containsKey(
"hour")) {
33 call.set_hour(root[
"hour"]);
35 if (root.containsKey(
"minute")) {
36 call.set_minute(root[
"minute"]);
38 if (root.containsKey(
"second")) {
39 call.set_second(root[
"second"]);
45 this->datetime_->minute, this->datetime_->second);
51 LOG_MQTT_COMPONENT(
true,
true)
63 this->datetime_->hour, this->datetime_->minute, this->datetime_->second);
72 root[
"month"] =
month;
83 #endif // USE_DATETIME_DATETIME
bool publish_state(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second)
bool publish_json(const std::string &topic, const json::json_build_t &f)
Construct and send a JSON MQTT message.
void setup() override
Override setup.
void subscribe_json(const std::string &topic, const mqtt_json_callback_t &callback, uint8_t qos=0)
Subscribe to a MQTT topic and automatically parse JSON payload.
const EntityBase * get_entity() const override
MQTTDateTimeComponent(datetime::DateTimeEntity *datetime)
Construct this MQTTDateTimeComponent instance with the provided friendly_name and time...
bool has_state() const
Return whether this Datetime has gotten a full state yet.
Simple Helper struct used for Home Assistant MQTT send_discovery().
void send_discovery(JsonObject root, mqtt::SendDiscoveryConfig &config) override
std::string component_type() const override
datetime::DateTimeEntity * datetime_
void add_on_state_callback(std::function< void()> &&callback)
constexpr const char * c_str() const
bool send_initial_state() override
Implementation of SPI Controller mode.
void dump_config() override
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.
const StringRef & get_name() const