HASS: Move create of device object so separate method
This commit is contained in:
parent
13b22de53a
commit
a7f571a581
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "Configuration.h"
|
#include "Configuration.h"
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <ArduinoJson.h>
|
||||||
#include <Hoymiles.h>
|
#include <Hoymiles.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
@ -59,6 +60,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void publishField(std::shared_ptr<InverterAbstract> inv, uint8_t channel, byteAssign_fieldDeviceClass_t fieldType, bool clear = false);
|
void publishField(std::shared_ptr<InverterAbstract> inv, uint8_t channel, byteAssign_fieldDeviceClass_t fieldType, bool clear = false);
|
||||||
|
void createDeviceInfo(JsonObject& object, std::shared_ptr<InverterAbstract> inv);
|
||||||
|
|
||||||
bool _wasConnected = false;
|
bool _wasConnected = false;
|
||||||
bool _updateForced = false;
|
bool _updateForced = false;
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
* Copyright (C) 2022 Thomas Basler and others
|
* Copyright (C) 2022 Thomas Basler and others
|
||||||
*/
|
*/
|
||||||
#include "MqttHassPublishing.h"
|
#include "MqttHassPublishing.h"
|
||||||
#include "ArduinoJson.h"
|
|
||||||
#include "MqttPublishing.h"
|
#include "MqttPublishing.h"
|
||||||
#include "MqttSettings.h"
|
#include "MqttSettings.h"
|
||||||
#include "NetworkSettings.h"
|
#include "NetworkSettings.h"
|
||||||
@ -102,13 +101,8 @@ void MqttHassPublishingClass::publishField(std::shared_ptr<InverterAbstract> inv
|
|||||||
}
|
}
|
||||||
|
|
||||||
DynamicJsonDocument deviceDoc(512);
|
DynamicJsonDocument deviceDoc(512);
|
||||||
deviceDoc[F("name")] = inv->name();
|
|
||||||
deviceDoc[F("ids")] = String(serial);
|
|
||||||
deviceDoc[F("cu")] = String(F("http://")) + String(WiFi.localIP().toString());
|
|
||||||
deviceDoc[F("mf")] = F("OpenDTU");
|
|
||||||
deviceDoc[F("mdl")] = inv->typeName();
|
|
||||||
deviceDoc[F("sw")] = AUTO_GIT_HASH;
|
|
||||||
JsonObject deviceObj = deviceDoc.as<JsonObject>();
|
JsonObject deviceObj = deviceDoc.as<JsonObject>();
|
||||||
|
createDeviceInfo(deviceObj, inv);
|
||||||
|
|
||||||
DynamicJsonDocument root(1024);
|
DynamicJsonDocument root(1024);
|
||||||
root[F("name")] = name;
|
root[F("name")] = name;
|
||||||
@ -129,8 +123,22 @@ void MqttHassPublishingClass::publishField(std::shared_ptr<InverterAbstract> inv
|
|||||||
char buffer[512];
|
char buffer[512];
|
||||||
serializeJson(root, buffer);
|
serializeJson(root, buffer);
|
||||||
MqttSettings.publishHass(configTopic, buffer);
|
MqttSettings.publishHass(configTopic, buffer);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
MqttSettings.publishHass(configTopic, "");
|
MqttSettings.publishHass(configTopic, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MqttHassPublishingClass::createDeviceInfo(JsonObject& object, std::shared_ptr<InverterAbstract> inv)
|
||||||
|
{
|
||||||
|
char serial[sizeof(uint64_t) * 8 + 1];
|
||||||
|
snprintf(serial, sizeof(serial), "%0x%08x",
|
||||||
|
((uint32_t)((inv->serial() >> 32) & 0xFFFFFFFF)),
|
||||||
|
((uint32_t)(inv->serial() & 0xFFFFFFFF)));
|
||||||
|
|
||||||
|
object[F("name")] = inv->name();
|
||||||
|
object[F("ids")] = String(serial);
|
||||||
|
object[F("cu")] = String(F("http://")) + String(WiFi.localIP().toString());
|
||||||
|
object[F("mf")] = F("OpenDTU");
|
||||||
|
object[F("mdl")] = inv->typeName();
|
||||||
|
object[F("sw")] = AUTO_GIT_HASH;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user