mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
minor cleanup of debug statements #632
This commit is contained in:
@@ -23,7 +23,6 @@ namespace emsesp {
|
||||
|
||||
// mapping of UOM, to match order in DeviceValueUOM enum emsdevice.h
|
||||
// must be an int of 4 bytes, 32bit aligned
|
||||
// TODO see if its easier to use const strings here
|
||||
static const __FlashStringHelper * DeviceValueUOM_s[] __attribute__((__aligned__(sizeof(int)))) PROGMEM = {
|
||||
|
||||
F_(degrees),
|
||||
@@ -67,7 +66,7 @@ const std::string EMSdevice::tag_to_string(uint8_t tag) {
|
||||
if (tag == DeviceValueTAG::TAG_NONE) {
|
||||
return std::string{};
|
||||
}
|
||||
return uuid::read_flash_string(DeviceValueTAG_s[tag]);
|
||||
return uuid::read_flash_string(DeviceValueTAG_s[tag - 1]); // offset by 1 to account for NONE
|
||||
}
|
||||
|
||||
const std::vector<EMSdevice::DeviceValue> EMSdevice::devicevalues() const {
|
||||
@@ -532,8 +531,6 @@ bool EMSdevice::generate_values_json_web(JsonObject & json) {
|
||||
|
||||
// For each value in the device create the json object pair and add it to given json
|
||||
// return false if empty
|
||||
|
||||
// TODO fix tag_filter!
|
||||
bool EMSdevice::generate_values_json(JsonObject & root, const uint8_t tag_filter, const bool verbose) {
|
||||
bool has_value = false; // to see if we've added a value. it's faster than doing a json.size() at the end
|
||||
uint8_t old_tag = 255;
|
||||
|
||||
29
src/mqtt.cpp
29
src/mqtt.cpp
@@ -745,17 +745,14 @@ void Mqtt::register_mqtt_ha_sensor(uint8_t type, // device v
|
||||
// DynamicJsonDocument doc(EMSESP_JSON_SIZE_HA_CONFIG);
|
||||
StaticJsonDocument<EMSESP_JSON_SIZE_HA_CONFIG> doc; // TODO see if this crashes ESP8266?
|
||||
|
||||
// TODO fix prefix
|
||||
char prefix[10] = "test"; // TODO remove!
|
||||
|
||||
bool have_prefix = ((prefix[0] != '\0') && (device_type != EMSdevice::DeviceType::BOILER));
|
||||
bool have_prefix = ((tag != DeviceValueTAG::TAG_NONE) && (device_type != EMSdevice::DeviceType::BOILER));
|
||||
|
||||
// create entity by inserting any given prefix
|
||||
// we ignore the tag if BOILER
|
||||
char new_entity[50];
|
||||
// special case for boiler - don't use the prefix
|
||||
if (have_prefix) {
|
||||
snprintf_P(new_entity, sizeof(new_entity), PSTR("%s.%s"), prefix, uuid::read_flash_string(entity).c_str());
|
||||
snprintf_P(new_entity, sizeof(new_entity), PSTR("%s.%s"), EMSdevice::tag_to_string(tag).c_str(), uuid::read_flash_string(entity).c_str());
|
||||
} else {
|
||||
snprintf_P(new_entity, sizeof(new_entity), PSTR("%s"), uuid::read_flash_string(entity).c_str());
|
||||
}
|
||||
@@ -769,35 +766,29 @@ void Mqtt::register_mqtt_ha_sensor(uint8_t type, // device v
|
||||
std::string uniq(50, '\0');
|
||||
snprintf_P(&uniq[0], uniq.capacity() + 1, PSTR("%s_%s"), device_name, new_entity);
|
||||
std::replace(uniq.begin(), uniq.end(), '.', '_');
|
||||
|
||||
// topic
|
||||
char topic[MQTT_TOPIC_MAX_SIZE];
|
||||
doc["uniq_id"] = uniq;
|
||||
|
||||
// state topic
|
||||
// if its a boiler we use the tag
|
||||
char stat_t[MQTT_TOPIC_MAX_SIZE];
|
||||
if (device_type == EMSdevice::DeviceType::BOILER) {
|
||||
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), hostname_.c_str(), prefix);
|
||||
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s"), hostname_.c_str(), EMSdevice::tag_to_string(tag).c_str());
|
||||
} else {
|
||||
snprintf_P(stat_t, sizeof(stat_t), PSTR("%s/%s_data"), hostname_.c_str(), device_name);
|
||||
}
|
||||
|
||||
// ha device
|
||||
char ha_device[40];
|
||||
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), device_name);
|
||||
doc["stat_t"] = stat_t;
|
||||
|
||||
// name
|
||||
char new_name[50];
|
||||
if (have_prefix) {
|
||||
snprintf_P(new_name, sizeof(new_name), PSTR("%s %s %s"), device_name, prefix, uuid::read_flash_string(name).c_str());
|
||||
snprintf_P(new_name, sizeof(new_name), PSTR("%s %s %s"), device_name, EMSdevice::tag_to_string(tag).c_str(), uuid::read_flash_string(name).c_str());
|
||||
} else {
|
||||
snprintf_P(new_name, sizeof(new_name), PSTR("%s %s"), device_name, uuid::read_flash_string(name).c_str());
|
||||
}
|
||||
new_name[0] = toupper(new_name[0]); // capitalize first letter
|
||||
doc["name"] = new_name;
|
||||
|
||||
doc["name"] = new_name;
|
||||
doc["uniq_id"] = uniq;
|
||||
doc["stat_t"] = stat_t;
|
||||
char topic[MQTT_TOPIC_MAX_SIZE]; // reserved for topic
|
||||
|
||||
// look at the device value type
|
||||
if (type != DeviceValueType::BOOL) {
|
||||
@@ -850,6 +841,10 @@ void Mqtt::register_mqtt_ha_sensor(uint8_t type, // device v
|
||||
|
||||
JsonObject dev = doc.createNestedObject("dev");
|
||||
JsonArray ids = dev.createNestedArray("ids");
|
||||
|
||||
// ha device
|
||||
char ha_device[40];
|
||||
snprintf_P(ha_device, sizeof(ha_device), PSTR("ems-esp-%s"), device_name);
|
||||
ids.add(ha_device);
|
||||
|
||||
publish_ha(topic, doc.as<JsonObject>());
|
||||
|
||||
Reference in New Issue
Block a user