Skip to content

Commit

Permalink
switchtime settings not translated, junkers times
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Aug 29, 2024
1 parent 68e9452 commit 6122bc6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 33 deletions.
46 changes: 29 additions & 17 deletions src/devices/thermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,6 @@ void Thermostat::process_JunkersTimer(std::shared_ptr<const Telegram> telegram)
auto dhw = dhw_circuit(0, 1, true);
memcpy(&dhw->circswitchtime[telegram->offset], telegram->message_data, length);
}

}

// type 0xA3 - for external temp settings from the the RC* thermostats (e.g. RC35)
Expand Down Expand Up @@ -3307,12 +3306,14 @@ bool Thermostat::set_switchtime(const char * value, const uint16_t type_id) {
}
JsonDocument doc;
if (deserializeJson(doc, value) != DeserializationError::Ok) {
LOG_ERROR("json error");
return false;
}
uint8_t no = doc["id"] | 0;
uint8_t no = doc["no"] | 0;
std::string s_day = doc["day"] | "";
uint8_t day;
if (!Helpers::value2enum(s_day.c_str(), day, FL_(enum_dayOfWeek))) {
// LOG_ERROR("wrong day of week");
return false;
}
std::string s_mode = doc["mode"] | "";
Expand All @@ -3325,24 +3326,26 @@ bool Thermostat::set_switchtime(const char * value, const uint16_t type_id) {
if (Helpers::value2bool(s_mode.c_str(), b)) {
temp = b ? 1 : 0;
}
time /= 6;
time /= 10;
} else if ((model() == EMSdevice::EMS_DEVICE_FLAG_RC20) || (model() == EMSdevice::EMS_DEVICE_FLAG_RC30)) {
temp = s_mode[0] - '0'; // temp level as mode
time /= 6;
time /= 10;
} else if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS || model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS_OLD) {
time /= 4;
time /= 15;
temp = EMSESP::system_.fahrenheit() ? (temp - 32.0) / 1.8 : temp;
} else { // RC300
if (temp == 0) {
if (!Helpers::value2enum(s_mode.c_str(), temp, FL_(enum_switchmode))) {
LOG_ERROR("wrong switchmode");
return false;
}
temp--; // set on->0xFF, off to 0x00
} else {
temp = 2 * (EMSESP::system_.fahrenheit() ? (temp - 32.0) / 1.8 : temp);
}
time /= 4;
time /= 15;
}
if (s_mode == "not_set") {
day = 7;
temp = 7;
time = 0xFF;
}

