mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 07:49:52 +03:00
text changes and formatting
This commit is contained in:
@@ -46,7 +46,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
if (!strncmp(path, Mqtt::base().c_str(), Mqtt::base().length())) {
|
if (!strncmp(path, Mqtt::base().c_str(), Mqtt::base().length())) {
|
||||||
char new_path[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
char new_path[Mqtt::MQTT_TOPIC_MAX_SIZE];
|
||||||
strlcpy(new_path, path, sizeof(new_path));
|
strlcpy(new_path, path, sizeof(new_path));
|
||||||
p.parse(new_path + Mqtt::base().length() + 1); // re-parse the stripped path
|
p.parse(new_path + Mqtt::base().length() + 1); // re-parse the stripped path
|
||||||
} else {
|
} else {
|
||||||
return message(CommandRet::ERROR, "unrecognized path", output); // error
|
return message(CommandRet::ERROR, "unrecognized path", output); // error
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
|
|||||||
} else if (data.isNull()) {
|
} else if (data.isNull()) {
|
||||||
return_code = Command::call(device_type, command_p, "", is_admin, id_n, output); // empty, will do a query instead
|
return_code = Command::call(device_type, command_p, "", is_admin, id_n, output); // empty, will do a query instead
|
||||||
} else {
|
} else {
|
||||||
return message(CommandRet::ERROR, "cannot parse command", output); // can't process
|
return message(CommandRet::ERROR, "cannot parse command", output); // can't process
|
||||||
}
|
}
|
||||||
return return_code;
|
return return_code;
|
||||||
}
|
}
|
||||||
@@ -301,9 +301,14 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
|||||||
auto cf = find_command(device_type, device_id, cmd);
|
auto cf = find_command(device_type, device_id, cmd);
|
||||||
|
|
||||||
// check if its a call to and end-point to a device
|
// check if its a call to and end-point to a device
|
||||||
// except for system commands as this is a special device without any queryable entities (device values)
|
// this is used to fetch the attributes of the device entity, or call a command directly
|
||||||
if ((device_type > EMSdevice::DeviceType::SYSTEM) && (!value || !strlen(value))) {
|
bool single_command = (!value || !strlen(value));
|
||||||
if (!cf || !cf->cmdfunction_json_) {
|
if (single_command) {
|
||||||
|
// exception 1: anything that is from System
|
||||||
|
// exception 2: boiler coldshot command
|
||||||
|
bool get_attributes = (!cf || !cf->cmdfunction_json_) && (device_type > EMSdevice::DeviceType::SYSTEM) && (strcmp(cmd, F_(coldshot)) != 0);
|
||||||
|
|
||||||
|
if (get_attributes) {
|
||||||
LOG_DEBUG("Calling %s command '%s' to retrieve attributes", dname, cmd);
|
LOG_DEBUG("Calling %s command '%s' to retrieve attributes", dname, cmd);
|
||||||
return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd
|
return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd
|
||||||
}
|
}
|
||||||
@@ -344,7 +349,7 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
|||||||
|
|
||||||
// check if read-only. This also checks for valid tags (e.g. heating circuits)
|
// check if read-only. This also checks for valid tags (e.g. heating circuits)
|
||||||
if (cf->cmdfunction_) {
|
if (cf->cmdfunction_) {
|
||||||
if (EMSESP::cmd_is_readonly(device_type, device_id, cmd, id)) {
|
if (!single_command && EMSESP::cmd_is_readonly(device_type, device_id, cmd, id)) {
|
||||||
return_code = CommandRet::INVALID; // readonly or invalid hc
|
return_code = CommandRet::INVALID; // readonly or invalid hc
|
||||||
} else {
|
} else {
|
||||||
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR;
|
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR;
|
||||||
@@ -593,7 +598,7 @@ void Command::show_devices(uuid::console::Shell & shell) {
|
|||||||
// output list of all commands to console
|
// output list of all commands to console
|
||||||
// calls show with verbose mode set
|
// calls show with verbose mode set
|
||||||
void Command::show_all(uuid::console::Shell & shell) {
|
void Command::show_all(uuid::console::Shell & shell) {
|
||||||
shell.println("Available commands (*=do not need authorization): ");
|
shell.println("Available commands (*=authorization not required): ");
|
||||||
|
|
||||||
// show system first
|
// show system first
|
||||||
shell.print(COLOR_BOLD_ON);
|
shell.print(COLOR_BOLD_ON);
|
||||||
|
|||||||
@@ -341,7 +341,7 @@ void EMSESP::dump_all_values(uuid::console::Shell & shell) {
|
|||||||
if (device.product_id == 160) { // MM100
|
if (device.product_id == 160) { // MM100
|
||||||
device_id = 0x28; // wwc
|
device_id = 0x28; // wwc
|
||||||
} else {
|
} else {
|
||||||
device_id = 0x20; // hc
|
device_id = 0x20; // hc
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
device_id = 0x20; // should cover all the other device types
|
device_id = 0x20; // should cover all the other device types
|
||||||
@@ -926,7 +926,7 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
|
|||||||
if (telegram->type_id == publish_id_) {
|
if (telegram->type_id == publish_id_) {
|
||||||
publish_id_ = 0;
|
publish_id_ = 0;
|
||||||
}
|
}
|
||||||
emsdevice->has_update(false); // reset flag
|
emsdevice->has_update(false); // reset flag
|
||||||
if (!Mqtt::publish_single()) {
|
if (!Mqtt::publish_single()) {
|
||||||
publish_device_values(emsdevice->device_type()); // publish to MQTT if we explicitly have too
|
publish_device_values(emsdevice->device_type()); // publish to MQTT if we explicitly have too
|
||||||
}
|
}
|
||||||
@@ -1118,7 +1118,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
|
|||||||
name = "Modem";
|
name = "Modem";
|
||||||
device_type = DeviceType::CONNECT;
|
device_type = DeviceType::CONNECT;
|
||||||
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CONVERTER) {
|
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CONVERTER) {
|
||||||
name = "Converter"; // generic
|
name = "Converter"; // generic
|
||||||
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CLOCK) {
|
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CLOCK) {
|
||||||
name = "Clock"; // generic
|
name = "Clock"; // generic
|
||||||
device_type = DeviceType::CONTROLLER;
|
device_type = DeviceType::CONTROLLER;
|
||||||
@@ -1390,7 +1390,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
|
|||||||
#endif
|
#endif
|
||||||
Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data); // check if there is a message for the roomcontroller
|
Roomctrl::check((data[1] ^ 0x80 ^ rxservice_.ems_mask()), data); // check if there is a message for the roomcontroller
|
||||||
|
|
||||||
rxservice_.add(data, length); // add to RxQueue
|
rxservice_.add(data, length); // add to RxQueue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1470,8 +1470,8 @@ void EMSESP::start() {
|
|||||||
bool factory_settings = false;
|
bool factory_settings = false;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
|
esp8266React.begin(); // loads core system services settings (network, mqtt, ap, ntp etc)
|
||||||
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
|
webLogService.begin(); // start web log service. now we can start capturing logs to the web log
|
||||||
|
|
||||||
LOG_INFO("Starting EMS-ESP version %s", EMSESP_APP_VERSION); // welcome message
|
LOG_INFO("Starting EMS-ESP version %s", EMSESP_APP_VERSION); // welcome message
|
||||||
LOG_DEBUG("System is running in Debug mode");
|
LOG_DEBUG("System is running in Debug mode");
|
||||||
@@ -1491,7 +1491,7 @@ void EMSESP::start() {
|
|||||||
system_.system_restart();
|
system_.system_restart();
|
||||||
};
|
};
|
||||||
|
|
||||||
system_.reload_settings(); // ... and store some of the settings locally
|
system_.reload_settings(); // ... and store some of the settings locally
|
||||||
|
|
||||||
webCustomizationService.begin(); // load the customizations
|
webCustomizationService.begin(); // load the customizations
|
||||||
webSchedulerService.begin(); // load the scheduler events
|
webSchedulerService.begin(); // load the scheduler events
|
||||||
|
|||||||
24
src/mqtt.cpp
24
src/mqtt.cpp
@@ -278,9 +278,13 @@ void Mqtt::on_message(const char * topic, const uint8_t * payload, size_t len) c
|
|||||||
if (return_code != CommandRet::OK) {
|
if (return_code != CommandRet::OK) {
|
||||||
char error[100];
|
char error[100];
|
||||||
if (output.size()) {
|
if (output.size()) {
|
||||||
snprintf(error, sizeof(error), "Call failed with error: %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str());
|
snprintf(error,
|
||||||
|
sizeof(error),
|
||||||
|
"MQTT command failed with error: %s (%s)",
|
||||||
|
(const char *)output["message"],
|
||||||
|
Command::return_code_string(return_code).c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(error, sizeof(error), "Call failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
snprintf(error, sizeof(error), "MQTT command failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
||||||
}
|
}
|
||||||
LOG_ERROR(error);
|
LOG_ERROR(error);
|
||||||
Mqtt::queue_publish("response", error);
|
Mqtt::queue_publish("response", error);
|
||||||
@@ -506,7 +510,7 @@ void Mqtt::on_connect() {
|
|||||||
// publish to the last will topic (see Mqtt::start() function) to say we're alive
|
// publish to the last will topic (see Mqtt::start() function) to say we're alive
|
||||||
queue_publish_retain("status", "online", true); // with retain on
|
queue_publish_retain("status", "online", true); // with retain on
|
||||||
|
|
||||||
mqtt_publish_fails_ = 0; // reset fail count to 0
|
mqtt_publish_fails_ = 0; // reset fail count to 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// Home Assistant Discovery - the main master Device called EMS-ESP
|
// Home Assistant Discovery - the main master Device called EMS-ESP
|
||||||
@@ -679,7 +683,7 @@ bool Mqtt::queue_remove_topic(const char * topic) {
|
|||||||
if (ha_enabled_) {
|
if (ha_enabled_) {
|
||||||
return queue_publish_message(Mqtt::discovery_prefix() + topic, "", true); // publish with retain to remove from broker
|
return queue_publish_message(Mqtt::discovery_prefix() + topic, "", true); // publish with retain to remove from broker
|
||||||
} else {
|
} else {
|
||||||
return queue_publish_message(topic, "", true); // publish with retain to remove from broker
|
return queue_publish_message(topic, "", true); // publish with retain to remove from broker
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -691,7 +695,7 @@ bool Mqtt::queue_ha(const char * topic, const JsonObject & payload) {
|
|||||||
|
|
||||||
std::string payload_text;
|
std::string payload_text;
|
||||||
payload_text.reserve(measureJson(payload) + 1);
|
payload_text.reserve(measureJson(payload) + 1);
|
||||||
serializeJson(payload, payload_text); // convert json to string
|
serializeJson(payload, payload_text); // convert json to string
|
||||||
|
|
||||||
return queue_publish_message(Mqtt::discovery_prefix() + topic, payload_text, true); // with retain true
|
return queue_publish_message(Mqtt::discovery_prefix() + topic, payload_text, true); // with retain true
|
||||||
}
|
}
|
||||||
@@ -860,7 +864,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
if (type == DeviceValueType::BOOL) {
|
if (type == DeviceValueType::BOOL) {
|
||||||
snprintf(topic, sizeof(topic), "binary_sensor/%s", config_topic); // binary sensor (for booleans)
|
snprintf(topic, sizeof(topic), "binary_sensor/%s", config_topic); // binary sensor (for booleans)
|
||||||
} else {
|
} else {
|
||||||
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor
|
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -874,13 +878,13 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
// build the payload
|
// build the payload
|
||||||
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
|
||||||
doc["uniq_id"] = uniq_id;
|
doc["uniq_id"] = uniq_id;
|
||||||
doc["obj_id"] = uniq_id; // same as unique_id
|
doc["obj_id"] = uniq_id; // same as unique_id
|
||||||
|
|
||||||
const char * ic_ha = "ic"; // icon - only set this if there is no device class
|
const char * ic_ha = "ic"; // icon - only set this if there is no device class
|
||||||
const char * sc_ha = "stat_cla"; // state class
|
const char * sc_ha = "stat_cla"; // state class
|
||||||
const char * uom_ha = "unit_of_meas"; // unit of measure
|
const char * uom_ha = "unit_of_meas"; // unit of measure
|
||||||
|
|
||||||
char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet
|
char sample_val[30] = "0"; // sample, correct(!) entity value, used only to prevent warning/error in HA if real value is not published yet
|
||||||
|
|
||||||
// handle commands, which are device entities that are writable
|
// handle commands, which are device entities that are writable
|
||||||
// we add the command topic parameter
|
// we add the command topic parameter
|
||||||
@@ -952,7 +956,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
|
|||||||
} else {
|
} else {
|
||||||
snprintf(ha_name, sizeof(ha_name), "%s", F_name); // no tag
|
snprintf(ha_name, sizeof(ha_name), "%s", F_name); // no tag
|
||||||
}
|
}
|
||||||
free(F_name); // very important!
|
free(F_name); // very important!
|
||||||
doc["name"] = ha_name;
|
doc["name"] = ha_name;
|
||||||
|
|
||||||
// value template
|
// value template
|
||||||
@@ -1164,7 +1168,7 @@ bool Mqtt::publish_ha_climate_config(const uint8_t tag, const bool has_roomtemp,
|
|||||||
if (Mqtt::entity_format() == entityFormat::MULTI_SHORT) {
|
if (Mqtt::entity_format() == entityFormat::MULTI_SHORT) {
|
||||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
|
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
|
||||||
} else {
|
} else {
|
||||||
snprintf(uniq_id_s, sizeof(uniq_id_s), "thermostat_hc%d", hc_num); // backward compatible with v3.4
|
snprintf(uniq_id_s, sizeof(uniq_id_s), "thermostat_hc%d", hc_num); // backward compatible with v3.4
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(temp_cmd_s, sizeof(temp_cmd_s), "~/thermostat/hc%d/seltemp", hc_num);
|
snprintf(temp_cmd_s, sizeof(temp_cmd_s), "~/thermostat/hc%d/seltemp", hc_num);
|
||||||
|
|||||||
@@ -121,9 +121,9 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
|||||||
if (return_code != CommandRet::OK) {
|
if (return_code != CommandRet::OK) {
|
||||||
char error[100];
|
char error[100];
|
||||||
if (output.size()) {
|
if (output.size()) {
|
||||||
snprintf(error, sizeof(error), "Call failed with error: %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str());
|
snprintf(error, sizeof(error), "API failed with error: %s (%s)", (const char *)output["message"], Command::return_code_string(return_code).c_str());
|
||||||
} else {
|
} else {
|
||||||
snprintf(error, sizeof(error), "Call failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
snprintf(error, sizeof(error), "API failed with error code (%s)", Command::return_code_string(return_code).c_str());
|
||||||
}
|
}
|
||||||
emsesp::EMSESP::logger().err(error);
|
emsesp::EMSESP::logger().err(error);
|
||||||
api_fails_++;
|
api_fails_++;
|
||||||
|
|||||||
@@ -219,8 +219,8 @@ bool WebEntityService::get_value_info(JsonObject & output, const char * cmd) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (Helpers::toLower(cmd) == "commands") {
|
if (Helpers::toLower(cmd) == "commands") {
|
||||||
output["info"] = "lists all values";
|
output["info"] = "list all values";
|
||||||
output["commands"] = "lists all commands";
|
output["commands"] = "list all commands";
|
||||||
for (const auto & entity : *entityItems) {
|
for (const auto & entity : *entityItems) {
|
||||||
output[entity.name] = "custom entitiy";
|
output[entity.name] = "custom entitiy";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user