comply with function naming convention

This commit is contained in:
hermlon 2024-09-08 11:21:28 +02:00
parent f8cbbbb19f
commit 8cbc49bf2b
4 changed files with 22 additions and 26 deletions

View file

@ -12,15 +12,15 @@ namespace mqtt {
static const char *const TAG = "mqtt-backend-esp8266"; static const char *const TAG = "mqtt-backend-esp8266";
void MQTTBackendESP8266::on_mqtt_message_wrapper_(MQTTClient *client, char topic[], char bytes[], int length) { void MQTTBackendESP8266::on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length) {
static_cast<MQTTBackendESP8266 *>(client->ref)->on_mqtt_message_(client, topic, bytes, length); static_cast<MQTTBackendESP8266 *>(client->ref)->on_mqtt_message(client, topic, bytes, length);
} }
void MQTTBackendESP8266::on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length) { void MQTTBackendESP8266::on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length) {
this->on_message_.call(topic, bytes, length, 0, length); this->on_message_.call(topic, bytes, length, 0, length);
} }
void MQTTBackendESP8266::initialize_() { void MQTTBackendESP8266::initialize() {
#ifdef USE_MQTT_SECURE_CLIENT #ifdef USE_MQTT_SECURE_CLIENT
if (this->ca_certificate_str_.has_value()) { if (this->ca_certificate_str_.has_value()) {
this->ca_certificate_.append(this->ca_certificate_str_.value().c_str()); this->ca_certificate_.append(this->ca_certificate_str_.value().c_str());
@ -39,7 +39,7 @@ void MQTTBackendESP8266::initialize_() {
this->is_initalized_ = true; this->is_initalized_ = true;
} }
void MQTTBackendESP8266::handleErrors_() { void MQTTBackendESP8266::handleErrors() {
lwmqtt_err_t error = this->mqtt_client_.lastError(); lwmqtt_err_t error = this->mqtt_client_.lastError();
lwmqtt_return_code_t return_code = this->mqtt_client_.returnCode(); lwmqtt_return_code_t return_code = this->mqtt_client_.returnCode();
if (error != LWMQTT_SUCCESS) { if (error != LWMQTT_SUCCESS) {
@ -84,11 +84,11 @@ void MQTTBackendESP8266::handleErrors_() {
void MQTTBackendESP8266::connect() { void MQTTBackendESP8266::connect() {
if (!this->is_initalized_) { if (!this->is_initalized_) {
this->initialize_(); this->initialize();
} }
this->mqtt_client_.begin(this->host_.c_str(), this->port_, this->wifi_client_); this->mqtt_client_.begin(this->host_.c_str(), this->port_, this->wifi_client_);
this->mqtt_client_.connect(this->client_id_.c_str(), this->username_.c_str(), this->password_.c_str()); this->mqtt_client_.connect(this->client_id_.c_str(), this->username_.c_str(), this->password_.c_str());
this->handleErrors_(); this->handleErrors();
} }
void MQTTBackendESP8266::loop() { void MQTTBackendESP8266::loop() {

View file

@ -4,8 +4,6 @@
#ifdef USE_MQTT #ifdef USE_MQTT
#ifdef USE_ESP8266 #ifdef USE_ESP8266
#include "mqtt_backend.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <BearSSLHelpers.h> #include <BearSSLHelpers.h>
@ -96,10 +94,10 @@ class MQTTBackendESP8266 final : public MQTTBackend {
void set_ssl_fingerprint(const std::array<uint8_t, 20> &fingerprint) { this->ssl_fingerprint_ = fingerprint; }; void set_ssl_fingerprint(const std::array<uint8_t, 20> &fingerprint) { this->ssl_fingerprint_ = fingerprint; };
protected: protected:
void initialize_(); void initialize();
void handleErrors_(); void handleErrors();
static void on_mqtt_message_wrapper_(MQTTClient *client, char topic[], char bytes[], int length); static void on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length);
void on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length); void on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length);
#ifdef USE_MQTT_SECURE_CLIENT #ifdef USE_MQTT_SECURE_CLIENT
WiFiClientSecure wifi_client_; WiFiClientSecure wifi_client_;

View file

@ -12,21 +12,21 @@ namespace mqtt {
static const char *const TAG = "mqtt-backend-libretiny"; static const char *const TAG = "mqtt-backend-libretiny";
void MQTTBackendLibreTiny::on_mqtt_message_wrapper_(MQTTClient *client, char topic[], char bytes[], int length) { void MQTTBackendLibreTiny::on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length) {
static_cast<MQTTBackendLibreTiny *>(client->ref)->on_mqtt_message_(client, topic, bytes, length); static_cast<MQTTBackendLibreTiny *>(client->ref)->on_mqtt_message(client, topic, bytes, length);
} }
void MQTTBackendLibreTiny::on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length) { void MQTTBackendLibreTiny::on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length) {
this->on_message_.call(topic, bytes, length, 0, length); this->on_message_.call(topic, bytes, length, 0, length);
} }
void MQTTBackendLibreTiny::initialize_() { void MQTTBackendLibreTiny::initialize() {
this->mqtt_client_.ref = this; this->mqtt_client_.ref = this;
mqtt_client_.onMessageAdvanced(MQTTBackendLibreTiny::on_mqtt_message_wrapper_); mqtt_client_.onMessageAdvanced(MQTTBackendLibreTiny::on_mqtt_message_wrapper_);
this->is_initalized_ = true; this->is_initalized_ = true;
} }
void MQTTBackendLibreTiny::handleErrors_() { void MQTTBackendLibreTiny::handleErrors() {
lwmqtt_err_t error = this->mqtt_client_.lastError(); lwmqtt_err_t error = this->mqtt_client_.lastError();
lwmqtt_return_code_t return_code = this->mqtt_client_.returnCode(); lwmqtt_return_code_t return_code = this->mqtt_client_.returnCode();
if (error != LWMQTT_SUCCESS) { if (error != LWMQTT_SUCCESS) {
@ -65,11 +65,11 @@ void MQTTBackendLibreTiny::handleErrors_() {
void MQTTBackendLibreTiny::connect() { void MQTTBackendLibreTiny::connect() {
if (!this->is_initalized_) { if (!this->is_initalized_) {
this->initialize_(); this->initialize();
} }
this->mqtt_client_.begin(this->host_.c_str(), this->port_, this->wifi_client_); this->mqtt_client_.begin(this->host_.c_str(), this->port_, this->wifi_client_);
this->mqtt_client_.connect(this->client_id_.c_str(), this->username_.c_str(), this->password_.c_str()); this->mqtt_client_.connect(this->client_id_.c_str(), this->username_.c_str(), this->password_.c_str());
this->handleErrors_(); this->handleErrors();
} }
void MQTTBackendLibreTiny::loop() { void MQTTBackendLibreTiny::loop() {

View file

@ -4,8 +4,6 @@
#ifdef USE_MQTT #ifdef USE_MQTT
#ifdef USE_LIBRETINY #ifdef USE_LIBRETINY
#include "mqtt_backend.h"
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include <WiFiClient.h> #include <WiFiClient.h>
@ -95,10 +93,10 @@ class MQTTBackendLibreTiny final : public MQTTBackend {
void set_ssl_fingerprint(const std::array<uint8_t, 20> &fingerprint) { this->ssl_fingerprint_ = fingerprint; }; void set_ssl_fingerprint(const std::array<uint8_t, 20> &fingerprint) { this->ssl_fingerprint_ = fingerprint; };
protected: protected:
void initialize_(); void initialize();
void handleErrors_(); void handleErrors();
static void on_mqtt_message_wrapper_(MQTTClient *client, char topic[], char bytes[], int length); static void on_mqtt_message_wrapper(MQTTClient *client, char topic[], char bytes[], int length);
void on_mqtt_message_(MQTTClient *client, char topic[], char bytes[], int length); void on_mqtt_message(MQTTClient *client, char topic[], char bytes[], int length);
WiFiClient wifi_client_; WiFiClient wifi_client_;
MQTTClient mqtt_client_; MQTTClient mqtt_client_;