Expand All @@ -3357,10 +3360,19 @@ bool Thermostat::set_switchtime(const char * value, const uint16_t type_id) {
}
write_command(type_id, no * 2, &data[0], 2, 0);
return true;
}
if (isRC300() || model() == EMSdevice::EMS_DEVICE_FLAG_RC100) {
uint8_t data[2] = {(uint8_t)time, temp};
} else if (model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS || model() == EMSdevice::EMS_DEVICE_FLAG_JUNKERS_OLD) {
uint8_t data[2] = {temp, (uint8_t)time};
if (day > 6 || no > 5) {
LOG_ERROR("day or no out of range");
return false;
}
write_command(type_id, day * 12 + no * 2, &data[0], 2, 0);
return true;

} else if (isRC300() || model() == EMSdevice::EMS_DEVICE_FLAG_RC100) {
uint8_t data[2] = {temp, (uint8_t)time};
if (day > 6 || no > 5) {
LOG_ERROR("day or no out of range");
return false;
}
write_command(type_id, day * 12 + no * 2, &data[0], 2, 0);
Expand All @@ -3376,10 +3388,10 @@ bool Thermostat::set_switchtime1(const char * value, const int8_t id) {
if (hc == nullptr) {
return false;
}
if (isRC300() && hc->switchProgMode == 0) {
return set_switchtime(value, timer_typeids[hc->hc()]);
} else {
if (isRC300() && hc->switchProgMode == 1) {
return set_switchtime(value, timer3_typeids[hc->hc()]);
} else { // all other thermostats
return set_switchtime(value, timer_typeids[hc->hc()]);
}
return false;
}
Expand All @@ -3390,10 +3402,10 @@ bool Thermostat::set_switchtime2(const char * value, const int8_t id) {
if (hc == nullptr) {
return false;
}
if (isRC300() && hc->switchProgMode == 0) {
return set_switchtime(value, timer2_typeids[hc->hc()]);
} else {
if (isRC300() && hc->switchProgMode == 1) {
return set_switchtime(value, timer4_typeids[hc->hc()]);
} else { // all other thermostats
return set_switchtime(value, timer2_typeids[hc->hc()]);
}
return false;
}
Expand Down
46 changes: 30 additions & 16 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1593,16 +1593,14 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {
case DeviceValueType::JSON:
json[type] = ("json");
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++) {
uint8_t * v_p = (uint8_t *)dv.value_p + 2 * i;
for (uint8_t no = 0; no < 42; no++) {
uint8_t * v_p = (uint8_t *)dv.value_p + 2 * no;
if (((*v_p) >> 5) != 7 && ((*v_p) & 0x07) != 7 && ((*v_p) & 0x18) == 0 && (*(v_p + 1) < 0x90)) {
// char n[3];
// auto data = json_val[Helpers::smallitoa(n, i)].to<JsonObject>();
auto data = json_val.add<JsonObject>();
data["id"] = i;
data["day"] = Helpers::translated_word(FL_(enum_dayOfWeek[(*v_p) >> 5]));
data["no"] = no;
data["day"] = FL_(enum_dayOfWeek[(*v_p) >> 5])[0]; // always en
// 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 (!strcmp(dv.options_single[0], "RC35")) {
Expand All @@ -1625,20 +1623,36 @@ void EMSdevice::get_value_json(JsonObject json, DeviceValue & dv) {
} else if (!strcmp(dv.options_single[0], "RC300")) {
auto json_val = json[value].to<JsonArray>();
for (uint8_t day = 0; day < 7; day++) {
for (uint8_t id = 0; id < 6; id++) {
uint8_t * v_p = ((uint8_t *)dv.value_p) + 12 * day + 2 * id;
for (uint8_t no = 0; no < 6; no++) {
uint8_t * v_p = ((uint8_t *)dv.value_p) + 12 * day + 2 * no;
if (*(v_p + 1) != 0xFF) {
auto data = json_val.add<JsonObject>();
data["day"] = Helpers::translated_word(FL_(enum_dayOfWeek[day]));
char time[6];
data["time"] = Helpers::render_clock(time, *(v_p + 1), DeviceValue::DV_NUMOP_MUL15);
uint8_t mode = *(v_p) + 1; // sets 0xFF to index 0
data["day"] = FL_(enum_dayOfWeek[day])[0]; // always en
// data["day"] = Helpers::translated_word(FL_(enum_dayOfWeek[day]));
data["time"] = Helpers::render_clock(val, *(v_p + 1), DeviceValue::DV_NUMOP_MUL15);
uint8_t mode = (*v_p) + 1; // sets 0xFF to index 0
if (mode < 5) {
data["mode"] = Helpers::translated_word(FL_(enum_switchmode[mode]));
data["mode"] = FL_(enum_switchmode[mode])[0]; // always en
// data["mode"] = Helpers::translated_word(FL_(enum_switchmode[mode]));
} else {
data["temp"] = (*(v_p)) / 2;
data["temp"] = serialized(Helpers::render_value(val, *v_p, 2, fahrenheit));
// data["temp"] = Helpers::transformNumFloat(*(v_p), 2, fahrenheit);
}
data["id"] = id;
data["no"] = no;
}
}
}
} else if (!strcmp(dv.options_single[0], "Junkers")) {
auto json_val = json[value].to<JsonArray>();
for (uint8_t day = 0; day < 7; day++) {
for (uint8_t no = 0; no < 6; no++) {
uint8_t * v_p = ((uint8_t *)dv.value_p) + 12 * day + 2 * no;
if (*(v_p + 1) != 0xFF) {
auto data = json_val.add<JsonObject>();
data["day"] = FL_(enum_dayOfWeek[day])[0]; // always en
data["time"] = Helpers::render_clock(val, *(v_p + 1), DeviceValue::DV_NUMOP_MUL15);
data["temp"] = serialized(Helpers::render_value(val, *v_p, 1, fahrenheit));
data["no"] = no;
}
}
}
Expand Down

0 comments on commit 6122bc6

Please sign in to comment.