mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
brand_to_string to brand_to_char. use const char * where possible
This commit is contained in:
@@ -79,7 +79,7 @@ const char * EMSdevice::uom_to_string(uint8_t uom) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string EMSdevice::brand_to_string() {
|
const char * EMSdevice::brand_to_char() {
|
||||||
switch (brand_) {
|
switch (brand_) {
|
||||||
case EMSdevice::Brand::BOSCH:
|
case EMSdevice::Brand::BOSCH:
|
||||||
return "Bosch";
|
return "Bosch";
|
||||||
@@ -267,8 +267,8 @@ const std::string EMSdevice::to_string() {
|
|||||||
return std::string(name_) + " (DeviceID:" + Helpers::hextoa(device_id_) + ", ProductID:" + Helpers::itoa(product_id_) + ", Version:" + version_ + ")";
|
return std::string(name_) + " (DeviceID:" + Helpers::hextoa(device_id_) + ", ProductID:" + Helpers::itoa(product_id_) + ", Version:" + version_ + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
return brand_to_string() + " " + name_ + " (DeviceID:" + Helpers::hextoa(device_id_) + ", ProductID:" + Helpers::itoa(product_id_) + ", Version:" + version_
|
return std::string(brand_to_char()) + " " + name_ + " (DeviceID:" + Helpers::hextoa(device_id_) + ", ProductID:" + Helpers::itoa(product_id_)
|
||||||
+ ")";
|
+ ", Version:" + version_ + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns out brand + device name
|
// returns out brand + device name
|
||||||
@@ -278,7 +278,7 @@ const std::string EMSdevice::to_string_short() {
|
|||||||
return std::string(device_type_2_device_name_translated()) + ": " + name_;
|
return std::string(device_type_2_device_name_translated()) + ": " + name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
return std::string(device_type_2_device_name_translated()) + ": " + brand_to_string() + " " + name_;
|
return std::string(device_type_2_device_name_translated()) + ": " + brand_to_char() + " " + name_;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for each telegram that has the fetch value set (true) do a read request
|
// for each telegram that has the fetch value set (true) do a read request
|
||||||
@@ -458,30 +458,18 @@ void EMSdevice::register_telegram_type(const uint16_t telegram_type_id, const ch
|
|||||||
}
|
}
|
||||||
|
|
||||||
// add to device value library, also know now as a "device entity"
|
// add to device value library, also know now as a "device entity"
|
||||||
// arguments are:
|
void EMSdevice::add_device_value(uint8_t tag, // to be used to group mqtt together, either as separate topics as a nested object
|
||||||
// tag: to be used to group mqtt together, either as separate topics as a nested object
|
void * value_p, // pointer to the value from the .h file
|
||||||
// value_p: pointer to the value from the .h file
|
uint8_t type, // one of DeviceValueType
|
||||||
// type: one of DeviceValueType
|
const char * const ** options, // options for enum, which are translated as a list of lists
|
||||||
// options: options for enum, which are translated as a list of lists
|
const char * const * options_single, // list of names
|
||||||
// options_single: list of names
|
int8_t numeric_operator, // to divide or multiply, see DeviceValueNumOps::
|
||||||
// numeric_operator: to divide or multiply, see DeviceValueNumOps::
|
const char * const * name, // shortname, used in MQTT as the key
|
||||||
// short_name: used in MQTT as keys
|
uint8_t uom, // unit of measure from DeviceValueUOM
|
||||||
// fullname: used in Web and Console unless empty (nullptr) - can be translated
|
const cmd_function_p f, // command function pointer
|
||||||
// uom: unit of measure from DeviceValueUOM
|
int16_t min, // min allowed value
|
||||||
// has_cmd: true if this is an associated command
|
uint16_t max // max allowed value
|
||||||
// min: min allowed value
|
) {
|
||||||
// max: max allowed value
|
|
||||||
void EMSdevice::add_device_value(uint8_t tag,
|
|
||||||
void * value_p,
|
|
||||||
uint8_t type,
|
|
||||||
const char * const ** options,
|
|
||||||
const char * const * options_single,
|
|
||||||
int8_t numeric_operator,
|
|
||||||
const char * const * name,
|
|
||||||
uint8_t uom,
|
|
||||||
const cmd_function_p f,
|
|
||||||
int16_t min,
|
|
||||||
uint16_t max) {
|
|
||||||
// initialize the device value depending on it's type
|
// initialize the device value depending on it's type
|
||||||
// ignoring DeviceValueType::CMD and DeviceValueType::TIME
|
// ignoring DeviceValueType::CMD and DeviceValueType::TIME
|
||||||
|
|
||||||
@@ -512,7 +500,12 @@ void EMSdevice::add_device_value(uint8_t tag,
|
|||||||
// get fullname, getting translation if it exists
|
// get fullname, getting translation if it exists
|
||||||
const char * const * fullname;
|
const char * const * fullname;
|
||||||
if (Helpers::count_items(name) == 1) {
|
if (Helpers::count_items(name) == 1) {
|
||||||
fullname = nullptr; // no translations available, use empty to prevent crash
|
#ifdef EMSESP_DEBUG
|
||||||
|
// when compiling in debug, we don't use all the translations to save on Flash memory
|
||||||
|
fullname = &name[0]; // use shortname when debugging
|
||||||
|
#else
|
||||||
|
fullname = nullptr; // no translations available, use empty
|
||||||
|
#endif
|
||||||
} else {
|
} else {
|
||||||
fullname = &name[1]; // translations start at index 1
|
fullname = &name[1]; // translations start at index 1
|
||||||
}
|
}
|
||||||
@@ -1533,11 +1526,7 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c
|
|||||||
for (auto & dv : devicevalues_) {
|
for (auto & dv : devicevalues_) {
|
||||||
// check if it exists, there is a value for the entity. Set the flag to ACTIVE
|
// check if it exists, there is a value for the entity. Set the flag to ACTIVE
|
||||||
// not that this will override any previously removed states
|
// not that this will override any previously removed states
|
||||||
if (dv.hasValue()) {
|
(dv.hasValue()) ? dv.add_state(DeviceValueState::DV_ACTIVE) : dv.remove_state(DeviceValueState::DV_ACTIVE);
|
||||||
dv.add_state(DeviceValueState::DV_ACTIVE);
|
|
||||||
} else {
|
|
||||||
dv.remove_state(DeviceValueState::DV_ACTIVE);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto fullname = dv.get_fullname();
|
auto fullname = dv.get_fullname();
|
||||||
|
|
||||||
@@ -1720,7 +1709,7 @@ void EMSdevice::mqtt_ha_entity_config_create() {
|
|||||||
if (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) && (dv.type != DeviceValueType::CMD) && dv.has_state(DeviceValueState::DV_ACTIVE)
|
if (!dv.has_state(DeviceValueState::DV_HA_CONFIG_CREATED) && (dv.type != DeviceValueType::CMD) && dv.has_state(DeviceValueState::DV_ACTIVE)
|
||||||
&& !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE)) {
|
&& !dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE)) {
|
||||||
// create_device_config is only done once for the EMS device. It can added to any entity, so we take the first
|
// create_device_config is only done once for the EMS device. It can added to any entity, so we take the first
|
||||||
Mqtt::publish_ha_sensor_config(dv, name(), brand_to_string(), false, create_device_config);
|
Mqtt::publish_ha_sensor_config(dv, name(), brand_to_char(), false, create_device_config);
|
||||||
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
dv.add_state(DeviceValueState::DV_HA_CONFIG_CREATED);
|
||||||
create_device_config = false; // only create the main config once
|
create_device_config = false; // only create the main config once
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ class EMSdevice {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string brand_to_string();
|
const char * brand_to_char();
|
||||||
const std::string to_string();
|
const std::string to_string();
|
||||||
const std::string to_string_short();
|
const std::string to_string_short();
|
||||||
|
|
||||||
|
|||||||
@@ -912,7 +912,7 @@ void Mqtt::process_queue() {
|
|||||||
|
|
||||||
// create's a ha sensor config topic from a device value object
|
// create's a ha sensor config topic from a device value object
|
||||||
// and also takes a flag (create_device_config) used to also create the main HA device config. This is only needed for one entity
|
// and also takes a flag (create_device_config) used to also create the main HA device config. This is only needed for one entity
|
||||||
void Mqtt::publish_ha_sensor_config(DeviceValue & dv, const std::string & model, const std::string & brand, const bool remove, const bool create_device_config) {
|
void Mqtt::publish_ha_sensor_config(DeviceValue & dv, const char * model, const char * brand, const bool remove, const bool create_device_config) {
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> dev_json;
|
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> dev_json;
|
||||||
|
|
||||||
// always create the ids
|
// always create the ids
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ class Mqtt {
|
|||||||
static void publish_ha(const char * topic, const JsonObject & payload);
|
static void publish_ha(const char * topic, const JsonObject & payload);
|
||||||
static void publish_ha(const char * topic);
|
static void publish_ha(const char * topic);
|
||||||
|
|
||||||
static void
|
static void publish_ha_sensor_config(DeviceValue & dv, const char * model, const char * brand, const bool remove, const bool create_device_config = false);
|
||||||
publish_ha_sensor_config(DeviceValue & dv, const std::string & model, const std::string & brand, const bool remove, const bool create_device_config = false);
|
|
||||||
static void publish_ha_sensor_config(uint8_t type,
|
static void publish_ha_sensor_config(uint8_t type,
|
||||||
uint8_t tag,
|
uint8_t tag,
|
||||||
const char * const fullname,
|
const char * const fullname,
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ void WebDataService::core_data(AsyncWebServerRequest * request) {
|
|||||||
obj["id"] = Helpers::smallitoa(buffer, emsdevice->unique_id()); // a unique id as a string
|
obj["id"] = Helpers::smallitoa(buffer, emsdevice->unique_id()); // a unique id as a string
|
||||||
obj["tn"] = emsdevice->device_type_2_device_name_translated(); // translated device type name
|
obj["tn"] = emsdevice->device_type_2_device_name_translated(); // translated device type name
|
||||||
obj["t"] = emsdevice->device_type(); // device type number
|
obj["t"] = emsdevice->device_type(); // device type number
|
||||||
obj["b"] = emsdevice->brand_to_string(); // brand
|
obj["b"] = emsdevice->brand_to_char(); // brand
|
||||||
obj["n"] = emsdevice->name(); // name
|
obj["n"] = emsdevice->name(); // name
|
||||||
obj["d"] = emsdevice->device_id(); // deviceid
|
obj["d"] = emsdevice->device_id(); // deviceid
|
||||||
obj["p"] = emsdevice->product_id(); // productid
|
obj["p"] = emsdevice->product_id(); // productid
|
||||||
|
|||||||
Reference in New Issue
Block a user