mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-06 15:59:52 +03:00
info shows shortnames, only valid hcs
This commit is contained in:
@@ -130,28 +130,16 @@ void WebAPIService::parse(AsyncWebServerRequest * request, std::string & device_
|
||||
// /{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());
|
||||
|
||||
// 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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return (json.size() > 0);
|
||||
}
|
||||
|
||||
// send all dallas sensor values as a JSON package to MQTT
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user