Skip to content

Commit

Permalink
show scheduler/custom always
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Sep 17, 2023
1 parent 7310db6 commit 9d3456c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 34 deletions.
4 changes: 0 additions & 4 deletions src/analogsensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
#include "mqtt.h"
#include "console.h"

#ifndef EMSESP_STANDALONE
#include "driver/adc.h"
#endif

#include <uuid/log.h>

namespace emsesp {
Expand Down
36 changes: 20 additions & 16 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,19 +541,23 @@ bool Command::device_has_commands(const uint8_t device_type) {
}

if (device_type == EMSdevice::DeviceType::SCHEDULER) {
return EMSESP::webSchedulerService.has_commands();
return true; // we always have info
// return EMSESP::webSchedulerService.has_commands();
}

if (device_type == EMSdevice::DeviceType::CUSTOM) {
return (EMSESP::webEntityService.count_entities() != 0);
return true; // we always have info
// return (EMSESP::webEntityService.count_entities() != 0);
}

if (device_type == EMSdevice::DeviceType::TEMPERATURESENSOR) {
return (EMSESP::temperaturesensor_.have_sensors());
return true; // we always have info
// return (EMSESP::temperaturesensor_.have_sensors());
}

if (device_type == EMSdevice::DeviceType::ANALOGSENSOR) {
return (EMSESP::analogsensor_.have_sensors());
return EMSESP::system_.analog_enabled();
// return (EMSESP::analogsensor_.have_sensors());
}

for (const auto & emsdevice : EMSESP::emsdevices) {
Expand All @@ -574,13 +578,13 @@ bool Command::device_has_commands(const uint8_t device_type) {
void Command::show_devices(uuid::console::Shell & shell) {
shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SYSTEM));

if (EMSESP::webSchedulerService.has_commands()) {
// if (EMSESP::webSchedulerService.has_commands()) {
shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SCHEDULER));
}
if (EMSESP::temperaturesensor_.have_sensors()) {
// }
// if (EMSESP::temperaturesensor_.have_sensors()) {
shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR));
}
if (EMSESP::analogsensor_.have_sensors()) {
// }
if (EMSESP::analogsensor_.analog_enabled()) {
shell.printf("%s ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::ANALOGSENSOR));
}

Expand Down Expand Up @@ -608,7 +612,7 @@ void Command::show_all(uuid::console::Shell & shell) {
show(shell, EMSdevice::DeviceType::SYSTEM, true);

// show Custom
if (EMSESP::webEntityService.has_commands()) {
// if (EMSESP::webEntityService.has_commands()) {
shell.print(COLOR_BOLD_ON);
shell.print(COLOR_YELLOW);
shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::CUSTOM));
Expand All @@ -618,10 +622,10 @@ void Command::show_all(uuid::console::Shell & shell) {
shell.printf(" commands: %slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED);
shell.print(COLOR_RESET);
show(shell, EMSdevice::DeviceType::CUSTOM, true);
}
// }

// show scheduler
if (EMSESP::webSchedulerService.has_commands()) {
// if (EMSESP::webSchedulerService.has_commands()) {
shell.print(COLOR_BOLD_ON);
shell.print(COLOR_YELLOW);
shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::SCHEDULER));
Expand All @@ -631,17 +635,17 @@ void Command::show_all(uuid::console::Shell & shell) {
shell.printf(" commands: %slists all commands %s*", COLOR_BRIGHT_CYAN, COLOR_BRIGHT_RED);
shell.print(COLOR_RESET);
show(shell, EMSdevice::DeviceType::SCHEDULER, true);
}
// }

// show sensors
if (EMSESP::temperaturesensor_.have_sensors()) {
// if (EMSESP::temperaturesensor_.have_sensors()) {
shell.print(COLOR_BOLD_ON);
shell.print(COLOR_YELLOW);
shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::TEMPERATURESENSOR));
shell.print(COLOR_RESET);
show(shell, EMSdevice::DeviceType::TEMPERATURESENSOR, true);
}
if (EMSESP::analogsensor_.have_sensors()) {
// }
if (EMSESP::analogsensor_.analog_enabled()) {
shell.print(COLOR_BOLD_ON);
shell.print(COLOR_YELLOW);
shell.printf(" %s: ", EMSdevice::device_type_2_device_name(EMSdevice::DeviceType::ANALOGSENSOR));
Expand Down
15 changes: 8 additions & 7 deletions src/web/WebEntityService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,25 @@ void WebEntityService::render_value(JsonObject & output, EntityItem entity, cons
// process json output for info/commands and value_info
bool WebEntityService::get_value_info(JsonObject & output, const char * cmd) {
EMSESP::webEntityService.read([&](WebEntity & webEntity) { entityItems = &webEntity.entityItems; });
if (entityItems->size() == 0) {
return false;
}
if (Helpers::toLower(cmd) == "commands") {
output["info"] = "list all values";
output["commands"] = "list all commands";
if (Helpers::toLower(cmd) == F_(commands)) {
output[F_(info)] = Helpers::translated_word(FL_(info_cmd));
output[F_(commands)] = Helpers::translated_word(FL_(commands_cmd));
for (const auto & entity : *entityItems) {
output[entity.name] = "custom entitiy";
}
return true;
}
if (strlen(cmd) == 0 || Helpers::toLower(cmd) == "values" || Helpers::toLower(cmd) == "info") {
if (strlen(cmd) == 0 || Helpers::toLower(cmd) == F_(values) || Helpers::toLower(cmd) == F_(info)) {
// list all names
for (const EntityItem & entity : *entityItems) {
render_value(output, entity);
}
return (output.size() != 0);
}
if (entityItems->size() == 0) {
output["message"] = "no custom entities";
return false;
}
char command_s[30];
strlcpy(command_s, cmd, sizeof(command_s));
char * attribute_s = nullptr;
Expand Down
15 changes: 8 additions & 7 deletions src/web/WebSchedulerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,17 @@ bool WebSchedulerService::command_setvalue(const char * value, const std::string
// process json output for info/commands and value_info
bool WebSchedulerService::get_value_info(JsonObject & output, const char * cmd) {
EMSESP::webSchedulerService.read([&](WebScheduler & webScheduler) { scheduleItems = &webScheduler.scheduleItems; });
if (scheduleItems->size() == 0) {
return false;
}
if (Helpers::toLower(cmd) == "commands") {
output["info"] = "lists all values";
output["commands"] = "lists all commands";
if (Helpers::toLower(cmd) == F_(commands)) {
output[F_(info)] = Helpers::translated_word(FL_(info_cmd));
output[F_(commands)] = Helpers::translated_word(FL_(commands_cmd));
for (const ScheduleItem & scheduleItem : *scheduleItems) {
if (!scheduleItem.name.empty()) {
output[scheduleItem.name] = "activate schedule";
}
}
return true;
}
if (strlen(cmd) == 0 || Helpers::toLower(cmd) == "values" || Helpers::toLower(cmd) == "info") {
if (strlen(cmd) == 0 || Helpers::toLower(cmd) == F_(values) || Helpers::toLower(cmd) == F_(info)) {
// list all names
for (const ScheduleItem & scheduleItem : *scheduleItems) {
if (!scheduleItem.name.empty()) {
Expand All @@ -161,6 +158,10 @@ bool WebSchedulerService::get_value_info(JsonObject & output, const char * cmd)
}
return (output.size() > 0);
}
if (scheduleItems->size() == 0) {
output["message"] = "no schedules";
return false;
}
char command_s[30];
strlcpy(command_s, cmd, sizeof(command_s));
char * attribute_s = nullptr;
Expand Down

0 comments on commit 9d3456c

Please sign in to comment.