commands showertimer, showeralert work instant and permanent, move to shower.cpp

This commit is contained in:
MichaelDvP
2024-11-05 15:01:00 +01:00
parent fa630b9e64
commit 64a1e00501
3 changed files with 42 additions and 35 deletions

View File

@@ -51,6 +51,48 @@ void Shower::start() {
FL_(coldshot_cmd),
CommandFlag::ADMIN_ONLY);
Command::add(
EMSdevice::DeviceType::SYSTEM,
F_(showertimer),
[&](const char * value, const int8_t id, JsonObject output) {
bool b;
if (!Helpers::value2bool(value, b)) {
return false;
}
shower_timer_ = b;
EMSESP::webSettingsService.update([&](WebSettings & settings) {
if (settings.shower_timer != b) {
settings.shower_timer = b;
return StateUpdateResult::CHANGED;
}
return StateUpdateResult::UNCHANGED;
});
return true;
},
FL_(showertimer_cmd),
CommandFlag::ADMIN_ONLY);
Command::add(
EMSdevice::DeviceType::SYSTEM,
F_(showeralert),
[&](const char * value, const int8_t id, JsonObject output) {
bool b;
if (!Helpers::value2bool(value, b)) {
return false;
}
shower_alert_ = b;
EMSESP::webSettingsService.update([&](WebSettings & settings) {
if (settings.shower_alert != b) {
settings.shower_alert = b;
return StateUpdateResult::CHANGED;
}
return StateUpdateResult::UNCHANGED;
});
return true;
},
FL_(showeralert_cmd),
CommandFlag::ADMIN_ONLY);
if (shower_timer_) {
set_shower_state(false, true); // turns shower to off and creates HA topic if not already done
}

View File

@@ -196,37 +196,6 @@ bool System::command_syslog_level(const char * value, const int8_t id) {
return false;
}
*/
// shower timer
bool System::command_showertimer(const char * value, const int8_t id) {
bool b;
if (Helpers::value2bool(value, b)) {
EMSESP::webSettingsService.update([&](WebSettings & settings) {
if (settings.shower_timer != b) {
settings.shower_timer = b;
return StateUpdateResult::CHANGED;
}
return StateUpdateResult::UNCHANGED;
});
return true;
}
return false;
}
// shower alert
bool System::command_showeralert(const char * value, const int8_t id) {
bool b;
if (Helpers::value2bool(value, b)) {
EMSESP::webSettingsService.update([&](WebSettings & settings) {
if (settings.shower_alert != b) {
settings.shower_alert = b;
return StateUpdateResult::CHANGED;
}
return StateUpdateResult::UNCHANGED;
});
return true;
}
return false;
}
// send message - to log and MQTT
bool System::command_message(const char * value, const int8_t id) {
@@ -891,8 +860,6 @@ void System::commands_init() {
Command::add(EMSdevice::DeviceType::SYSTEM, F_(format), System::command_format, FL_(format_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, FL_(watch_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, F_(message), System::command_message, FL_(message_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, F_(showertimer), System::command_showertimer, FL_(showertimer_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(showeralert), System::command_showeralert, FL_(showeralert_cmd), CommandFlag::ADMIN_ONLY);
#if defined(EMSESP_TEST)
Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, FL_(test_cmd));
#endif

View File

@@ -69,8 +69,6 @@ class System {
static bool command_fetch(const char * value, const int8_t id);
static bool command_restart(const char * value, const int8_t id);
static bool command_format(const char * value, const int8_t id);
static bool command_showertimer(const char * value, const int8_t id);
static bool command_showeralert(const char * value, const int8_t id);
static bool command_watch(const char * value, const int8_t id);
static bool command_message(const char * value, const int8_t id);
static bool command_info(const char * value, const int8_t id, JsonObject output);