mirror of
https://github.com/esphome/esphome.git
synced 2026-09-11 23:37:34 +00:00
Merge remote-tracking branch 'upstream/mqtt-publish-json-std-bind-to-lambda' into integration
This commit is contained in:
@@ -405,15 +405,14 @@ template<typename... Ts> class MQTTPublishJsonAction : public Action<Ts...> {
|
||||
void set_payload(std::function<void(Ts..., JsonObject)> payload) { this->payload_ = payload; }
|
||||
|
||||
void play(const Ts &...x) override {
|
||||
auto f = std::bind(&MQTTPublishJsonAction<Ts...>::encode_, this, x..., std::placeholders::_1);
|
||||
auto topic = this->topic_.value(x...);
|
||||
auto qos = this->qos_.value(x...);
|
||||
auto retain = this->retain_.value(x...);
|
||||
this->parent_->publish_json(topic, f, qos, retain);
|
||||
this->parent_->publish_json(
|
||||
topic, [this, x...](JsonObject root) { this->payload_(x..., root); }, qos, retain);
|
||||
}
|
||||
|
||||
protected:
|
||||
void encode_(Ts... x, JsonObject root) { this->payload_(x..., root); }
|
||||
std::function<void(Ts..., JsonObject)> payload_;
|
||||
MQTTClientComponent *parent_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user