move 6x identical code to one function add_ha_bool

This commit is contained in:
MichaelDvP
2024-08-02 12:40:16 +02:00
parent aeafb5f566
commit ab587fa1b7
6 changed files with 24 additions and 69 deletions

View File

@@ -202,17 +202,7 @@ void Shower::set_shower_state(bool state, bool force) {
snprintf(stat_t, sizeof(stat_t), "%s/shower_active", Mqtt::base().c_str());
doc["stat_t"] = stat_t;
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
doc["pl_on"] = "true";
doc["pl_off"] = "false";
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
doc["pl_on"] = 1;
doc["pl_off"] = 0;
} else {
char result[12];
doc["pl_on"] = Helpers::render_boolean(result, true);
doc["pl_off"] = Helpers::render_boolean(result, false);
}
Mqtt::add_ha_bool(doc);
Mqtt::add_ha_sections_to_doc("shower", stat_t, doc, true); // create first dev & ids