Skip to content

Commit

Permalink
text changes and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
proddy committed Aug 29, 2023
1 parent f46b002 commit 2fe18c1
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 28 deletions.
19 changes: 12 additions & 7 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
char new_path[Mqtt::MQTT_TOPIC_MAX_SIZE];
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 {
return message(CommandRet::ERROR, "unrecognized path", output); // error
}
Expand Down Expand Up @@ -194,7 +194,7 @@ uint8_t Command::process(const char * path, const bool is_admin, const JsonObjec
} else if (data.isNull()) {
return_code = Command::call(device_type, command_p, "", is_admin, id_n, output); // empty, will do a query instead
} 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;
}
Expand Down Expand Up @@ -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);

// 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)
if ((device_type > EMSdevice::DeviceType::SYSTEM) && (!value || !strlen(value))) {
if (!cf || !cf->cmdfunction_json_) {
// this is used to fetch the attributes of the device entity, or call a command directly
bool single_command = (!value || !strlen(value));
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);
return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd
}
Expand Down Expand Up @@ -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)
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
} else {
return_code = ((cf->cmdfunction_)(value, id)) ? CommandRet::OK : CommandRet::ERROR;
Expand Down Expand Up @@ -593,7 +598,7 @@ void Command::show_devices(uuid::console::Shell & shell) {
// output list of all commands to console
// calls show with verbose mode set
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
shell.print(COLOR_BOLD_ON);
Expand Down
14 changes: 7 additions & 7 deletions src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void EMSESP::dump_all_values(uuid::console::Shell & shell) {
if (device.product_id == 160) { // MM100
device_id = 0x28; // wwc
} else {
device_id = 0x20; // hc
device_id = 0x20; // hc
}
} else {
device_id = 0x20; // should cover all the other device types
Expand Down Expand Up @@ -926,7 +926,7 @@ bool EMSESP::process_telegram(std::shared_ptr<const Telegram> telegram) {
if (telegram->type_id == publish_id_) {
publish_id_ = 0;
}
emsdevice->has_update(false); // reset flag
emsdevice->has_update(false); // reset flag
if (!Mqtt::publish_single()) {
publish_device_values(emsdevice->device_type()); // publish to MQTT if we explicitly have too
}
Expand Down Expand Up @@ -1118,7 +1118,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
name = "Modem";
device_type = DeviceType::CONNECT;
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CONVERTER) {
name = "Converter"; // generic
name = "Converter"; // generic
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CLOCK) {
name = "Clock"; // generic
device_type = DeviceType::CONTROLLER;
Expand Down Expand Up @@ -1390,7 +1390,7 @@ void EMSESP::incoming_telegram(uint8_t * data, const uint8_t length) {
#endif
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
}
}

Expand Down Expand Up @@ -1470,8 +1470,8 @@ void EMSESP::start() {
bool factory_settings = false;
#endif

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
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

LOG_INFO("Starting EMS-ESP version %s", EMSESP_APP_VERSION); // welcome message
LOG_DEBUG("System is running in Debug mode");
Expand All @@ -1491,7 +1491,7 @@ void EMSESP::start() {
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
webSchedulerService.begin(); // load the scheduler events
Expand Down
24 changes: 14 additions & 10 deletions src/mqtt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,9 +278,13 @@ void Mqtt::on_message(const char * topic, const uint8_t * payload, size_t len) c
if (return_code != CommandRet::OK) {
char error[100];
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 {
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);
Mqtt::queue_publish("response", error);
Expand Down Expand Up @@ -506,7 +510,7 @@ void Mqtt::on_connect() {
// publish to the last will topic (see Mqtt::start() function) to say we're alive
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
Expand Down Expand Up @@ -679,7 +683,7 @@ bool Mqtt::queue_remove_topic(const char * topic) {
if (ha_enabled_) {
return queue_publish_message(Mqtt::discovery_prefix() + topic, "", true); // publish with retain to remove from broker
} 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
}
}

Expand All @@ -691,7 +695,7 @@ bool Mqtt::queue_ha(const char * topic, const JsonObject & payload) {

std::string payload_text;
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
}
Expand Down Expand Up @@ -860,7 +864,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
if (type == DeviceValueType::BOOL) {
snprintf(topic, sizeof(topic), "binary_sensor/%s", config_topic); // binary sensor (for booleans)
} else {
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor
snprintf(topic, sizeof(topic), "sensor/%s", config_topic); // normal HA sensor
}
}

Expand All @@ -874,13 +878,13 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
// build the payload
StaticJsonDocument<EMSESP_JSON_SIZE_LARGE> doc;
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 * sc_ha = "stat_cla"; // state class
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
// we add the command topic parameter
Expand Down Expand Up @@ -952,7 +956,7 @@ bool Mqtt::publish_ha_sensor_config(uint8_t type, // EMSdev
} else {
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;

// value template
Expand Down Expand Up @@ -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) {
snprintf(uniq_id_s, sizeof(uniq_id_s), "%s_thermostat_hc%d", mqtt_basename_.c_str(), hc_num); // add basename
} 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);
Expand Down
4 changes: 2 additions & 2 deletions src/web/WebAPIService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
if (return_code != CommandRet::OK) {
char error[100];
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 {
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);
api_fails_++;
Expand Down
4 changes: 2 additions & 2 deletions src/web/WebEntityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ bool WebEntityService::get_value_info(JsonObject & output, const char * cmd) {
return false;
}
if (Helpers::toLower(cmd) == "commands") {
output["info"] = "lists all values";
output["commands"] = "lists all commands";
output["info"] = "list all values";
output["commands"] = "list all commands";
for (const auto & entity : *entityItems) {
output[entity.name] = "custom entitiy";
}
Expand Down

0 comments on commit 2fe18c1

Please sign in to comment.