mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
changes to #828
This commit is contained in:
@@ -187,7 +187,6 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
newSettings.clientId = root["client_id"] | FACTORY_MQTT_CLIENT_ID;
|
||||
newSettings.keepAlive = root["keep_alive"] | FACTORY_MQTT_KEEP_ALIVE;
|
||||
newSettings.cleanSession = root["clean_session"] | FACTORY_MQTT_CLEAN_SESSION;
|
||||
newSettings.entity_format = root["entity_format"] | FACTORY_MQTT_ENTITY_FORMAT;
|
||||
newSettings.mqtt_qos = root["mqtt_qos"] | EMSESP_DEFAULT_MQTT_QOS;
|
||||
newSettings.mqtt_retain = root["mqtt_retain"] | EMSESP_DEFAULT_MQTT_RETAIN;
|
||||
|
||||
@@ -205,6 +204,7 @@ StateUpdateResult MqttSettings::update(JsonObject & root, MqttSettings & setting
|
||||
newSettings.publish_single = root["publish_single"] | EMSESP_DEFAULT_PUBLISH_SINGLE;
|
||||
newSettings.publish_single2cmd = root["publish_single2cmd"] | EMSESP_DEFAULT_PUBLISH_SINGLE2CMD;
|
||||
newSettings.send_response = root["send_response"] | EMSESP_DEFAULT_SEND_RESPONSE;
|
||||
newSettings.entity_format = root["entity_format"] | EMSESP_DEFAULT_ENTITY_FORMAT;
|
||||
|
||||
if (newSettings.enabled != settings.enabled) {
|
||||
changed = true;
|
||||
|
||||
@@ -57,10 +57,6 @@ static String generateClientId() {
|
||||
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
|
||||
#endif
|
||||
|
||||
#ifndef FACTORY_MQTT_ENTITY_FORMAT
|
||||
#define FACTORY_MQTT_ENTITY_FORMAT 1 // use shortnames
|
||||
#endif
|
||||
|
||||
class MqttSettings {
|
||||
public:
|
||||
// host and port - if enabled
|
||||
@@ -79,9 +75,6 @@ class MqttSettings {
|
||||
uint16_t keepAlive;
|
||||
bool cleanSession;
|
||||
|
||||
// multiple instances
|
||||
uint8_t entity_format;
|
||||
|
||||
// proddy EMS-ESP specific
|
||||
String base;
|
||||
uint16_t publish_time_boiler;
|
||||
@@ -99,6 +92,7 @@ class MqttSettings {
|
||||
bool publish_single;
|
||||
bool publish_single2cmd;
|
||||
bool send_response;
|
||||
uint8_t entity_format;
|
||||
|
||||
static void read(MqttSettings & settings, JsonObject & root);
|
||||
static StateUpdateResult update(JsonObject & root, MqttSettings & settings);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
# use like
|
||||
# strips out lines between two markers
|
||||
# pipe a file into, for example:
|
||||
# make clean; make ARGS=-DEMSESP_STANDALONE_DUMP; echo "test dump" | ./emsesp | python3 ./scripts/dump_entities.py
|
||||
|
||||
import fileinput
|
||||
|
||||
@@ -2,4 +2,8 @@
|
||||
|
||||
# creates an CSV file called "dump_entities.cvs" with all devices and their entities
|
||||
# run from top folder like `sh ./scripts/dump_entities.sh`
|
||||
make clean; make ARGS=-DEMSESP_STANDALONE_DUMP; echo "test dump" | ./emsesp | python3 ./scripts/dump_entities.py > dump_entities.csv
|
||||
rm -f dump_entities.csv
|
||||
make clean;
|
||||
make ARGS=-DEMSESP_STANDALONE_DUMP;
|
||||
echo "test dump" | ./emsesp | python3 ./scripts/dump_entities.py > dump_entities.csv
|
||||
cat dump_entities.csv
|
||||
@@ -209,6 +209,10 @@
|
||||
#define EMSESP_DEFAULT_WEBLOG_COMPACT true
|
||||
#endif
|
||||
|
||||
#ifndef EMSESP_DEFAULT_ENTITY_FORMAT
|
||||
#define EMSESP_DEFAULT_ENTITY_FORMAT 1 // in MQTT discovery, use shortnames and not multiple (prefixed with base)
|
||||
#endif
|
||||
|
||||
// matches Web UI settings
|
||||
enum {
|
||||
|
||||
|
||||
@@ -1063,7 +1063,8 @@ void EMSdevice::getCustomEntities(std::vector<std::string> & entity_ids) {
|
||||
}
|
||||
|
||||
#if defined(EMSESP_STANDALONE_DUMP)
|
||||
// device name, device type, shortname, fullname, type [(enum values) | (min/max)], uom, readable, writeable, visible
|
||||
// dumps all entity values in native English
|
||||
// device name,device type,product_id,shortname,fullname,type [(enum values) | (min/max)],uom,writeable,discovery_entityid
|
||||
void EMSdevice::dump_value_info() {
|
||||
for (auto & dv : devicevalues_) {
|
||||
Serial.print(name_);
|
||||
@@ -1071,9 +1072,13 @@ void EMSdevice::dump_value_info() {
|
||||
Serial.print(device_type_name().c_str());
|
||||
Serial.print(',');
|
||||
|
||||
Serial.print(product_id_);
|
||||
Serial.print(',');
|
||||
|
||||
Serial.print(dv.short_name);
|
||||
Serial.print(',');
|
||||
Serial.print(dv.get_fullname().c_str());
|
||||
|
||||
Serial.print(dv.fullname[0]);
|
||||
Serial.print(',');
|
||||
|
||||
// type and optional enum values and min/max
|
||||
@@ -1161,12 +1166,54 @@ void EMSdevice::dump_value_info() {
|
||||
}
|
||||
Serial.print(",");
|
||||
|
||||
// readable, writeable, visible flags
|
||||
Serial.print(!dv.has_state(DeviceValueState::DV_API_MQTT_EXCLUDE) ? "true" : "false");
|
||||
// writeable flag
|
||||
Serial.print(dv.has_cmd ? "true" : "false");
|
||||
Serial.print(",");
|
||||
Serial.print((dv.has_cmd && !dv.has_state(DeviceValueState::DV_READONLY)) ? "true" : "false");
|
||||
Serial.print(",");
|
||||
Serial.print(!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) ? "true" : "false");
|
||||
|
||||
// MQTT Discovery entity name, assuming we're using the default v3.5 option
|
||||
char entity_with_tag[50];
|
||||
if (dv.tag >= DeviceValueTAG::TAG_HC1) {
|
||||
snprintf(entity_with_tag,
|
||||
sizeof(entity_with_tag),
|
||||
"%s_%s_%s",
|
||||
device_type_2_device_name(device_type_),
|
||||
EMSdevice::tag_to_mqtt(dv.tag).c_str(),
|
||||
dv.short_name);
|
||||
} else {
|
||||
// should really test for which device types have tags (like hc, wwc etc)
|
||||
// snprintf(entity_with_tag, sizeof(entity_with_tag), "%s_[<tag>_]%s", device_type_2_device_name(device_type_), dv.short_name);
|
||||
snprintf(entity_with_tag, sizeof(entity_with_tag), "%s_%s", device_type_2_device_name(device_type_), dv.short_name);
|
||||
}
|
||||
|
||||
char entityid[150];
|
||||
if (dv.has_cmd) {
|
||||
switch (dv.type) {
|
||||
case DeviceValueType::INT:
|
||||
case DeviceValueType::UINT:
|
||||
case DeviceValueType::SHORT:
|
||||
case DeviceValueType::USHORT:
|
||||
case DeviceValueType::ULONG:
|
||||
snprintf(entityid, sizeof(entityid), "number.%s", entity_with_tag);
|
||||
break;
|
||||
case DeviceValueType::BOOL:
|
||||
snprintf(entityid, sizeof(entityid), "switch.%s", entity_with_tag);
|
||||
break;
|
||||
case DeviceValueType::ENUM:
|
||||
snprintf(entityid, sizeof(entityid), "select.%s", entity_with_tag);
|
||||
break;
|
||||
default:
|
||||
snprintf(entityid, sizeof(entityid), "sensor.%s", entity_with_tag);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if (dv.type == DeviceValueType::BOOL) {
|
||||
snprintf(entityid, sizeof(entityid), "binary_sensor.%s", entity_with_tag); // binary sensor (for booleans)
|
||||
} else {
|
||||
snprintf(entityid, sizeof(entityid), "sensor.%s", entity_with_tag); // normal HA sensor
|
||||
}
|
||||
}
|
||||
|
||||
Serial.print(entityid);
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
@@ -201,7 +201,9 @@ class EMSdevice {
|
||||
bool get_value_info(JsonObject & root, const char * cmd, const int8_t id);
|
||||
void get_dv_info(JsonObject & json);
|
||||
|
||||
#if defined(EMSESP_STANDALONE_DUMP)
|
||||
void dump_value_info();
|
||||
#endif
|
||||
|
||||
enum OUTPUT_TARGET : uint8_t { API_VERBOSE, API_SHORTNAMES, MQTT, CONSOLE };
|
||||
bool generate_values(JsonObject & output, const uint8_t tag_filter, const bool nested, const uint8_t output_target);
|
||||
|
||||
@@ -313,7 +313,7 @@ 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,shortname,fullname,type [(enum values) | (min/max)],uom,readable,writeable,visible");
|
||||
Serial.print("device name,device type,product_id,shortname,fullname,type [(enum values) | (min/max)],uom,writeable,discovery_entityid");
|
||||
Serial.println();
|
||||
|
||||
for (const auto & device_class : EMSFactory::device_handlers()) {
|
||||
|
||||
@@ -992,12 +992,11 @@ void Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
||||
// prefix base name to each uniq_id and use the shortname
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s_%s", mqtt_basename_.c_str(), device_name, entity_with_tag);
|
||||
} else if (Mqtt::entity_format() == 1) {
|
||||
// shortname, no mqtt base
|
||||
// shortname, no mqtt base. This is the default version.
|
||||
snprintf(uniq_id, sizeof(uniq_id), "%s_%s", device_name, entity_with_tag);
|
||||
} else {
|
||||
// entity_format is 0
|
||||
// old v3.4 style
|
||||
// take en_name and replace all spaces and lowercase it
|
||||
// entity_format is 0, the old v3.4 style
|
||||
// take en_name and replace all spaces
|
||||
char uniq_s[60];
|
||||
strlcpy(uniq_s, en_name, sizeof(uniq_s));
|
||||
Helpers::replace_char(uniq_s, ' ', '_');
|
||||
|
||||
Reference in New Issue
Block a user