Skip to content

Commit

Permalink
Fix restart button not display
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungpv committed Aug 28, 2024
1 parent 02463a3 commit b6255a2
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@ void haConfigFreq(String tag, String unit, String icon) {

haConfig["icon"] = icon;
haConfig["name"] = tag;
haConfig["unique_id"] = String("hvac_") + getId() + "_" + tag;
haConfig["unique_id"] = getId() + "_" + tag;

haConfig["dev_cla"] = "frequency";
haConfig["stat_t"] = ha_state_topic;
Expand Down Expand Up @@ -2631,7 +2631,7 @@ void haConfigSensor(String tag, String unit, String icon)
tag.replace(" ", "_");
tag.toLowerCase();
//
haConfig["unique_id"] = String("hvac_") + getId() + "_" + tag;
haConfig["unique_id"] = getId() + "_" + tag;
if (strcmp(tag.c_str(), "connection_state") == 0)
{
haConfig["dev_cla"] = "connectivity";
Expand Down Expand Up @@ -2704,16 +2704,14 @@ void haConfigButton(String tag, String payload_press, String icon)
// clean string
tag.replace(" ", "_");
tag.toLowerCase();
String deviceId = hostname;
deviceId.toLowerCase();
//
haConfig["unique_id"] = deviceId + "_" + tag;
haConfig["unique_id"] = getId() + "_" + tag;
if (strcmp(payload_press.c_str(), "restart") == 0)
{
haConfig["dev_cla"] = "restart";
}
haConfig["command_topic"] = ha_system_set_topic;
haConfig["entity_category"] = "config";
haConfig["entity_category"] = "diagnostic";
haConfig["payload_press"] = payload_press; //"restart", "factory", "upgrade" ;

JsonObject haConfigDevice = haConfig["device"].to<JsonObject>();
Expand All @@ -2727,7 +2725,7 @@ void haConfigButton(String tag, String payload_press, String icon)

String mqttOutput;
serializeJson(haConfig, mqttOutput);
String ha_config_topic_button = "homeassistant/button/" + deviceId + "/" + tag + "/config";
String ha_config_topic_button = "homeassistant/button/" + getId() + "/" + tag + "/config";
mqttClient->publish(ha_config_topic_button.c_str(), 1, true, mqttOutput.c_str());
}

Expand Down Expand Up @@ -2844,7 +2842,8 @@ void sendHaConfig()
String mqttOutput;
serializeJson(haConfig, mqttOutput);
mqttClient->publish(ha_config_topic.c_str(), 1, true, mqttOutput.c_str());

// Button
haConfigButton("Restart", "restart", "mdi:restart");
// Temperature sensors
haConfigTemp("roomTemperature", "mdi:thermometer");
// Freq sensor
Expand All @@ -2856,8 +2855,6 @@ void sendHaConfig()
haConfigSensor("Free Heap", "%", "mdi:memory");
haConfigSensor("RSSI", "dBm", "mdi:network-strength-1");
haConfigSensor("BSSI", "", "mdi:router-wireless");
// Button
haConfigButton("Restart", "restart", "mdi:restart");
}

void mqttConnect()
Expand Down

0 comments on commit b6255a2

Please sign in to comment.