mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2026-04-02 15:06:32 +03:00
customze device brand #2784
This commit is contained in:
@@ -72,6 +72,21 @@ const char * EMSdevice::tag_to_mqtt(int8_t tag) {
|
||||
return (DeviceValue::DeviceValueTAG_mqtt[tag > DeviceValue::NUM_TAGS ? 0 : tag]);
|
||||
}
|
||||
|
||||
uint8_t EMSdevice::tag_to_flag(const uint8_t tag) {
|
||||
if (tag >= DeviceValueTAG::TAG_HC1 && tag <= DeviceValueTAG::TAG_HC8) {
|
||||
return CommandFlag::CMD_FLAG_HC;
|
||||
} else if (tag >= DeviceValueTAG::TAG_DHW1 && tag <= DeviceValueTAG::TAG_DHW10) {
|
||||
return CommandFlag::CMD_FLAG_DHW;
|
||||
} else if (tag >= DeviceValueTAG::TAG_HS1 && tag <= DeviceValueTAG::TAG_HS16) {
|
||||
return CommandFlag::CMD_FLAG_HS;
|
||||
} else if (tag >= DeviceValueTAG::TAG_AHS1 && tag <= DeviceValueTAG::TAG_AHS1) {
|
||||
return CommandFlag::CMD_FLAG_AHS;
|
||||
} else if (tag >= DeviceValueTAG::TAG_SRC1 && tag <= DeviceValueTAG::TAG_SRC16) {
|
||||
return CommandFlag::CMD_FLAG_SRC;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// convert UOM to a char string - translating only for hours/minutes/seconds
|
||||
const char * EMSdevice::uom_to_string(uint8_t uom) {
|
||||
switch (uom) {
|
||||
@@ -90,6 +105,9 @@ const char * EMSdevice::uom_to_string(uint8_t uom) {
|
||||
}
|
||||
|
||||
const char * EMSdevice::brand_to_char() {
|
||||
if (!custom_brand().empty()) {
|
||||
return custom_brand().c_str();
|
||||
}
|
||||
switch (brand_) {
|
||||
case EMSdevice::Brand::BOSCH:
|
||||
return F_(bosch);
|
||||
@@ -316,7 +334,7 @@ std::string EMSdevice::to_string() {
|
||||
return std::string(name()) + " (DeviceID:" + Helpers::hextoa(device_id_) + ")";
|
||||
}
|
||||
|
||||
if (brand_ == Brand::NO_BRAND) {
|
||||
if (brand_ == Brand::NO_BRAND && custom_brand().empty()) {
|
||||
return std::string(name()) + " (DeviceID:" + Helpers::hextoa(device_id_) + ", ProductID:" + Helpers::itoa(product_id_) + ", Version:" + version_ + ")";
|
||||
}
|
||||
|
||||
@@ -332,7 +350,7 @@ std::string EMSdevice::to_string_version() {
|
||||
// returns out brand + device name
|
||||
// translated
|
||||
std::string EMSdevice::to_string_short() {
|
||||
if (brand_ == Brand::NO_BRAND) {
|
||||
if (brand_ == Brand::NO_BRAND && custom_brand().empty()) {
|
||||
return std::string(device_type_2_device_name_translated()) + ": " + name();
|
||||
}
|
||||
|
||||
@@ -650,25 +668,21 @@ void EMSdevice::add_device_value(int8_t tag, // to b
|
||||
|
||||
// add a new command if it has a function attached
|
||||
if (has_cmd) {
|
||||
uint8_t flags = CommandFlag::ADMIN_ONLY; // executing commands require admin privileges
|
||||
|
||||
if (tag >= DeviceValueTAG::TAG_HC1 && tag <= DeviceValueTAG::TAG_HC8) {
|
||||
flags |= CommandFlag::CMD_FLAG_HC;
|
||||
} else if (tag >= DeviceValueTAG::TAG_DHW1 && tag <= DeviceValueTAG::TAG_DHW10) {
|
||||
flags |= CommandFlag::CMD_FLAG_DHW;
|
||||
} else if (tag >= DeviceValueTAG::TAG_HS1 && tag <= DeviceValueTAG::TAG_HS16) {
|
||||
flags |= CommandFlag::CMD_FLAG_HS;
|
||||
} else if (tag >= DeviceValueTAG::TAG_AHS1 && tag <= DeviceValueTAG::TAG_AHS1) {
|
||||
flags |= CommandFlag::CMD_FLAG_AHS;
|
||||
} else if (tag >= DeviceValueTAG::TAG_SRC1 && tag <= DeviceValueTAG::TAG_SRC16) {
|
||||
flags |= CommandFlag::CMD_FLAG_SRC;
|
||||
}
|
||||
|
||||
uint8_t flags = CommandFlag::ADMIN_ONLY | tag_to_flag(tag); // executing commands require admin privileges
|
||||
// add the command to our library
|
||||
Command::add(device_type_, device_id_, short_name, f, fullname, flags);
|
||||
}
|
||||
}
|
||||
|
||||
void EMSdevice::erase_device_values() {
|
||||
for (auto & dv : devicevalues_) {
|
||||
if (dv.has_cmd) {
|
||||
Command::erase_command(device_type_, dv.short_name, tag_to_flag(dv.tag));
|
||||
}
|
||||
}
|
||||
devicevalues_.clear();
|
||||
}
|
||||
|
||||
// single list of options
|
||||
void EMSdevice::register_device_value(int8_t tag,
|
||||
void * value_p,
|
||||
|
||||
@@ -55,6 +55,7 @@ class EMSdevice {
|
||||
static const char * tag_to_mqtt(int8_t tag);
|
||||
static uint8_t decode_brand(uint8_t value);
|
||||
static bool export_values(uint8_t device_type, JsonObject output, const int8_t id, const uint8_t output_target);
|
||||
static uint8_t tag_to_flag(const uint8_t tag);
|
||||
|
||||
// non static functions
|
||||
|
||||
@@ -124,6 +125,14 @@ class EMSdevice {
|
||||
return custom_name_;
|
||||
}
|
||||
|
||||
// set custom brand
|
||||
void custom_brand(std::string const & custom_brand) {
|
||||
custom_brand_ = custom_brand;
|
||||
}
|
||||
|
||||
std::string custom_brand() const {
|
||||
return custom_brand_;
|
||||
}
|
||||
// set device model
|
||||
void model(std::string const & model) {
|
||||
model_ = model;
|
||||
@@ -282,6 +291,8 @@ class EMSdevice {
|
||||
int16_t min,
|
||||
uint32_t max);
|
||||
|
||||
void erase_device_values();
|
||||
|
||||
void
|
||||
register_device_value(int8_t tag, void * value_p, uint8_t type, const char * const ** options, const char * const * name, uint8_t uom, const cmd_function_p f);
|
||||
|
||||
@@ -524,12 +535,13 @@ class EMSdevice {
|
||||
uint8_t device_id_ = 0;
|
||||
uint8_t product_id_ = 0;
|
||||
char version_[6];
|
||||
const char * default_name_; // the fixed name the EMS model taken from the device library
|
||||
std::string custom_name_ = ""; // custom name
|
||||
std::string model_ = ""; // model, taken from the 0x01 telegram. see process_deviceName()
|
||||
uint8_t flags_ = 0;
|
||||
uint8_t brand_ = Brand::NO_BRAND;
|
||||
bool active_ = true;
|
||||
const char * default_name_; // the fixed name the EMS model taken from the device library
|
||||
std::string custom_name_ = ""; // custom name
|
||||
std::string custom_brand_ = ""; // custom brand
|
||||
std::string model_ = ""; // model, taken from the 0x01 telegram. see process_deviceName()
|
||||
uint8_t flags_ = 0;
|
||||
uint8_t brand_ = Brand::NO_BRAND;
|
||||
bool active_ = true;
|
||||
|
||||
bool ha_config_done_ = false;
|
||||
bool has_update_ = false;
|
||||
|
||||
@@ -1310,6 +1310,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
if (product_id == 0 || (*it)->product_id() != 0) { // update only with valid product_id
|
||||
return true;
|
||||
}
|
||||
(*it)->erase_device_values();
|
||||
emsdevices.erase(it); // erase the old device without product_id and re detect
|
||||
break;
|
||||
}
|
||||
@@ -1450,6 +1451,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
||||
if ((e.device_id == device_id) && (e.product_id == product_id)) {
|
||||
LOG_DEBUG("Have customizations for %s with deviceID 0x%02X productID %d", e.custom_name.c_str(), device_id, product_id);
|
||||
emsdevices.back()->custom_name(e.custom_name);
|
||||
emsdevices.back()->custom_brand(e.custom_brand);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1760,7 +1762,7 @@ void EMSESP::start() {
|
||||
nvs_.begin("ems-esp", false, "nvs"); // fallback to small nvs
|
||||
}
|
||||
|
||||
LOG_DEBUG("NVS device information: %s", system_.getBBQKeesGatewayDetails().isEmpty() ? "not set" : system_.getBBQKeesGatewayDetails().c_str());
|
||||
LOG_DEBUG("Fuse device information: %s", system_.getBBQKeesGatewayDetails().isEmpty() ? "not set" : system_.getBBQKeesGatewayDetails().c_str());
|
||||
|
||||
webSettingsService.begin(); // load EMS-ESP Application settings
|
||||
|
||||
|
||||
Reference in New Issue
Block a user