mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
more fixes - Refactor MQTT subscriptions #173
This commit is contained in:
@@ -18,7 +18,10 @@ upload_flags =
|
||||
--auth=ems-esp-neo
|
||||
upload_port = ems-esp.local
|
||||
|
||||
extra_scripts = scripts/rename_fw.py ; don't build WebUI just firmware
|
||||
; use this when you don't want to re-build the WebUI
|
||||
extra_scripts =
|
||||
scripts/rename_fw.py
|
||||
scripts/upload_fw.py
|
||||
|
||||
; pio run -e debug
|
||||
; or from Visual Studio Code do PIO -> Project Tasks -> debug -> General -> Upload and Monitor
|
||||
|
||||
@@ -106,12 +106,20 @@ uint8_t Command::process(const char * path, const bool authenticated, const Json
|
||||
|
||||
// some commands may be prefixed with hc. or wwc. so extract these if they exist
|
||||
// parse_command_string returns the extracted command
|
||||
// exit if we don't have a command
|
||||
command_p = parse_command_string(command_p, id_n);
|
||||
if (command_p == nullptr) {
|
||||
output.clear();
|
||||
output["message"] = "missing or bad command";
|
||||
return CommandRet::NOT_FOUND;
|
||||
// default to info or values, only for device endpoints like api/system or api/boiler
|
||||
if (num_paths < 3) {
|
||||
if (device_type == EMSdevice::DeviceType::SYSTEM) {
|
||||
command_p = "info";
|
||||
} else {
|
||||
command_p = "values";
|
||||
}
|
||||
} else {
|
||||
output.clear();
|
||||
output["message"] = "missing or bad command";
|
||||
return CommandRet::NOT_FOUND;
|
||||
}
|
||||
}
|
||||
|
||||
// if we don't have an id/hc/wwc try and get it from the JSON input
|
||||
@@ -237,6 +245,8 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
||||
uint8_t Command::call(const uint8_t device_type, const char * cmd, const char * value, bool authenticated, const int8_t id, JsonObject & output) {
|
||||
uint8_t return_code = CommandRet::OK;
|
||||
|
||||
std::string dname = EMSdevice::device_type_2_device_name(device_type);
|
||||
|
||||
// see if there is a command registered
|
||||
auto cf = find_command(device_type, cmd);
|
||||
|
||||
@@ -244,13 +254,13 @@ uint8_t Command::call(const uint8_t device_type, const char * cmd, const char *
|
||||
// except for system commands as this is a special device without any queryable entities (device values)
|
||||
if ((device_type != EMSdevice::DeviceType::SYSTEM) && (!value || !strlen(value))) {
|
||||
if (!cf || !cf->cmdfunction_json_) {
|
||||
LOG_INFO(F("Calling %s command '%s' to retrieve values"), dname.c_str(), cmd);
|
||||
return EMSESP::get_device_value_info(output, cmd, id, device_type) ? CommandRet::OK : CommandRet::ERROR; // entity = cmd
|
||||
}
|
||||
}
|
||||
|
||||
if (cf) {
|
||||
// we have a matching command
|
||||
std::string dname = EMSdevice::device_type_2_device_name(device_type);
|
||||
if ((value == nullptr) || !strlen(value)) {
|
||||
LOG_INFO(F("Calling %s command '%s'"), dname.c_str(), cmd);
|
||||
} else if (id == -1) {
|
||||
|
||||
@@ -248,7 +248,7 @@ class EMSdevice {
|
||||
const std::string get_value_uom(const char * key);
|
||||
bool get_value_info(JsonObject & root, const char * cmd, const int8_t id);
|
||||
|
||||
enum OUTPUT_TARGET : uint8_t { API_VERBOSE, API_SHORT, MQTT };
|
||||
enum OUTPUT_TARGET : uint8_t { API_VERBOSE, API_SHORTNAMES, MQTT };
|
||||
bool generate_values_json(JsonObject & output, const uint8_t tag_filter, const bool nested, const uint8_t output_target);
|
||||
void generate_values_json_web(JsonObject & output);
|
||||
|
||||
|
||||
@@ -998,9 +998,9 @@ bool EMSESP::add_device(const uint8_t device_id, const uint8_t product_id, std::
|
||||
F_(info_cmd));
|
||||
Command::add(
|
||||
device_type,
|
||||
F("list"),
|
||||
F("values"),
|
||||
[device_type](const char * value, const int8_t id, JsonObject & output) {
|
||||
return command_info(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_SHORT); // HIDDEN command showing short names, used in e.g. /api/boiler
|
||||
return command_info(device_type, output, id, EMSdevice::OUTPUT_TARGET::API_SHORTNAMES); // HIDDEN command showing short names, used in e.g. /api/boiler
|
||||
},
|
||||
nullptr,
|
||||
CommandFlag::HIDDEN); // this command is hidden
|
||||
|
||||
@@ -508,6 +508,7 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
return;
|
||||
*/
|
||||
|
||||
/*
|
||||
request2.url("/api/thermostat"); // check if defaults to info
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
request2.url("/api/thermostat/info");
|
||||
@@ -519,6 +520,33 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
request2.url("/api/thermostat/mode");
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
return;
|
||||
*/
|
||||
|
||||
request2.url("/api/system"); // check if defaults to info
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
request2.url("/api/system/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
request2.url("/api/thermostat"); // check if defaults to values
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
request2.url("/api/thermostat/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
request2.url("/api/thermostat/seltemp");
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
|
||||
emsesp::EMSESP::logger().notice("****");
|
||||
request2.url("/api/dallassensor/fdfd");
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
request2.url("/api/dallassensor/info");
|
||||
EMSESP::webAPIService.webAPIService_get(&request2);
|
||||
return;
|
||||
|
||||
/*
|
||||
AsyncWebServerRequest request2;
|
||||
@@ -595,7 +623,6 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
Mqtt::base("home/cellar/heating");
|
||||
EMSESP::mqtt_.incoming("home/cellar/heating/thermostat/mode"); // empty payload, sends reponse
|
||||
|
||||
|
||||
#if defined(EMSESP_STANDALONE)
|
||||
// Web API TESTS
|
||||
AsyncWebServerRequest request;
|
||||
@@ -673,6 +700,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & cmd) {
|
||||
request.url("/rest/writeValue");
|
||||
EMSESP::webDataService.write_value(&request, json);
|
||||
|
||||
emsesp::EMSESP::logger().notice("*");
|
||||
|
||||
// should fail
|
||||
char data8[] = "{}";
|
||||
deserializeJson(doc, data8);
|
||||
|
||||
@@ -62,13 +62,8 @@ void WebAPIService::parse(AsyncWebServerRequest * request, JsonObject & input) {
|
||||
auto method = request->method();
|
||||
bool authenticated = false;
|
||||
|
||||
if (method == HTTP_GET) {
|
||||
// special case if there is no command, then default to 'list' which is like info but showing short names
|
||||
if (!input.size()) {
|
||||
input["cmd"] = "list";
|
||||
}
|
||||
} else {
|
||||
// if its a POST then check authentication
|
||||
// if its a POST then check authentication
|
||||
if (method != HTTP_GET) {
|
||||
EMSESP::webSettingsService.read([&](WebSettings & settings) {
|
||||
Authentication authentication = _securityManager->authenticateRequest(request);
|
||||
authenticated = settings.notoken_api | AuthenticationPredicates::IS_ADMIN(authentication);
|
||||
|
||||
Reference in New Issue
Block a user