mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 00:09:51 +03:00
minor code optimizations
This commit is contained in:
@@ -563,9 +563,9 @@ static void setup_commands(std::shared_ptr<Commands> & commands) {
|
||||
}
|
||||
return devices_list;
|
||||
} else if (current_arguments.size() == 1) {
|
||||
std::vector<std::string> command_list;
|
||||
uint8_t device_type = EMSdevice::device_name_2_device_type(current_arguments[0].c_str());
|
||||
if (Command::device_has_commands(device_type)) {
|
||||
std::vector<std::string> command_list;
|
||||
for (const auto & cf : Command::commands()) {
|
||||
if (cf.device_type_ == device_type) {
|
||||
command_list.emplace_back(cf.cmd_);
|
||||
|
||||
@@ -392,7 +392,6 @@ void EMSESP::show_device_values(uuid::console::Shell & shell) {
|
||||
// extract the shortname from the key, which is in brackets
|
||||
std::size_t first_bracket = key.find_last_of('(');
|
||||
std::size_t last_bracket = key.find_last_of(')');
|
||||
std::string shortname = key.substr(first_bracket + 1, last_bracket - first_bracket - 1);
|
||||
std::string uom = emsdevice->get_value_uom(key.substr(first_bracket + 1, last_bracket - first_bracket - 1));
|
||||
|
||||
shell.printfln(" %s: %s%s %s%s", key.c_str(), COLOR_BRIGHT_GREEN, p.value().as<std::string>().c_str(), uom.c_str(), COLOR_RESET);
|
||||
|
||||
@@ -629,7 +629,7 @@ void System::send_info_mqtt() {
|
||||
}
|
||||
|
||||
// create the json for heartbeat
|
||||
bool System::heartbeat_json(JsonObject output) {
|
||||
void System::heartbeat_json(JsonObject output) {
|
||||
uint8_t bus_status = EMSESP::bus_status();
|
||||
if (bus_status == EMSESP::BUS_STATUS_TX_ERRORS) {
|
||||
output["bus_status"] = "txerror";
|
||||
@@ -681,8 +681,6 @@ bool System::heartbeat_json(JsonObject output) {
|
||||
output["wifistrength"] = wifi_quality(rssi);
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// send periodic MQTT message with system information
|
||||
@@ -697,9 +695,8 @@ void System::send_heartbeat() {
|
||||
JsonDocument doc;
|
||||
JsonObject json = doc.to<JsonObject>();
|
||||
|
||||
if (heartbeat_json(json)) {
|
||||
heartbeat_json(json);
|
||||
Mqtt::queue_publish(F_(heartbeat), json); // send to MQTT with retain off. This will add to MQTT queue.
|
||||
}
|
||||
}
|
||||
|
||||
// initializes network
|
||||
|
||||
@@ -79,7 +79,7 @@ class System {
|
||||
void syslog_init();
|
||||
bool check_upgrade(bool factory_settings);
|
||||
bool check_restore();
|
||||
bool heartbeat_json(JsonObject output);
|
||||
void heartbeat_json(JsonObject output);
|
||||
void send_heartbeat();
|
||||
void send_info_mqtt();
|
||||
|
||||
|
||||
@@ -414,8 +414,8 @@ bool TemperatureSensor::get_value_info(JsonObject output, const char * cmd, cons
|
||||
if (Helpers::toLower(command_s) == Helpers::toLower(sensor.name().c_str()) || Helpers::toLower(command_s) == Helpers::toLower(sensor.id().c_str())) {
|
||||
output["id"] = sensor.id();
|
||||
output["name"] = sensor.name();
|
||||
char val[10];
|
||||
if (Helpers::hasValue(sensor.temperature_c)) {
|
||||
char val[10];
|
||||
output["value"] = serialized(Helpers::render_value(val, sensor.temperature_c, 10, EMSESP::system_.fahrenheit() ? 2 : 0));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user