mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
some refactoring
This commit is contained in:
@@ -422,7 +422,7 @@ class EMSESPSettingsForm extends Component<EMSESPSettingsFormProps> {
|
|||||||
value="notoken_api"
|
value="notoken_api"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
label="Bypass Access Token authorization on API calls"
|
label="Bypass Access Token authorization on API calls (warning! security vulnerability)"
|
||||||
/>
|
/>
|
||||||
<Grid
|
<Grid
|
||||||
container
|
container
|
||||||
|
|||||||
@@ -41,12 +41,12 @@ void DallasSensor::start() {
|
|||||||
bus_.begin(dallas_gpio_);
|
bus_.begin(dallas_gpio_);
|
||||||
#endif
|
#endif
|
||||||
// API calls
|
// API calls
|
||||||
Command::add_with_json(
|
Command::add_returns_json(
|
||||||
EMSdevice::DeviceType::DALLASSENSOR,
|
EMSdevice::DeviceType::DALLASSENSOR,
|
||||||
F_(info),
|
F_(info),
|
||||||
[&](const char * value, const int8_t id, JsonObject & json) { return command_info(value, id, json); },
|
[&](const char * value, const int8_t id, JsonObject & json) { return command_info(value, id, json); },
|
||||||
F_(info_cmd));
|
F_(info_cmd));
|
||||||
Command::add_with_json(
|
Command::add_returns_json(
|
||||||
EMSdevice::DeviceType::DALLASSENSOR,
|
EMSdevice::DeviceType::DALLASSENSOR,
|
||||||
F_(commands),
|
F_(commands),
|
||||||
[&](const char * value, const int8_t id, JsonObject & json) { return command_commands(value, id, json); },
|
[&](const char * value, const int8_t id, JsonObject & json) { return command_commands(value, id, json); },
|
||||||
|
|||||||
@@ -438,7 +438,7 @@ void EMSdevice::register_telegram_type(const uint16_t telegram_type_id, const __
|
|||||||
// type: one of DeviceValueType
|
// type: one of DeviceValueType
|
||||||
// options: options for enum or a divider for int (e.g. F("10"))
|
// options: options for enum or a divider for int (e.g. F("10"))
|
||||||
// short_name: used in Mqtt as keys
|
// short_name: used in Mqtt as keys
|
||||||
// full name: used in Web and Console unless empty (nullptr)
|
// full_name: used in Web and Console unless empty (nullptr)
|
||||||
// uom: unit of measure from DeviceValueUOM
|
// uom: unit of measure from DeviceValueUOM
|
||||||
void EMSdevice::register_device_value(uint8_t tag,
|
void EMSdevice::register_device_value(uint8_t tag,
|
||||||
void * value_p,
|
void * value_p,
|
||||||
@@ -480,6 +480,7 @@ void EMSdevice::register_device_value(uint8_t tag,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// function with min and max values
|
// function with min and max values
|
||||||
|
// adds a new command to the command list
|
||||||
void EMSdevice::register_device_value(uint8_t tag,
|
void EMSdevice::register_device_value(uint8_t tag,
|
||||||
void * value_p,
|
void * value_p,
|
||||||
uint8_t type,
|
uint8_t type,
|
||||||
@@ -490,14 +491,18 @@ void EMSdevice::register_device_value(uint8_t tag,
|
|||||||
int32_t min,
|
int32_t min,
|
||||||
uint32_t max) {
|
uint32_t max) {
|
||||||
register_device_value(tag, value_p, type, options, name[0], name[1], uom, (f != nullptr), min, max);
|
register_device_value(tag, value_p, type, options, name[0], name[1], uom, (f != nullptr), min, max);
|
||||||
if (f != nullptr) {
|
|
||||||
if (tag >= TAG_HC1 && tag <= TAG_HC4) {
|
// add a new command if it has a function attached
|
||||||
Command::add(device_type_, name[0], f, name[1], FLAG_HC);
|
if (f == nullptr) {
|
||||||
} else if (tag >= TAG_WWC1 && tag <= TAG_WWC4) {
|
return;
|
||||||
Command::add(device_type_, name[0], f, name[1], FLAG_WWC);
|
|
||||||
} else {
|
|
||||||
Command::add(device_type_, name[0], f, name[1], 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tag >= TAG_HC1 && tag <= TAG_HC4) {
|
||||||
|
Command::add(device_type_, name[0], f, name[1], CommandFlag::MQTT_SUB_FLAG_HC | CommandFlag::ADMIN_ONLY);
|
||||||
|
} else if (tag >= TAG_WWC1 && tag <= TAG_WWC4) {
|
||||||
|
Command::add(device_type_, name[0], f, name[1], CommandFlag::MQTT_SUB_FLAG_WWC | CommandFlag::ADMIN_ONLY);
|
||||||
|
} else {
|
||||||
|
Command::add(device_type_, name[0], f, name[1], CommandFlag::MQTT_SUB_FLAG_NORMAL | CommandFlag::ADMIN_ONLY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -982,18 +982,18 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std::
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command::add_with_json(
|
Command::add_returns_json(
|
||||||
device_type,
|
device_type,
|
||||||
F_(info),
|
F_(info),
|
||||||
[device_type](const char * value, const int8_t id, JsonObject & json) { return command_info(device_type, json, id, true); },
|
[device_type](const char * value, const int8_t id, JsonObject & json) { return command_info(device_type, json, id, true); },
|
||||||
F_(info_cmd));
|
F_(info_cmd));
|
||||||
Command::add_with_json(
|
Command::add_returns_json(
|
||||||
device_type,
|
device_type,
|
||||||
F("info_short"),
|
F("info_short"),
|
||||||
[device_type](const char * value, const int8_t id, JsonObject & json) { return command_info(device_type, json, id, false); },
|
[device_type](const char * value, const int8_t id, JsonObject & json) { return command_info(device_type, json, id, false); },
|
||||||
nullptr,
|
nullptr,
|
||||||
true); // this command is hidden
|
CommandFlag::HIDDEN); // this command is hidden
|
||||||
Command::add_with_json(
|
Command::add_returns_json(
|
||||||
device_type,
|
device_type,
|
||||||
F_(commands),
|
F_(commands),
|
||||||
[device_type](const char * value, const int8_t id, JsonObject & json) { return command_commands(device_type, json, id); },
|
[device_type](const char * value, const int8_t id, JsonObject & json) { return command_commands(device_type, json, id); },
|
||||||
|
|||||||
@@ -65,8 +65,8 @@
|
|||||||
#define EMSESP_JSON_SIZE_XXLARGE_DYN 8192 // for extra very very large json docs, using DynamicJsonDocument
|
#define EMSESP_JSON_SIZE_XXLARGE_DYN 8192 // for extra very very large json docs, using DynamicJsonDocument
|
||||||
|
|
||||||
// helpers for callback functions
|
// helpers for callback functions
|
||||||
#define MAKE_PF_CB(__f) [&](std::shared_ptr<const Telegram> t) { __f(t); } // for process function callbacks to register_telegram_type()
|
#define MAKE_PF_CB(__f) [&](std::shared_ptr<const Telegram> t) { __f(t); } // for Process Function callbacks to EMSDevice::process_function_p
|
||||||
#define MAKE_CF_CB(__f) [&](const char * value, const int8_t id) { return __f(value, id); } // for command function callbacks to register_mqtt_cmd()
|
#define MAKE_CF_CB(__f) [&](const char * value, const int8_t id) { return __f(value, id); } // for Command Function callbacks Command::cmdfunction_p
|
||||||
|
|
||||||
namespace emsesp {
|
namespace emsesp {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user