limit thermostat time set to 3 tries, check dst flag #2142

This commit is contained in:
MichaelDvP
2024-10-29 11:43:50 +01:00
parent 29016b6342
commit 52adf6749e

View File

@@ -1562,9 +1562,15 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
}
static uint8_t setTimeRetry = 0;
uint8_t dst = 0xFE;
bool use_dst = !telegram->read_value(dst, 9) || dst == 0xFF;
if ((telegram->message_data[7] & 0x0C) && has_command(&dateTime_)) { // date and time not valid
if (setTimeRetry < 3) {
if (!use_dst) {
set_datetime("ntp", 0); // set from NTP without dst
} else {
set_datetime("ntp", -1); // set from NTP
}
setTimeRetry++;
}
return;
@@ -1580,7 +1586,9 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
tm_->tm_hour = telegram->message_data[2];
tm_->tm_min = telegram->message_data[4];
tm_->tm_sec = telegram->message_data[5];
if (use_dst) {
tm_->tm_isdst = telegram->message_data[7] & 0x01;
}
// render date to DD.MM.YYYY HH:MM and publish
char newdatetime[sizeof(dateTime_)];
@@ -1595,7 +1603,11 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
double difference = difftime(now, ttime);
if (difference > 15 || difference < -15) {
if (setTimeRetry < 3) {
if (!use_dst) {
set_datetime("ntp", 0); // set from NTP without dst
} else {
set_datetime("ntp", -1); // set from NTP
}
LOG_INFO("thermostat time correction from ntp");
setTimeRetry++;
}
@@ -2695,7 +2707,7 @@ bool Thermostat::set_datetime(const char * value, const int8_t id) {
data[4] = tm_->tm_min;
data[5] = tm_->tm_sec;
data[6] = (tm_->tm_wday + 6) % 7; // Bosch counts from Mo, time from Su
data[7] = tm_->tm_isdst + 2; // set DST and flag for ext. clock
data[7] = (id == 0) ? 2 : tm_->tm_isdst + 2; // set DST and flag for ext. clock
if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) {
data[6]++; // Junkers use 1-7;
data[7] = 0;