Move publishHass method to MqttHandleHassClass
This commit is contained in:
parent
113caf510f
commit
91f79fea19
@ -59,6 +59,7 @@ public:
|
||||
void forceUpdate();
|
||||
|
||||
private:
|
||||
void publish(const String& subtopic, const String& payload);
|
||||
void publishField(std::shared_ptr<InverterAbstract> inv, uint8_t channel, byteAssign_fieldDeviceClass_t fieldType, bool clear = false);
|
||||
void publishInverterButton(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* deviceClass, const char* subTopic, const char* payload);
|
||||
void publishInverterNumber(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, int16_t min = 1, int16_t max = 100);
|
||||
|
||||
@ -16,7 +16,6 @@ public:
|
||||
bool getConnected();
|
||||
void publish(const String& subtopic, const String& payload);
|
||||
void publishGeneric(const String& topic, const String& payload, bool retain, uint8_t qos = 0);
|
||||
void publishHass(const String& subtopic, const String& payload);
|
||||
|
||||
void subscribe(const String& topic, uint8_t qos, const espMqttClientTypes::OnMessageCallback& cb);
|
||||
void unsubscribe(const String& topic);
|
||||
|
||||
@ -131,9 +131,9 @@ void MqttHandleHassClass::publishField(std::shared_ptr<InverterAbstract> inv, ui
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
MqttSettings.publishHass(configTopic, buffer);
|
||||
publish(configTopic, buffer);
|
||||
} else {
|
||||
MqttSettings.publishHass(configTopic, "");
|
||||
publish(configTopic, "");
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ void MqttHandleHassClass::publishInverterButton(std::shared_ptr<InverterAbstract
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
MqttSettings.publishHass(configTopic, buffer);
|
||||
publish(configTopic, buffer);
|
||||
}
|
||||
|
||||
void MqttHandleHassClass::publishInverterNumber(
|
||||
@ -208,7 +208,7 @@ void MqttHandleHassClass::publishInverterNumber(
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
MqttSettings.publishHass(configTopic, buffer);
|
||||
publish(configTopic, buffer);
|
||||
}
|
||||
|
||||
void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptr<InverterAbstract> inv, const char* caption, const char* subTopic, const char* payload_on, const char* payload_off)
|
||||
@ -237,7 +237,7 @@ void MqttHandleHassClass::publishInverterBinarySensor(std::shared_ptr<InverterAb
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
MqttSettings.publishHass(configTopic, buffer);
|
||||
publish(configTopic, buffer);
|
||||
}
|
||||
|
||||
void MqttHandleHassClass::createDeviceInfo(JsonObject& object, std::shared_ptr<InverterAbstract> inv)
|
||||
@ -249,3 +249,10 @@ void MqttHandleHassClass::createDeviceInfo(JsonObject& object, std::shared_ptr<I
|
||||
object[F("mdl")] = inv->typeName();
|
||||
object[F("sw")] = AUTO_GIT_HASH;
|
||||
}
|
||||
|
||||
void MqttHandleHassClass::publish(const String& subtopic, const String& payload)
|
||||
{
|
||||
String topic = Configuration.get().Mqtt_Hass_Topic;
|
||||
topic += subtopic;
|
||||
MqttSettings.publishGeneric(topic.c_str(), payload.c_str(), Configuration.get().Mqtt_Hass_Retain);
|
||||
}
|
||||
@ -165,13 +165,6 @@ void MqttSettingsClass::publishGeneric(const String& topic, const String& payloa
|
||||
mqttClient->publish(topic.c_str(), qos, retain, payload.c_str());
|
||||
}
|
||||
|
||||
void MqttSettingsClass::publishHass(const String& subtopic, const String& payload)
|
||||
{
|
||||
String topic = Configuration.get().Mqtt_Hass_Topic;
|
||||
topic += subtopic;
|
||||
mqttClient->publish(topic.c_str(), 0, Configuration.get().Mqtt_Hass_Retain, payload.c_str());
|
||||
}
|
||||
|
||||
void MqttSettingsClass::init()
|
||||
{
|
||||
using std::placeholders::_1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user