Skip to content

Commit

Permalink
api: Unify variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
photron committed Dec 13, 2024
1 parent 916ae3d commit 73edded
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions software/src/modules/certs/certs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ void Certs::register_urls()
{
api.addState("certs/state", &state);

api.addCommand("certs/add", &add, {}, [this](String &error) {
api.addCommand("certs/add", &add, {}, [this](String &errmsg) {
if (add.get("cert")->asString().length() == 0) {
error = "Adding an empty certificate is not allowed. Did you mean to call certs/modify?";
errmsg = "Adding an empty certificate is not allowed. Did you mean to call certs/modify?";
return;
}

uint8_t cert_id = add.get("id")->asUint();

for (const auto &cert: state.get("certs")) {
if (cert.get("id")->asUint() == cert_id) {
error = String("A certificate with ID ") + cert_id + " does already exist! Did you mean to call certs/modify?";
errmsg = String("A certificate with ID ") + cert_id + " does already exist! Did you mean to call certs/modify?";
return;
}
}
Expand All @@ -197,7 +197,7 @@ void Certs::register_urls()
this->update_state();
}, true);

api.addCommand("certs/modify", &add, {}, [this](String &error) {
api.addCommand("certs/modify", &add, {}, [this](String &errmsg) {
uint8_t cert_id = add.get("id")->asUint();
bool found = false;
for (const auto &cert: state.get("certs")) {
Expand All @@ -208,7 +208,7 @@ void Certs::register_urls()
}

if (!found) {
error = String("No cert with ID ") + cert_id + " found! Did you mean to call certs/add?";
errmsg = String("No cert with ID ") + cert_id + " found! Did you mean to call certs/add?";
}

{
Expand All @@ -230,13 +230,13 @@ void Certs::register_urls()
this->update_state();
}, true);

api.addCommand("certs/remove", &remove, {}, [this](String &error) {
api.addCommand("certs/remove", &remove, {}, [this](String &errmsg) {
uint8_t cert_id = remove.get("id")->asUint();

String path = get_cert_path(cert_id);

if (!LittleFS.exists(path)) {
error = String("No cert with ID ") + cert_id + " found!";
errmsg = String("No cert with ID ") + cert_id + " found!";
return;
}

Expand Down
8 changes: 4 additions & 4 deletions software/src/modules/em_v2/em_v2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void EMV2::register_urls()
{
this->DeviceModule::register_urls();

api.addCommand("energy_manager/outputs_update", &outputs_update, {}, [this](String &error) {
api.addCommand("energy_manager/outputs_update", &outputs_update, {}, [this](String &errmsg) {
// 2x SG Ready, 2x Relay
uint8_t new_values[4];
this->outputs_update.fillUint8Array(new_values, ARRAY_SIZE(new_values));
Expand All @@ -188,7 +188,7 @@ void EMV2::register_urls()
uint8_t new_value = new_values[i + 2];
if (new_value != 255) {
if (new_value > 1) {
error += "Relay output value out of range [0, 1].\n";
errmsg += "Relay output value out of range [0, 1].\n";
} else {
set_relay_output(i, new_value);
}
Expand All @@ -201,7 +201,7 @@ void EMV2::register_urls()
uint8_t new_value = new_values[i];
if (new_value != 255) {
if (new_value > 1) {
error += "SG Ready output value out of range [0, 1].\n";
errmsg += "SG Ready output value out of range [0, 1].\n";
} else {
bool switching_blocked = false;

Expand All @@ -214,7 +214,7 @@ void EMV2::register_urls()
#endif

if (switching_blocked) {
error += "Cannot control SG Ready output that is currently in use by heating control.\n";
errmsg += "Cannot control SG Ready output that is currently in use by heating control.\n";
} else {
set_sg_ready_output(i, new_value);
}
Expand Down
12 changes: 6 additions & 6 deletions software/src/modules/meters_sun_spec/meters_sun_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ void MetersSunSpec::pre_setup()

void MetersSunSpec::register_urls()
{
api.addCommand("meters_sun_spec/scan", &scan_config, {}, [this](String &error) {
api.addCommand("meters_sun_spec/scan", &scan_config, {}, [this](String &errmsg) {
if (scan_state != ScanState::Idle) {
error = "Another scan is already in progress, please try again later!";
errmsg = "Another scan is already in progress, please try again later!";
return;
}

Expand All @@ -105,30 +105,30 @@ void MetersSunSpec::register_urls()
scan_last_keep_alive = now_us();
}, true);

api.addCommand("meters_sun_spec/scan_continue", &scan_continue_config, {}, [this](String &error) {
api.addCommand("meters_sun_spec/scan_continue", &scan_continue_config, {}, [this](String &errmsg) {
if (scan_state == ScanState::Idle) {
return;
}

uint32_t cookie = scan_continue_config.get("cookie")->asUint();

if (cookie != scan_cookie) {
error = "Cannot continue another scan";
errmsg = "Cannot continue another scan";
return;
}

scan_last_keep_alive = now_us();
}, true);

api.addCommand("meters_sun_spec/scan_abort", &scan_abort_config, {}, [this](String &error) {
api.addCommand("meters_sun_spec/scan_abort", &scan_abort_config, {}, [this](String &errmsg) {
if (scan_state == ScanState::Idle) {
return;
}

uint32_t cookie = scan_abort_config.get("cookie")->asUint();

if (cookie != scan_cookie) {
error = "Cannot abort another scan";
errmsg = "Cannot abort another scan";
return;
}

Expand Down

0 comments on commit 73edded

Please sign in to comment.