From 7f52ef8bd8e2b3b1cb4d8329bb9bb04534223529 Mon Sep 17 00:00:00 2001 From: MichaelDvP Date: Wed, 5 May 2021 18:48:07 +0200 Subject: [PATCH] info shows shortnames, only valid hcs --- src/WebAPIService.cpp | 34 +++++++++------------------------- src/dallassensor.cpp | 20 ++++++-------------- src/emsdevice.cpp | 2 ++ src/emsesp.cpp | 6 ++++-- 4 files changed, 21 insertions(+), 41 deletions(-) diff --git a/src/WebAPIService.cpp b/src/WebAPIService.cpp index 98caebd02..a018e9f42 100644 --- a/src/WebAPIService.cpp +++ b/src/WebAPIService.cpp @@ -129,29 +129,17 @@ void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_ // parse paths and json data // /{device}[/{hc}][/{name}] // first param must be a valid device, which includes "system" - device_s = p.paths().front(); - device_type = EMSdevice::device_name_2_device_type(device_s.c_str()); + device_s = p.paths().front(); - // if there are no more paths parameters, default to 'info' auto num_paths = p.paths().size(); - if (num_paths > 1) { - auto path2 = p.paths()[1]; // get next path - // if it's a system, the next path must be a command (info, settings,...) - if (device_type == EMSdevice::DeviceType::SYSTEM) { - cmd_s = path2; - } else { - // it's an EMS device - // path2 could be a hc which is optional or a name. first check if it's a hc - if (path2.substr(0, 2) == "hc") { - id_n = (byte)path2[2] - '0'; // bit of a hack - // there must be a name following - if (num_paths > 2) { - cmd_s = p.paths()[2]; - } - } else { - cmd_s = path2; - } - } + if (num_paths == 1) { + // if there are no more paths parameters, default to 'info' + cmd_s = "info"; + } else if (num_paths == 2) { + cmd_s = p.paths()[1]; + } else if (num_paths > 2) { + // command-check makes prefix to TAG + cmd_s = p.paths()[1] + "/" + p.paths()[2]; } } @@ -169,10 +157,6 @@ void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_ } // cmd check - // if the cmd is empty, default it 'info' - if (cmd_s.empty()) { - cmd_s = "info"; - } // check that we have permissions first. We require authenticating on 1 or more of these conditions: // 1. any HTTP POSTs or PUTs diff --git a/src/dallassensor.cpp b/src/dallassensor.cpp index dd1dd7dc5..467c80306 100644 --- a/src/dallassensor.cpp +++ b/src/dallassensor.cpp @@ -310,7 +310,7 @@ bool DallasSensor::updated_values() { // returns false if empty // e.g. dallassensor_data = {"sensor1":{"id":"28-EA41-9497-0E03-5F","temp":23.30},"sensor2":{"id":"28-233D-9497-0C03-8B","temp":24.0}} bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject & json) { - if (sensors_.size() == 0) { + if (sensors_.size() == 0 || id != -1) { return false; } @@ -318,22 +318,14 @@ bool DallasSensor::command_info(const char * value, const int8_t id, JsonObject for (const auto & sensor : sensors_) { char sensorID[10]; // sensor{1-n} snprintf_P(sensorID, 10, PSTR("sensor%d"), i++); - if (id == 0) { - if (Mqtt::dallas_format() == Mqtt::Dallas_Format::SENSORID && Helpers::hasValue(sensor.temperature_c)) { - json[sensor.to_string()] = (float)(sensor.temperature_c) / 10; - } else if (Helpers::hasValue(sensor.temperature_c)) { - json[sensorID] = (float)(sensor.temperature_c) / 10; - } - } else { - JsonObject dataSensor = json.createNestedObject(sensorID); - dataSensor["id"] = sensor.to_string(); - if (Helpers::hasValue(sensor.temperature_c)) { - dataSensor["temp"] = (float)(sensor.temperature_c) / 10; - } + if (Mqtt::dallas_format() == Mqtt::Dallas_Format::SENSORID && Helpers::hasValue(sensor.temperature_c)) { + json[sensor.to_string()] = (float)(sensor.temperature_c) / 10; + } else if (Helpers::hasValue(sensor.temperature_c)) { + json[sensorID] = (float)(sensor.temperature_c) / 10; } } - return true; + return (json.size() > 0); } // send all dallas sensor values as a JSON package to MQTT diff --git a/src/emsdevice.cpp b/src/emsdevice.cpp index abb7574e0..dd558e15a 100644 --- a/src/emsdevice.cpp +++ b/src/emsdevice.cpp @@ -672,6 +672,8 @@ bool EMSdevice::get_value_info(JsonObject & root, const char * cmd, const int8_t tag = DeviceValueTAG::TAG_HC1 + id - 1; } else if (id >= 8 && id <= 11) { tag = DeviceValueTAG::TAG_WWC1 + id - 8; + } else if (id != -1) { + return false; } // search device value with this tag diff --git a/src/emsesp.cpp b/src/emsesp.cpp index 38c8b741d..1196b77bc 100644 --- a/src/emsesp.cpp +++ b/src/emsesp.cpp @@ -984,14 +984,16 @@ bool EMSESP::command_info(uint8_t device_type, JsonObject & json, const int8_t i tag = DeviceValueTAG::TAG_HC1 + id - 1; } else if (id >= 9 && id <= 10) { tag = DeviceValueTAG::TAG_WWC1 + id - 9; - } else { + } else if (id == -1) { tag = DeviceValueTAG::TAG_NONE; + } else { + return false; } for (const auto & emsdevice : emsdevices) { if (emsdevice && (emsdevice->device_type() == device_type) && ((device_type != DeviceType::THERMOSTAT) || (emsdevice->device_id() == EMSESP::actual_master_thermostat()))) { - has_value |= emsdevice->generate_values_json(json, tag, (id < 1), (id == -1)); // nested for id -1,0 & console for id -1 + has_value |= emsdevice->generate_values_json(json, tag, (id == -1), false); // nested for id -1,0 & console for id -1 } }