fix again for #828

This commit is contained in:
Proddy
2022-12-30 15:36:25 +01:00
parent 8eeebb0cef
commit 263c011a7b
3 changed files with 185 additions and 189 deletions

View File

@@ -26,8 +26,6 @@ uuid::log::Logger Thermostat::logger_{F_(thermostat), uuid::log::Facility::CONSO
Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_id, const char * version, const char * name, uint8_t flags, uint8_t brand)
: EMSdevice(device_type, device_id, product_id, version, name, flags, brand) {
uint8_t model = this->model();
// RF remote sensor seen at 0x40, maybe this is also for different hc with id 0x40 - 0x47? emsesp.cpp maps only 0x40
if (device_id >= 0x40 && device_id <= 0x47) {
register_telegram_type(0x0435, "RFTemp", false, MAKE_PF_CB(process_RemoteTemp));
@@ -48,6 +46,9 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
register_telegram_type(0xA2, "RCError", false, MAKE_PF_CB(process_RCError));
register_telegram_type(0x12, "RCErrorMessage", false, MAKE_PF_CB(process_RCErrorMessage));
register_telegram_type(0x13, "RCErrorMessage2", false, MAKE_PF_CB(process_RCErrorMessage));
uint8_t model = this->model();
// RC10
if (model == EMSdevice::EMS_DEVICE_FLAG_RC10) {
monitor_typeids = {0xB1};
@@ -194,11 +195,6 @@ Thermostat::Thermostat(uint8_t device_type, uint8_t device_id, uint8_t product_i
EMSESP::send_read_request(EMS_TYPE_RCTime, device_id);
EMSESP::send_read_request(0x12, device_id); // read last error (only published on errors)
EMSESP::send_read_request(0xA2, device_id); // read errorCode (only published on errors)
#if defined(EMSESP_STANDALONE_DUMP)
// if we're just dumping out values, create a single dummy hc
register_device_values_hc(std::make_shared<emsesp::Thermostat::HeatingCircuit>(1, model)); // hc=1
#endif
}
// returns the heating circuit object based on the hc number
@@ -3389,6 +3385,7 @@ void Thermostat::register_device_values() {
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &errorCode_, DeviceValueType::STRING, FL_(errorCode), DeviceValueUOM::NONE);
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &lastCode_, DeviceValueType::STRING, FL_(lastCode), DeviceValueUOM::NONE);
switch (this->model()) {
case EMS_DEVICE_FLAG_RC100:
case EMS_DEVICE_FLAG_RC300:
@@ -4013,6 +4010,11 @@ void Thermostat::register_device_values() {
register_device_value(DeviceValueTAG::TAG_DEVICE_DATA, &dateTime_, DeviceValueType::STRING, FL_(dateTime), DeviceValueUOM::NONE); // can't set datetime
break;
}
#if defined(EMSESP_STANDALONE_DUMP)
// if we're just dumping out values, create a single dummy hc
register_device_values_hc(std::make_shared<emsesp::Thermostat::HeatingCircuit>(1, this->model())); // hc=1
#endif
}
// registers the values for a heating circuit
@@ -4036,6 +4038,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
seltemp_divider = DeviceValueNumOp::DV_NUMOP_DIV2;
roomtemp_divider = DeviceValueNumOp::DV_NUMOP_DIV10;
}
if (has_flags(EMS_DEVICE_FLAG_NO_WRITE)) {
register_device_value(tag, &hc->selTemp, DeviceValueType::SHORT, seltemp_divider, FL_(selRoomTemp), DeviceValueUOM::DEGREES);
} else {

View File

@@ -431,17 +431,6 @@ void EMSdevice::add_device_value(uint8_t tag,
const cmd_function_p f,
int16_t min,
uint16_t max) {
bool has_cmd = (f != nullptr);
auto short_name = name[0];
const char * const * fullname;
if (Helpers::count_items(name) == 1) {
fullname = nullptr; // no translations available, use empty to prevent crash
} else {
fullname = &name[1]; // translations start at index 1
}
// initialize the device value depending on it's type
// ignoring DeviceValueType::CMD and DeviceValueType::TIME
if (type == DeviceValueType::STRING) {
@@ -462,11 +451,18 @@ void EMSdevice::add_device_value(uint8_t tag,
*(uint8_t *)(value_p) = EMS_VALUE_DEFAULT_ENUM; // enums behave as uint8_t
}
// determine state
uint8_t state = DeviceValueState::DV_DEFAULT;
uint8_t state = DeviceValueState::DV_DEFAULT; // determine state
std::string custom_fullname = std::string(""); // custom fullname
auto short_name = name[0]; // entity name
bool has_cmd = (f != nullptr); // is it a command?
// custom fullname
std::string custom_fullname = std::string("");
// get fullname, getting translation if it exists
const char * const * fullname;
if (Helpers::count_items(name) == 1) {
fullname = nullptr; // no translations available, use empty to prevent crash
} else {
fullname = &name[1]; // translations start at index 1
}
// scan through customizations to see if it's on the exclusion list by matching the productID and deviceID
EMSESP::webCustomizationService.read([&](WebCustomization & settings) {
@@ -506,10 +502,7 @@ void EMSdevice::add_device_value(uint8_t tag,
device_type_, tag, value_p, type, options, options_single, numeric_operator, short_name, fullname, custom_fullname, uom, has_cmd, min, max, state);
// add a new command if it has a function attached
if (!has_cmd) {
return;
}
if (has_cmd) {
uint8_t flags = CommandFlag::ADMIN_ONLY; // executing commands require admin privileges
if (tag >= DeviceValueTAG::TAG_HC1 && tag <= DeviceValueTAG::TAG_HC8) {
@@ -523,6 +516,7 @@ void EMSdevice::add_device_value(uint8_t tag,
// add the command to our library
Command::add(device_type_, device_id_, short_name, f, fullname, flags);
}
}
// single list of options
void EMSdevice::register_device_value(uint8_t tag,
@@ -1069,10 +1063,7 @@ void EMSdevice::getCustomEntities(std::vector<std::string> & entity_ids) {
// format is: device name,device type,product id,shortname,fullname,type [options...] \\| (min/max),uom,writeable,discovery entityid v3.4, discovery entityid
void EMSdevice::dump_value_info() {
for (auto & dv : devicevalues_) {
if (dv.fullname == nullptr) {
break; // ignore entities that don't have a fullname, like the thermostat climate thingy
}
if (dv.fullname != nullptr) {
Serial.print(name_);
Serial.print(',');
Serial.print(device_type_name().c_str());
@@ -1153,7 +1144,6 @@ void EMSdevice::dump_value_info() {
Serial.print(dv_set_max);
Serial.print(")");
}
Serial.print(",");
// uom
@@ -1174,6 +1164,7 @@ void EMSdevice::dump_value_info() {
char entityid[500];
char entity_name[100];
for (uint8_t count = 0; count < 2; count++) {
if (count) {
// new name, comes as last
@@ -1231,6 +1222,7 @@ void EMSdevice::dump_value_info() {
Serial.println();
}
}
}
#endif
// builds json for a specific device value / entity

View File

@@ -313,7 +313,8 @@ void EMSESP::show_ems(uuid::console::Shell & shell) {
void EMSESP::dump_all_values(uuid::console::Shell & shell) {
Serial.println("---- CSV START ----"); // marker use by py script
// add header for CSV
Serial.print("device name,device type,product id,shortname,fullname,type [options...] \\| (min/max),uom,writeable,discovery entityid v3.4, discovery entityid");
Serial.print(
"device name,device type,product id,shortname,fullname,type [options...] \\| (min/max),uom,writeable,discovery entityid v3.4, discovery entityid");
Serial.println();
for (const auto & device_class : EMSFactory::device_handlers()) {