Skip to content

Commit

Permalink
check lastcode, fix #2189, allow setting silentfrom/to as hh:mm
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Nov 8, 2024
1 parent afc2afb commit df92e92
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/devices/boiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,10 @@ void Boiler::process_UBAErrorMessage(std::shared_ptr<const Telegram> telegram) {
uint8_t min = telegram->message_data[8];
uint16_t duration = telegram->message_data[9] * 256 + telegram->message_data[10];
uint32_t date = (year - 2000) * 535680UL + month * 44640UL + day * 1440UL + hour * 60 + min + duration;
// check valid https://github.com/emsesp/EMS-ESP32/issues/2189
if (day == 0 || day > 31 || month == 0 || month > 12 || !std::isprint(code[0]) || !std::isprint(code[1])) {
return;
}
// store only the newest code from telegrams 10 and 11
if (date > lastCodeDate_ && lastCodeDate_) {
lastCodeDate_ = date;
Expand Down Expand Up @@ -1855,6 +1859,9 @@ void Boiler::process_UBAErrorMessage2(std::shared_ptr<const Telegram> telegram)
code[2] = telegram->message_data[7];
code[3] = 0;
telegram->read_value(codeNo, 8);
if (!std::isprint(code[0]) || !std::isprint(code[1]) || !std::isprint(code[2])) {
return;
}

// check for valid date, https://github.com/emsesp/EMS-ESP32/issues/204
if (telegram->message_data[10] & 0x80) {
Expand Down Expand Up @@ -2970,19 +2977,19 @@ bool Boiler::set_silentMode(const char * value, const int8_t id) {
}

bool Boiler::set_silentFrom(const char * value, const int8_t id) {
int v;
if (!Helpers::value2number(value, v)) {
if (value == nullptr || value[0] < '0' || value[0] > '9') {
return false;
}
auto v = Helpers::string2minutes(value);
write_command(0x484, 52, v / 15, 0x484);
return true;
}

bool Boiler::set_silentTo(const char * value, const int8_t id) {
int v;
if (!Helpers::value2number(value, v)) {
if (value == nullptr || value[0] < '0' || value[0] > '9') {
return false;
}
auto v = Helpers::string2minutes(value);
write_command(0x484, 53, v / 15, 0x484);
return true;
}
Expand Down

0 comments on commit df92e92

Please sign in to comment.