Skip to content

Commit

Permalink
fix ha discovery when no data avaible
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarecrash committed Nov 24, 2023
1 parent 8c8daf6 commit 243822d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
platform = espressif8266
framework = arduino
monitor_speed = 115200
custom_prog_version = 2.10.1HA-10
custom_prog_version = 2.10.2

build_flags =
-DVERSION=${this.custom_prog_version}
Expand Down
20 changes: 12 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,12 @@ void loop()
ws.cleanupClients(); // clean unused client connections
MDNS.update();
mqttclient.loop(); // Check if we have something to read from MQTT
if ((haDiscTrigger || haAutoDiscTrigger) && bms.getState())
if (haDiscTrigger || haAutoDiscTrigger)
{
sendHaDiscovery();
if(sendHaDiscovery()){
haDiscTrigger = false;
haAutoDiscTrigger = false;
}
}
}
bms.loop();
Expand Down Expand Up @@ -1016,6 +1017,15 @@ bool connectMQTT()

bool sendHaDiscovery()
{
if (!bms.getState() || bms.get.numberOfCells == 0)
{
return false;
}
if (!connectMQTT())
{
return false;
}

String haDeviceDescription = String("\"dev\":") +
"{\"ids\":[\"" + mqttClientId + "\"]," +
"\"name\":\"" + _settings.data.deviceName + "\"," +
Expand All @@ -1025,13 +1035,7 @@ bool sendHaDiscovery()
"\"sw\":\"" + SOFTWARE_VERSION + "\"" +
"}";

if (!connectMQTT())
{
return false;
}
char topBuff[128];
//char configBuff[1024];
//size_t mqttContentLength;
// main pack data
for (size_t i = 0; i < sizeof haPackDescriptor / sizeof haPackDescriptor[0]; i++)
{
Expand Down

0 comments on commit 243822d

Please sign in to comment.