mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
factor for charge duration
This commit is contained in:
@@ -1383,11 +1383,12 @@ bool Thermostat::set_wwcharge(const char * value, const int8_t id) {
|
||||
|
||||
// Set ww charge duration in steps of 15 min, ems+
|
||||
bool Thermostat::set_wwchargeduration(const char * value, const int8_t id) {
|
||||
uint8_t t = 0xFF;
|
||||
if (!Helpers::value2enum(value, t, FL_(enum_wwChargeDuration))) {
|
||||
int t = 0xFF;
|
||||
if (!Helpers::value2number(value, t)) {
|
||||
LOG_WARNING(F("Set warm water charge duration: Invalid value"));
|
||||
return false;
|
||||
}
|
||||
t = (t + 8) / 15;
|
||||
LOG_INFO(F("Setting warm water charge duration to %d min"), t * 15);
|
||||
write_command(0x2F5, 10, t, 0x02F5);
|
||||
return true;
|
||||
@@ -2420,10 +2421,10 @@ void Thermostat::register_device_values() {
|
||||
TAG_THERMOSTAT_DATA, &wwCircMode_, DeviceValueType::ENUM, FL_(enum_wwCircMode), FL_(wwCircMode), DeviceValueUOM::LIST, MAKE_CF_CB(set_wwcircmode));
|
||||
register_device_value(TAG_THERMOSTAT_DATA,
|
||||
&wwChargeDuration_,
|
||||
DeviceValueType::ENUM,
|
||||
FL_(enum_wwChargeDuration),
|
||||
DeviceValueType::UINT,
|
||||
FL_(mul15),
|
||||
FL_(wwChargeDuration),
|
||||
DeviceValueUOM::LIST,
|
||||
DeviceValueUOM::MINUTES,
|
||||
MAKE_CF_CB(set_wwchargeduration));
|
||||
register_device_value(TAG_THERMOSTAT_DATA, &wwCharge_, DeviceValueType::BOOL, nullptr, FL_(wwCharge), DeviceValueUOM::BOOLEAN, MAKE_CF_CB(set_wwcharge));
|
||||
register_device_value(TAG_THERMOSTAT_DATA, &wwExtra1_, DeviceValueType::UINT, nullptr, FL_(wwExtra1), DeviceValueUOM::DEGREES);
|
||||
|
||||
@@ -603,27 +603,36 @@ void EMSdevice::generate_values_json_web(JsonObject & json) {
|
||||
// If a divider is specified, do the division to 2 decimals places and send back as double/float
|
||||
// otherwise force as an integer whole
|
||||
// the nested if's is necessary due to the way the ArduinoJson templates are pre-processed by the compiler
|
||||
uint8_t divider = (dv.options_size == 1) ? Helpers::atoint(uuid::read_flash_string(dv.options[0]).c_str()) : 0;
|
||||
uint8_t divider = 0;
|
||||
uint8_t factor = 1;
|
||||
if (dv.options_size == 1) {
|
||||
const char * s = uuid::read_flash_string(dv.options[0]).c_str();
|
||||
if (s[0] == '*') {
|
||||
factor = Helpers::atoint(&s[1]);
|
||||
} else {
|
||||
divider = Helpers::atoint(s);
|
||||
}
|
||||
}
|
||||
|
||||
if ((dv.type == DeviceValueType::INT) && Helpers::hasValue(*(int8_t *)(dv.value_p))) {
|
||||
obj = data.createNestedObject();
|
||||
obj["v"] = (divider) ? Helpers::round2(*(int8_t *)(dv.value_p), divider) : *(int8_t *)(dv.value_p);
|
||||
obj["v"] = (divider) ? Helpers::round2(*(int8_t *)(dv.value_p), divider) : *(int8_t *)(dv.value_p) * factor;
|
||||
} else if ((dv.type == DeviceValueType::UINT) && Helpers::hasValue(*(uint8_t *)(dv.value_p))) {
|
||||
obj = data.createNestedObject();
|
||||
obj["v"] = (divider) ? Helpers::round2(*(uint8_t *)(dv.value_p), divider) : *(uint8_t *)(dv.value_p);
|
||||
obj["v"] = (divider) ? Helpers::round2(*(uint8_t *)(dv.value_p), divider) : *(uint8_t *)(dv.value_p) * factor;
|
||||
} else if ((dv.type == DeviceValueType::SHORT) && Helpers::hasValue(*(int16_t *)(dv.value_p))) {
|
||||
obj = data.createNestedObject();
|
||||
obj["v"] = (divider) ? Helpers::round2(*(int16_t *)(dv.value_p), divider) : *(int16_t *)(dv.value_p);
|
||||
obj["v"] = (divider) ? Helpers::round2(*(int16_t *)(dv.value_p), divider) : *(int16_t *)(dv.value_p) * factor;
|
||||
} else if ((dv.type == DeviceValueType::USHORT) && Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
|
||||
obj = data.createNestedObject();
|
||||
obj["v"] = (divider) ? Helpers::round2(*(uint16_t *)(dv.value_p), divider) : *(uint16_t *)(dv.value_p);
|
||||
obj["v"] = (divider) ? Helpers::round2(*(uint16_t *)(dv.value_p), divider) : *(uint16_t *)(dv.value_p) * factor;
|
||||
} else if ((dv.type == DeviceValueType::ULONG) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
obj = data.createNestedObject();
|
||||
obj["v"] = (divider) ? Helpers::round2(*(uint32_t *)(dv.value_p), divider) : *(uint32_t *)(dv.value_p);
|
||||
obj["v"] = divider ? Helpers::round2(*(uint32_t *)(dv.value_p), divider) : *(uint32_t *)(dv.value_p) * factor;
|
||||
} else if ((dv.type == DeviceValueType::TIME) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
uint32_t time_value = *(uint32_t *)(dv.value_p);
|
||||
obj = data.createNestedObject();
|
||||
obj["v"] = (divider) ? time_value / divider : time_value; // sometimes we need to divide by 60
|
||||
obj["v"] = (divider > 0) ? time_value / divider : time_value * factor; // sometimes we need to divide by 60
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,7 +693,16 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
// search device value with this tag
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (strcmp(cmd, Helpers::toLower(uuid::read_flash_string(dv.short_name)).c_str()) == 0 && (tag <= 0 || tag == dv.tag)) {
|
||||
uint8_t divider = (dv.options_size == 1) ? Helpers::atoint(uuid::read_flash_string(dv.options[0]).c_str()) : 0;
|
||||
uint8_t divider = 0;
|
||||
uint8_t factor = 1;
|
||||
if (dv.options_size == 1) {
|
||||
const char * s = uuid::read_flash_string(dv.options[0]).c_str();
|
||||
if (s[0] == '*') {
|
||||
factor = Helpers::atoint(&s[1]);
|
||||
} else {
|
||||
divider = Helpers::atoint(s);
|
||||
}
|
||||
}
|
||||
const char * type = "type";
|
||||
const char * min = "min";
|
||||
const char * max = "max";
|
||||
@@ -726,7 +744,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::USHORT:
|
||||
if (Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
|
||||
json[value] = Helpers::round2(*(uint16_t *)(dv.value_p), divider);
|
||||
json[value] = divider ? Helpers::round2(*(uint16_t *)(dv.value_p), divider) : *(uint16_t *)(dv.value_p) * factor;
|
||||
}
|
||||
json[type] = F_(number);
|
||||
json[min] = 0;
|
||||
@@ -735,7 +753,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::UINT:
|
||||
if (Helpers::hasValue(*(uint8_t *)(dv.value_p))) {
|
||||
json[value] = Helpers::round2(*(uint8_t *)(dv.value_p), divider);
|
||||
json[value] = divider ? Helpers::round2(*(uint8_t *)(dv.value_p), divider) : *(uint8_t *)(dv.value_p) * factor;
|
||||
}
|
||||
json[type] = F_(number);
|
||||
json[min] = 0;
|
||||
@@ -748,7 +766,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::SHORT:
|
||||
if (Helpers::hasValue(*(int16_t *)(dv.value_p))) {
|
||||
json[value] = Helpers::round2(*(int16_t *)(dv.value_p), divider);
|
||||
json[value] = divider ? Helpers::round2(*(int16_t *)(dv.value_p), divider) : *(int16_t *)(dv.value_p) * factor;
|
||||
}
|
||||
json[type] = F_(number);
|
||||
json[min] = divider ? -EMS_VALUE_SHORT_NOTSET / divider : -EMS_VALUE_SHORT_NOTSET;
|
||||
@@ -757,7 +775,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::INT:
|
||||
if (Helpers::hasValue(*(int8_t *)(dv.value_p))) {
|
||||
json[value] = Helpers::round2(*(int8_t *)(dv.value_p), divider);
|
||||
json[value] = divider ? Helpers::round2(*(int8_t *)(dv.value_p), divider) : *(int8_t *)(dv.value_p) * factor;
|
||||
}
|
||||
json[type] = F_(number);
|
||||
if (dv.uom == DeviceValueUOM::PERCENT) {
|
||||
@@ -771,7 +789,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::ULONG:
|
||||
if (Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
json[value] = Helpers::round2(*(uint32_t *)(dv.value_p), divider);
|
||||
json[value] = divider ? Helpers::round2(*(uint32_t *)(dv.value_p), divider) : *(uint32_t *)(dv.value_p) * factor;
|
||||
}
|
||||
json[type] = F_(number);
|
||||
json[min] = 0;
|
||||
@@ -797,7 +815,7 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t
|
||||
|
||||
case DeviceValueType::TIME:
|
||||
if (Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
json[value] = (divider) ? *(uint32_t *)(dv.value_p) / divider : *(uint32_t *)(dv.value_p);
|
||||
json[value] = (divider) ? *(uint32_t *)(dv.value_p) / divider : *(uint32_t *)(dv.value_p) * factor;
|
||||
}
|
||||
json[type] = F_(number);
|
||||
json[min] = 0;
|
||||
@@ -918,47 +936,56 @@ bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter
|
||||
// If a divider is specified, do the division to 2 decimals places and send back as double/float
|
||||
// otherwise force as an integer whole
|
||||
// the nested if's is necessary due to the way the ArduinoJson templates are pre-processed by the compiler
|
||||
uint8_t divider = (dv.options_size == 1) ? Helpers::atoint(uuid::read_flash_string(dv.options[0]).c_str()) : 0;
|
||||
uint8_t divider = 0;
|
||||
uint8_t factor = 1;
|
||||
if (dv.options_size == 1) {
|
||||
const char * s = uuid::read_flash_string(dv.options[0]).c_str();
|
||||
if (s[0] == '*') {
|
||||
factor = Helpers::atoint(&s[1]);
|
||||
} else {
|
||||
divider = Helpers::atoint(s);
|
||||
}
|
||||
}
|
||||
|
||||
// INT
|
||||
if ((dv.type == DeviceValueType::INT) && Helpers::hasValue(*(int8_t *)(dv.value_p))) {
|
||||
if (divider) {
|
||||
json[name] = Helpers::round2(*(int8_t *)(dv.value_p), divider);
|
||||
} else {
|
||||
json[name] = *(int8_t *)(dv.value_p);
|
||||
json[name] = *(int8_t *)(dv.value_p) * factor;
|
||||
}
|
||||
has_value = true;
|
||||
} else if ((dv.type == DeviceValueType::UINT) && Helpers::hasValue(*(uint8_t *)(dv.value_p))) {
|
||||
if (divider) {
|
||||
json[name] = Helpers::round2(*(uint8_t *)(dv.value_p), divider);
|
||||
} else {
|
||||
json[name] = *(uint8_t *)(dv.value_p);
|
||||
json[name] = *(uint8_t *)(dv.value_p) * factor;
|
||||
}
|
||||
has_value = true;
|
||||
} else if ((dv.type == DeviceValueType::SHORT) && Helpers::hasValue(*(int16_t *)(dv.value_p))) {
|
||||
if (divider) {
|
||||
json[name] = Helpers::round2(*(int16_t *)(dv.value_p), divider);
|
||||
} else {
|
||||
json[name] = *(int16_t *)(dv.value_p);
|
||||
json[name] = *(int16_t *)(dv.value_p) * factor;
|
||||
}
|
||||
has_value = true;
|
||||
} else if ((dv.type == DeviceValueType::USHORT) && Helpers::hasValue(*(uint16_t *)(dv.value_p))) {
|
||||
if (divider) {
|
||||
json[name] = Helpers::round2(*(uint16_t *)(dv.value_p), divider);
|
||||
} else {
|
||||
json[name] = *(uint16_t *)(dv.value_p);
|
||||
json[name] = *(uint16_t *)(dv.value_p) * factor;
|
||||
}
|
||||
has_value = true;
|
||||
} else if ((dv.type == DeviceValueType::ULONG) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
if (divider) {
|
||||
json[name] = Helpers::round2(*(uint32_t *)(dv.value_p), divider);
|
||||
} else {
|
||||
json[name] = *(uint32_t *)(dv.value_p);
|
||||
json[name] = *(uint32_t *)(dv.value_p) * factor;
|
||||
}
|
||||
has_value = true;
|
||||
} else if ((dv.type == DeviceValueType::TIME) && Helpers::hasValue(*(uint32_t *)(dv.value_p))) {
|
||||
uint32_t time_value = *(uint32_t *)(dv.value_p);
|
||||
time_value = (divider) ? time_value / divider : time_value; // sometimes we need to divide by 60
|
||||
time_value = (divider) ? time_value / divider : time_value * factor; // sometimes we need to divide by 60
|
||||
if (console) {
|
||||
char time_s[40];
|
||||
snprintf_P(time_s, sizeof(time_s), "%d days %d hours %d minutes", (time_value / 1440), ((time_value % 1440) / 60), (time_value % 60));
|
||||
|
||||
@@ -350,7 +350,7 @@ uint32_t Helpers::hextoint(const char * hex) {
|
||||
// quick char to long
|
||||
uint16_t Helpers::atoint(const char * value) {
|
||||
unsigned int x = 0;
|
||||
while (*value != '\0') {
|
||||
while (*value >= '0' && *value <= '9') {
|
||||
x = (x * 10) + (*value - '0');
|
||||
++value;
|
||||
}
|
||||
|
||||
@@ -162,6 +162,8 @@ MAKE_PSTR_LIST(div2, F_(2))
|
||||
MAKE_PSTR_LIST(div10, F_(10))
|
||||
MAKE_PSTR_LIST(div100, F_(100))
|
||||
MAKE_PSTR_LIST(div60, F_(60))
|
||||
MAKE_PSTR_LIST(mul10, F("*10"))
|
||||
MAKE_PSTR_LIST(mul15, F("*15"))
|
||||
|
||||
// Unit Of Measurement mapping - maps to DeviceValueUOM_s in emsdevice.cpp
|
||||
// uom - also used with HA see https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L384
|
||||
@@ -352,7 +354,7 @@ MAKE_PSTR_LIST(enum_control, F_(off), F_(rc20), F_(rc3x))
|
||||
|
||||
MAKE_PSTR_LIST(enum_wwProgMode, F("std prog"), F_(own_prog))
|
||||
MAKE_PSTR_LIST(enum_dayOfWeek, F("mo"), F("tu"), F("we"), F("th"), F("fr"), F("sa"), F("so"), F("all"))
|
||||
MAKE_PSTR_LIST(enum_wwChargeDuration, F_(off), F("15min"), F("30min"), F("45min"), F("60min"), F("75min"), F("90min"), F("105min"), F("120min"))
|
||||
// MAKE_PSTR_LIST(enum_wwChargeDuration, F_(off), F("15min"), F("30min"), F("45min"), F("60min"), F("75min"), F("90min"), F("105min"), F("120min"))
|
||||
|
||||
// solar list
|
||||
MAKE_PSTR_LIST(enum_solarmode, F_(constant), F("pwm"), F("analog"))
|
||||
|
||||
Reference in New Issue
Block a user