Skip to content

Commit

Permalink
fastheatup as percent-value, enlarge parse-buffer #122
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Sep 21, 2021
1 parent 769301c commit fcc2c0b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
- MQTT reconnecting after WiFi reconnect [#99](https://github.com/emsesp/EMS-ESP32/issues/99)
- Manually Controlling Solar Circuit [#107](https://github.com/emsesp/EMS-ESP32/issues/107)
- Fix thermostat commands not defaulting to the master thermostat [#110](https://github.com/emsesp/EMS-ESP32/issues/110)
- enlarge parse-buffer for long names like `cylinderpumpmodulation`

## Changed

- Syslog BOM only for utf-8 messages [#91](https://github.com/emsesp/EMS-ESP32/issues/91)
- Check for KM200 by device-id 0x48, remove tx-delay[#90](https://github.com/emsesp/EMS-ESP32/issues/90)
- rename `fastheatupfactor` to `fastheatup` and add percent [#122]
12 changes: 6 additions & 6 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ std::vector<Command::CmdFunction> Command::cmdfunctions_;
// returns 0 if the command errored, 1 (TRUE) if ok, 2 if not found, 3 if error or 4 if not allowed
uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * value, bool authenticated, const int8_t id) {
int8_t id_new = id;
char cmd_new[20] = {'\0'};
strlcpy(cmd_new, cmd, 20);
char cmd_new[30] = {'\0'};
strlcpy(cmd_new, cmd, sizeof(cmd_new));

// find the command
auto cf = find_command(device_type, cmd_new, id_new);
Expand Down Expand Up @@ -64,8 +64,8 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
// returns 0 if the command errored, 1 (TRUE) if ok, 2 if not found, 3 if error or 4 if not allowed
uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * value, bool authenticated, const int8_t id, JsonObject & json) {
int8_t id_new = id;
char cmd_new[20] = {'\0'};
strlcpy(cmd_new, cmd, 20);
char cmd_new[30] = {'\0'};
strlcpy(cmd_new, cmd, sizeof(cmd_new));

auto cf = find_command(device_type, cmd_new, id_new);

Expand Down Expand Up @@ -159,7 +159,7 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, char * c

// empty command after processing prefix is info
if (cmd[0] == '\0') {
strlcpy(cmd, "info", 20);
strcpy(cmd, "info");

This comment has been minimized.

Copy link
@proddy

proddy Sep 21, 2021

Contributor

prefer strlcpy to be memory safe. can it be replaced using sizeof(cmd) ?

This comment has been minimized.

Copy link
@MichaelDvP

MichaelDvP Sep 21, 2021

Author Contributor

in this case "info" is fixed length, no need to check. I agree when copying variables.

}

return find_command(device_type, cmd);
Expand Down Expand Up @@ -209,7 +209,7 @@ Command::CmdFunction * Command::find_command(const uint8_t device_type, const ch
}

// convert cmd to lowercase and compare
char lowerCmd[20];
char lowerCmd[30];
strlcpy(lowerCmd, cmd, sizeof(lowerCmd));
for (char * p = lowerCmd; *p; p++) {
*p = tolower(*p);
Expand Down
12 changes: 6 additions & 6 deletions src/devices/thermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ void Thermostat::process_RC300Summer(std::shared_ptr<const Telegram> telegram) {
}

has_update(telegram->read_value(hc->minflowtemp, 8));
has_update(telegram->read_value(hc->fastHeatupFactor, 10));
has_update(telegram->read_value(hc->fastHeatup, 10));
}

// types 0x471 ff
Expand Down Expand Up @@ -1849,19 +1849,19 @@ bool Thermostat::set_summermode(const char * value, const int8_t id) {
}

// Set fastheatupfactor, ems+
bool Thermostat::set_fastheatupfactor(const char * value, const int8_t id) {
bool Thermostat::set_fastheatup(const char * value, const int8_t id) {
uint8_t hc_num = (id == -1) ? AUTO_HEATING_CIRCUIT : id;
std::shared_ptr<Thermostat::HeatingCircuit> hc = heating_circuit(hc_num);
if (hc == nullptr) {
LOG_WARNING(F("Setfast heatup factor: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, device_id());
LOG_WARNING(F("Set fast heatup: Heating Circuit %d not found or activated for device ID 0x%02X"), hc_num, device_id());
return false;
}
int set = 0;
if (!Helpers::value2number(value, set)) {
LOG_WARNING(F("Set fast heatup factor: Invalid value"));
LOG_WARNING(F("Set fast heatup: Invalid value"));
return false;
}
LOG_INFO(F("Setting fast heatup factor to %d"), set);
LOG_INFO(F("Setting fast heatup to %d%%"), set);
write_command(summer_typeids[hc->hc_num() - 1], 10, set, summer_typeids[hc->hc_num() - 1]);
return true;
}
Expand Down Expand Up @@ -2625,7 +2625,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
register_device_value(tag, &hc->program, DeviceValueType::UINT, nullptr, FL_(program), DeviceValueUOM::NONE, MAKE_CF_CB(set_program));
register_device_value(tag, &hc->tempautotemp, DeviceValueType::UINT, FL_(div2), FL_(tempautotemp), DeviceValueUOM::DEGREES, MAKE_CF_CB(set_tempautotemp));
register_device_value(
tag, &hc->fastHeatupFactor, DeviceValueType::UINT, nullptr, FL_(fastheatupfactor), DeviceValueUOM::NONE, MAKE_CF_CB(set_fastheatupfactor));
tag, &hc->fastHeatup, DeviceValueType::UINT, nullptr, FL_(fastheatup), DeviceValueUOM::PERCENT, MAKE_CF_CB(set_fastheatup));
break;
case EMS_DEVICE_FLAG_CRF:
register_device_value(tag, &hc->mode, DeviceValueType::ENUM, FL_(enum_mode5), FL_(mode), DeviceValueUOM::LIST);
Expand Down
4 changes: 2 additions & 2 deletions src/devices/thermostat.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Thermostat : public EMSdevice {
uint8_t party;
int8_t noreducetemp; // signed -20°C to +10°C
uint8_t wwprio;
uint8_t fastHeatupFactor;
uint8_t fastHeatup;

uint8_t hc_num() const {
return hc_num_;
Expand Down Expand Up @@ -346,7 +346,7 @@ class Thermostat : public EMSdevice {
bool set_program(const char * value, const int8_t id);
bool set_controlmode(const char * value, const int8_t id);
bool set_wwprio(const char * value, const int8_t id);
bool set_fastheatupfactor(const char * value, const int8_t id);
bool set_fastheatup(const char * value, const int8_t id);

// set functions - these don't use the id/hc, the parameters are ignored
bool set_wwmode(const char * value, const int8_t id);
Expand Down
2 changes: 1 addition & 1 deletion src/locale_EN.h
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ MAKE_PSTR_LIST(setpoint_roomTemp, F("seltemp"), F("selected room temperature"))
MAKE_PSTR_LIST(curr_roomTemp, F("currtemp"), F("current room temperature"))
MAKE_PSTR_LIST(mode, F("mode"), F("mode"))
MAKE_PSTR_LIST(modetype, F("modetype"), F("mode type"))
MAKE_PSTR_LIST(fastheatupfactor, F("fastheatupfactor"), F("fast heatup factor"))
MAKE_PSTR_LIST(fastheatup, F("fastheatup"), F("fast heatup"))
MAKE_PSTR_LIST(daytemp, F("daytemp"), F("day temperature"))
MAKE_PSTR_LIST(heattemp, F("heattemp"), F("heat temperature"))
MAKE_PSTR_LIST(nighttemp, F("nighttemp"), F("night temperature"))
Expand Down

0 comments on commit fcc2c0b

Please sign in to comment.