Skip to content

Commit

Permalink
fix dhw read, more changes switchtimes
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Aug 18, 2024
1 parent aff3547 commit d345514
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 57 deletions.
57 changes: 27 additions & 30 deletions src/devices/thermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1209,10 +1209,10 @@ void Thermostat::process_RC300WWtemp(std::shared_ptr<const Telegram> telegram) {
void Thermostat::process_RC300WWmode(std::shared_ptr<const Telegram> telegram) {
uint8_t circuit = 0;
telegram->read_value(circuit, 0);
if (!circuit) {
auto dhw = dhw_circuit(telegram->type_id - 0x2F5, circuit, circuit != 0);
if (dhw == nullptr) {
return;
}
auto dhw = dhw_circuit(telegram->type_id - 0x2F5, circuit, true);
// circulation pump see: https://github.com/Th3M3/buderus_ems-wiki/blob/master/Einstellungen%20der%20Bedieneinheit%20RC310.md
has_update(telegram, dhw->wwCircPump_, 1); // FF=off, 0=on ?

Expand Down Expand Up @@ -3277,57 +3277,54 @@ bool Thermostat::set_switchtime(const char * value, const uint16_t type_id, char
if (value == nullptr) {
return false;
}
JsonDocument doc;
DeserializationError error = deserializeJson(doc, value);
if (error) {
JsonDocument doc;
if (deserializeJson(doc, value) != DeserializationError::Ok) {
return false;
}
uint8_t no = doc["id"] | 0;
const char * s_day = doc["day"];
uint8_t day;
if (!Helpers::value2enum(s_day, day, FL_(enum_dayOfWeek))) {
uint8_t no = doc["id"] | 0;
std::string s_day = doc["day"] | "";
uint8_t day;
if (!Helpers::value2enum(s_day.c_str(), day, FL_(enum_dayOfWeek))) {
return false;
}
const char * s_mode = doc["mode"];
const char * s_time = doc["time"];
uint8_t temp = doc["temp"];
uint16_t time = Helpers::string2minutes(s_time);
uint8_t on = 8; // invalid
std::string s_mode = doc["mode"] | "";
std::string s_time = doc["time"] | "";
uint8_t temp = doc["temp"] | 0;
uint16_t time = Helpers::string2minutes(s_time);

if (model() == EMSdevice::EMS_DEVICE_FLAG_RC35 || model() == EMSdevice::EMS_DEVICE_FLAG_RC30_N) {
bool b;
if (Helpers::value2bool(s_mode, b)) {
if (Helpers::value2bool(s_mode.c_str(), b)) {
temp = b ? 1 : 0;
}
time /= 6;
} else if ((model() == EMSdevice::EMS_DEVICE_FLAG_RC20) || (model() == EMSdevice::EMS_DEVICE_FLAG_RC30)) {
if (s_mode[0] == 'T') {
temp = s_mode[1] - '0';
} else {
temp = s_mode[0] - '0';
}
temp = s_mode[0] - '0'; // temp level as mode
time /= 6;
} else if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS || model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS_OLD) {
time /= 4;
} else { // RC300
if (temp == 0 && !Helpers::value2enum(s_mode, temp, FL_(enum_switchmode))) {
return false;
}
if (temp == 0) {
if (!Helpers::value2enum(s_mode.c_str(), temp, FL_(enum_switchmode))) {
return false;
}
temp--; // set on->0xFF, off to 0x00
}
time /= 4;
}
if (strncmp(s_mode, "not_set", 7) == 0) {
if (s_mode == "not_set") {
day = 7;
on = 7;
temp = 7;
time = 0xFF;
}

if (model() == EMSdevice::EMS_DEVICE_FLAG_RC35 || model() == EMSdevice::EMS_DEVICE_FLAG_RC30 || model() == EMSdevice::EMS_DEVICE_FLAG_RC20) {
uint8_t data[2] = {0xE7, 0x90}; // unset switchtime
if (day != 7 && on != 7 && time != 0xFF) {
data[0] = (day << 5) + on;
if (day != 7 && temp != 7 && time != 0xFF) {
data[0] = (day << 5) + temp;
data[1] = time;
}
if (no > 41 || day > 7 || on > 1) {
if (no > 41 || day > 7 || temp > 1) {
return false;
}
write_command(type_id, no * 2, &data[0], 2, 0);
Expand Down Expand Up @@ -4561,7 +4558,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
register_device_value(
tag, &hc->nighttemp, DeviceValueType::UINT8, DeviceValueNumOp::DV_NUMOP_DIV2, FL_(nighttemp2), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_nighttemp));
init_switchtime(hc->switchtime1, 84);
register_device_value(tag, &hc->switchtime1, DeviceValueType::JSON, FL_(rc35), FL_(switchtime), DeviceValueUOM::NONE, MAKE_CF_CB(set_switchtime1));
register_device_value(tag, &hc->switchtime1, DeviceValueType::JSON, FL_(rc30), FL_(switchtime), DeviceValueUOM::NONE, MAKE_CF_CB(set_switchtime1));
break;
case EMSdevice::EMS_DEVICE_FLAG_RC20_N:
register_device_value(tag, &hc->mode, DeviceValueType::ENUM, FL_(enum_mode3), FL_(mode), DeviceValueUOM::NONE, MAKE_CF_CB(set_mode));
Expand Down Expand Up @@ -4622,7 +4619,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
register_device_value(tag, &vacation[6], DeviceValueType::STRING, FL_(tpl_holidays), FL_(vacations7), DeviceValueUOM::NONE, MAKE_CF_CB(set_RC30Vacation7));
register_device_value(tag, &hc->program, DeviceValueType::ENUM, FL_(enum_progMode2), FL_(program), DeviceValueUOM::NONE, MAKE_CF_CB(set_program));
init_switchtime(hc->switchtime1, 84);
register_device_value(tag, &hc->switchtime1, DeviceValueType::JSON, FL_(rc35), FL_(switchtime1), DeviceValueUOM::NONE, MAKE_CF_CB(set_switchtime1));
register_device_value(tag, &hc->switchtime1, DeviceValueType::JSON, FL_(rc30), FL_(switchtime1), DeviceValueUOM::NONE, MAKE_CF_CB(set_switchtime1));
register_device_value(
tag, &hc->heatingtype, DeviceValueType::ENUM, FL_(enum_heatingtype), FL_(heatingtype), DeviceValueUOM::NONE, MAKE_CF_CB(set_heatingtype));
register_device_value(
Expand Down
4 changes: 1 addition & 3 deletions src/devices/thermostat.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ class Thermostat : public EMSdevice {
static uuid::log::Logger logger_;

static void init_switchtime(uint8_t * st, uint8_t len) {
for (uint8_t i = 0; i < len; i++) {
st[i] = 0xFF;
}
memset(st, 0xFF, len);
}

void register_device_values();
Expand Down
46 changes: 25 additions & 21 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,7 +1592,7 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {

case DeviceValueType::JSON:
json[type] = ("json");
if (!strcmp(dv.options_single[0], "RC35")) {
if (!strcmp(dv.options_single[0], "RC35") || !strcmp(dv.options_single[0], "RC30")) {
// Jauto json_val = json[value].to<JsonObject>();
auto json_val = json[value].to<JsonArray>();
for (uint8_t i = 0; i < 42; i++) {
Expand All @@ -1605,34 +1605,38 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {
data["day"] = Helpers::translated_word(FL_(enum_dayOfWeek[(*v_p) >> 5]));
char time[6];
data["time"] = Helpers::render_clock(time, *(v_p + 1), DeviceValue::DV_NUMOP_MUL10);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
data["mode"] = (*(v_p) & 1) ? 1 : 0;
} else if (EMSESP::system_.enum_format() == BOOL_FORMAT_TRUEFALSE) {
data["mode"] = (*(v_p) & 1) ? true : false;
} else { // if (dv.tag == DeviceValueTAG::TAG_DHW1) {
char b[12];
data["mode"] = Helpers::render_boolean(b, *(v_p) & 1);
// } else {
// data["mode"] = (*(v_p) & 1) ? Helpers::translated_word(FL_(day)) : Helpers::translated_word(FL_(night));
if (!strcmp(dv.options_single[0], "RC35")) {
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
data["mode"] = (*(v_p) & 1) ? 1 : 0;
} else if (EMSESP::system_.enum_format() == BOOL_FORMAT_TRUEFALSE) {
data["mode"] = (*(v_p) & 1) ? true : false;
} else {
char b[12];
data["mode"] = Helpers::render_boolean(b, *(v_p) & 1);
// } else {
// data["mode"] = (*(v_p) & 1) ? Helpers::translated_word(FL_(day)) : Helpers::translated_word(FL_(night));
}

} else {
data["mode"] = (*(v_p) & 7); // RC20/RC30 level, RC35 off/on
}
}
}
} else if (!strcmp(dv.options_single[0], "RC300")) {
auto json_val = json[value].to<JsonObject>();
for (uint8_t i = 0; i < 7; i++) {
auto dow = json_val[Helpers::translated_word(FL_(enum_dayOfWeek[i]))].to<JsonArray>();
for (uint8_t j = 0; j < 6; j++) {
auto data = dow.add<JsonObject>();
uint8_t * v_p = (uint8_t *)dv.value_p + 12 * i + 2 * j;
for (uint8_t day = 0; day < 7; day++) {
auto json_dow = json_val[Helpers::translated_word(FL_(enum_dayOfWeek[day]))].to<JsonArray>();
for (uint8_t id = 0; id < 6; id++) {
auto data = json_dow.add<JsonObject>();
uint8_t * v_p = (uint8_t *)dv.value_p + 12 * day + 2 * id;
if (*v_p != 0xFF) {
data["id"] = j;
data["day"] = Helpers::translated_word(FL_(enum_dayOfWeek[i]));
data["id"] = id;
data["day"] = Helpers::translated_word(FL_(enum_dayOfWeek[day]));
char time[6];
data["time"] = Helpers::render_clock(time, *(v_p), DeviceValue::DV_NUMOP_MUL15);
uint8_t mode = *(v_p + 1) + 1; // sets 0xFF to index 0
const char * modes[] = {"on", "off", "eco/low", "high", "comfort"};
data["time"] = Helpers::render_clock(time, *(v_p), DeviceValue::DV_NUMOP_MUL15);
uint8_t mode = *(v_p + 1) + 1; // sets 0xFF to index 0
if (mode < 5) {
data["mode"] = modes[mode];
data["mode"] = Helpers::translated_word(FL_(enum_switchmode[mode]));
} else {
data["temp"] = (*(v_p + 1)) / 2;
}
Expand Down
4 changes: 3 additions & 1 deletion src/helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ std::string Helpers::data_to_hex(const uint8_t * data, const uint8_t length) {
}

char str[length * 3];
memset(str, 0, length * sizeof(char));
memset(str, 0, sizeof(str));

char buffer[4];
char * p = &str[0];
Expand Down Expand Up @@ -848,6 +848,8 @@ uint16_t Helpers::string2minutes(const std::string & str) {

if (state == 1 && tmp < 60) {
return res + tmp;
} else if (state == 0) { // only on number in minutes
return tmp;
} else {
return 0; // Or if we were not, something is wrong in the given string
}
Expand Down
3 changes: 2 additions & 1 deletion src/locale_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ MAKE_NOTRANSLATION(progd, "prog d")
MAKE_NOTRANSLATION(proge, "prog e")
MAKE_NOTRANSLATION(progf, "prog f")
MAKE_NOTRANSLATION(rc35, "RC35")
MAKE_NOTRANSLATION(rc30, "RC30")
MAKE_NOTRANSLATION(rc300, "RC300")
MAKE_NOTRANSLATION(0kW, "0 kW")
MAKE_NOTRANSLATION(2kW, "2 kW")
Expand Down Expand Up @@ -354,7 +355,7 @@ MAKE_ENUM(enum_control1, FL_(rc310), FL_(rc200), FL_(rc100), FL_(rc100h), FL_(tc
MAKE_ENUM(enum_control2, FL_(off), FL_(dash), FL_(rc100), FL_(rc100h), FL_(dash), FL_(rc120rf), FL_(rc220), FL_(single)) // BC400
MAKE_ENUM(enum_control3, FL_(off), FL_(dash), FL_(cr10), FL_(cr10h), FL_(dash), FL_(cr20rf), FL_(rt800), FL_(single)) // UI800

MAKE_ENUM(enum_switchmode, FL_(off), FL_(eco), FL_(comfort), FL_(heat))
MAKE_ENUM(enum_switchmode, FL_(on), FL_(off), FL_(eco), FL_(high), FL_(comfort))
MAKE_ENUM(enum_switchProgMode, FL_(level), FL_(absolute))

MAKE_ENUM(enum_dayOfWeek, FL_(day_mo), FL_(day_tu), FL_(day_we), FL_(day_th), FL_(day_fr), FL_(day_sa), FL_(day_su), FL_(all))
Expand Down
2 changes: 1 addition & 1 deletion src/version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define EMSESP_APP_VERSION "3.7.0-dev.31"
#define EMSESP_APP_VERSION "3.7.0-test.31"

0 comments on commit d345514

Please sign in to comment.