Skip to content

Commit 52adf67

Browse files
committed
limit thermostat time set to 3 tries, check dst flag #2142
1 parent 29016b6 commit 52adf67

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/devices/thermostat.cpp

+26-14
Original file line numberDiff line numberDiff line change
@@ -1562,25 +1562,33 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
15621562
}
15631563

15641564
static uint8_t setTimeRetry = 0;
1565+
uint8_t dst = 0xFE;
1566+
bool use_dst = !telegram->read_value(dst, 9) || dst == 0xFF;
15651567
if ((telegram->message_data[7] & 0x0C) && has_command(&dateTime_)) { // date and time not valid
15661568
if (setTimeRetry < 3) {
1567-
set_datetime("ntp", -1); // set from NTP
1569+
if (!use_dst) {
1570+
set_datetime("ntp", 0); // set from NTP without dst
1571+
} else {
1572+
set_datetime("ntp", -1); // set from NTP
1573+
}
15681574
setTimeRetry++;
15691575
}
15701576
return;
15711577
}
15721578

15731579
// check clock
1574-
time_t now = time(nullptr);
1575-
tm * tm_ = localtime(&now);
1576-
bool tset_ = tm_->tm_year > 110; // year 2010 and up, time is valid
1577-
tm_->tm_year = (telegram->message_data[0] & 0x7F) + 100; // IVT
1578-
tm_->tm_mon = telegram->message_data[1] - 1;
1579-
tm_->tm_mday = telegram->message_data[3];
1580-
tm_->tm_hour = telegram->message_data[2];
1581-
tm_->tm_min = telegram->message_data[4];
1582-
tm_->tm_sec = telegram->message_data[5];
1583-
tm_->tm_isdst = telegram->message_data[7] & 0x01;
1580+
time_t now = time(nullptr);
1581+
tm * tm_ = localtime(&now);
1582+
bool tset_ = tm_->tm_year > 110; // year 2010 and up, time is valid
1583+
tm_->tm_year = (telegram->message_data[0] & 0x7F) + 100; // IVT
1584+
tm_->tm_mon = telegram->message_data[1] - 1;
1585+
tm_->tm_mday = telegram->message_data[3];
1586+
tm_->tm_hour = telegram->message_data[2];
1587+
tm_->tm_min = telegram->message_data[4];
1588+
tm_->tm_sec = telegram->message_data[5];
1589+
if (use_dst) {
1590+
tm_->tm_isdst = telegram->message_data[7] & 0x01;
1591+
}
15841592

15851593
// render date to DD.MM.YYYY HH:MM and publish
15861594
char newdatetime[sizeof(dateTime_)];
@@ -1595,7 +1603,11 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
15951603
double difference = difftime(now, ttime);
15961604
if (difference > 15 || difference < -15) {
15971605
if (setTimeRetry < 3) {
1598-
set_datetime("ntp", -1); // set from NTP
1606+
if (!use_dst) {
1607+
set_datetime("ntp", 0); // set from NTP without dst
1608+
} else {
1609+
set_datetime("ntp", -1); // set from NTP
1610+
}
15991611
LOG_INFO("thermostat time correction from ntp");
16001612
setTimeRetry++;
16011613
}
@@ -2694,8 +2706,8 @@ bool Thermostat::set_datetime(const char * value, const int8_t id) {
26942706
data[3] = tm_->tm_mday;
26952707
data[4] = tm_->tm_min;
26962708
data[5] = tm_->tm_sec;
2697-
data[6] = (tm_->tm_wday + 6) % 7; // Bosch counts from Mo, time from Su
2698-
data[7] = tm_->tm_isdst + 2; // set DST and flag for ext. clock
2709+
data[6] = (tm_->tm_wday + 6) % 7; // Bosch counts from Mo, time from Su
2710+
data[7] = (id == 0) ? 2 : tm_->tm_isdst + 2; // set DST and flag for ext. clock
26992711
if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS) {
27002712
data[6]++; // Junkers use 1-7;
27012713
data[7] = 0;

0 commit comments

Comments
 (0)