Skip to content

Commit

Permalink
cleanup and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Dec 24, 2022
1 parent 9d80c2c commit 70cfbc3
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 95 deletions.
2 changes: 1 addition & 1 deletion interface/.typesafe-i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
"adapter": "react",
"baseLocale": "pl",
"$schema": "https://unpkg.com/typesafe-i18n@5.18.0/schema/typesafe-i18n.json"
}
}
166 changes: 83 additions & 83 deletions interface/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"react-dom": "^18.2.0",
"react-dropzone": "^14.2.3",
"react-icons": "^4.7.1",
"react-router-dom": "^6.6.0",
"react-router-dom": "^6.6.1",
"react-scripts": "5.0.1",
"sockette": "^2.0.6",
"typesafe-i18n": "^5.18.0",
Expand Down
2 changes: 0 additions & 2 deletions src/analogsensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void AnalogSensor::start() {
CommandFlag::HIDDEN); // this command is hidden
Command::add(
EMSdevice::DeviceType::ANALOGSENSOR,
0,
F_(setvalue),
[&](const char * value, const int8_t id) { return command_setvalue(value, id); },
FL_(setiovalue_cmd),
Expand Down Expand Up @@ -121,7 +120,6 @@ void AnalogSensor::reload() {
if (sensor.type == AnalogType::COUNTER || sensor.type >= AnalogType::DIGITAL_OUT) {
Command::add(
EMSdevice::DeviceType::ANALOGSENSOR,
0,
sensor.name.c_str(),
[&](const char * value, const int8_t id) { return command_setvalue(value, sensor.gpio); },
sensor.type == AnalogType::COUNTER ? FL_(counter)
Expand Down
5 changes: 5 additions & 0 deletions src/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ void Command::add(const uint8_t device_type, const uint8_t device_id, const char
cmdfunctions_.emplace_back(device_type, device_id, flags, cmd, cb, nullptr, description); // callback for json is nullptr
}

// same for system/dallas/analog devices with device_id 0
void Command::add(const uint8_t device_type, const char * cmd, const cmd_function_p cb, const char * const * description, uint8_t flags) {
add(device_type, 0, cmd, cb, description, flags);
}

// add a command to the list, which does return a json object as output
void Command::add(const uint8_t device_type, const char * cmd, const cmd_json_function_p cb, const char * const * description, uint8_t flags) {
// if the command already exists for that device type don't add it
Expand Down
7 changes: 7 additions & 0 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ class Command {
const char * const * description,
uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT);

// same for system/dallas/analog devices
static void add(const uint8_t device_type,
const char * cmd,
const cmd_function_p cb,
const char * const * description,
uint8_t flags = CommandFlag::MQTT_SUB_FLAG_DEFAULT);

// callback function taking value, id and a json object for its output
static void add(const uint8_t device_type,
const char * cmd,
Expand Down
4 changes: 4 additions & 0 deletions src/devices/thermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ std::shared_ptr<Thermostat::HeatingCircuit> Thermostat::heating_circuit(const ui
return heating_circuit;
}
}
#if defined(EMSESP_DEBUG)
LOG_DEBUG("Heating circuit not fond on device 0x%02X", device_id());
#endif
return nullptr; // not found
}

Expand Down Expand Up @@ -3244,7 +3246,9 @@ bool Thermostat::set_temperature(const float temperature, const uint8_t mode, co
write_command(set_typeid, offset, (uint8_t)(temperature * (float)factor), validate_typeid);
return true;
}
#if defined(EMSESP_DEBUG)
LOG_DEBUG("temperature mode %d not found", mode);
#endif
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/emsesp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, const
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CONVERTER) {
name = "converter"; // generic
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CLOCK) {
name = "clock"; // generic
name = "clock"; // generic
device_type = DeviceType::CONTROLLER;
} else if (device_id == EMSdevice::EMS_DEVICE_ID_CONTROLLER) {
name = "generic controller";
Expand Down
14 changes: 7 additions & 7 deletions src/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ void System::syslog_init() {
syslog_.hostname(hostname().c_str());

// register the command
Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(syslog), System::command_syslog_level, FL_(changeloglevel_cmd), CommandFlag::ADMIN_ONLY);

} else if (was_enabled) {
// in case service is still running, this flushes the queue
Expand Down Expand Up @@ -730,21 +730,21 @@ void System::system_check() {

// commands - takes static function pointers
void System::commands_init() {
Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(watch), System::command_watch, FL_(watch_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, F_(send), System::command_send, FL_(send_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(fetch), System::command_fetch, FL_(fetch_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(restart), System::command_restart, FL_(restart_cmd), CommandFlag::ADMIN_ONLY);
Command::add(EMSdevice::DeviceType::SYSTEM, F_(watch), System::command_watch, FL_(watch_cmd));

if (Mqtt::enabled()) {
Command::add(EMSdevice::DeviceType::SYSTEM, 0, F_(publish), System::command_publish, FL_(publish_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, F_(publish), System::command_publish, FL_(publish_cmd));
}

// these commands will return data in JSON format
Command::add(EMSdevice::DeviceType::SYSTEM, F_(info), System::command_info, FL_(system_info_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, F_(commands), System::command_commands, FL_(commands_cmd));

#if defined(EMSESP_DEBUG)
Command::add(EMSdevice::DeviceType::SYSTEM, 0, ("test"), System::command_test, FL_(test_cmd));
Command::add(EMSdevice::DeviceType::SYSTEM, ("test"), System::command_test, FL_(test_cmd));
#endif

// MQTT subscribe "ems-esp/system/#"
Expand Down
4 changes: 4 additions & 0 deletions src/web/WebCustomizationService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,12 @@ void WebCustomizationService::device_entities(AsyncWebServerRequest * request, J
JsonArray output = response->getRoot();
emsdevice->generate_values_web_customization(output);
#endif
#if defined(EMSESP_DEBUG)
size_t length = response->setLength();
EMSESP::logger().debug("Customization buffer used: %d", length);
#else
response->setLength();
#endif
request->send(response);
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/web/WebDataService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,12 @@ void WebDataService::device_data(AsyncWebServerRequest * request, JsonVariant &
// #endif
// #endif

#if defined(EMSESP_DEBUG)
size_t length = response->setLength();
EMSESP::logger().debug("Dashboard buffer used: %d", length);
#else
response->setLength();
#endif
request->send(response);
return;
}
Expand Down

0 comments on commit 70cfbc3

Please sign in to comment.