Michael's PR merged (dv sort, remove id)

This commit is contained in:
proddy
2022-03-29 09:06:09 +02:00
parent 86430c6408
commit 6f347bd49e
7 changed files with 20 additions and 29 deletions

View File

@@ -395,9 +395,6 @@ void EMSdevice::register_device_value(uint8_t tag,
}
}
// this is the unique id set for the device entity. it's a simple sequence number
uint8_t dv_id = get_next_dv_id();
// determine state
uint8_t state = DeviceValueState::DV_DEFAULT;
@@ -418,7 +415,7 @@ void EMSdevice::register_device_value(uint8_t tag,
});
// add the device
devicevalues_.emplace_back(device_type_, tag, value_p, type, options, options_size, short_name, full_name, uom, 0, has_cmd, min, max, state, dv_id);
devicevalues_.emplace_back(device_type_, tag, value_p, type, options, options_size, short_name, full_name, uom, 0, has_cmd, min, max, state);
}
// function with min and max values
@@ -637,11 +634,15 @@ void EMSdevice::generate_values_web(JsonObject & output) {
output["label"] = to_string_short();
JsonArray data = output.createNestedArray("data");
// do two passes. First for all entities marked as favourites, then for all others. This sorts the list.
for (uint8_t i = 0; i < 2; i++) {
// do two passes. First for all entities marked as favorites, then for all others. This sorts the list.
for (int8_t fav = 1; fav >= 0; fav--) {
for (auto & dv : devicevalues_) {
bool state = (!i && dv.has_state(DeviceValueState::DV_FAVORITE)) || (i && !dv.has_state(DeviceValueState::DV_FAVORITE));
if (state && (!dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.full_name && (dv.hasValue() || (dv.type == DeviceValueType::CMD)))) {
// check conditions:
// 1. full_name cannot be empty
// 2. it must have a valid value, if it is not a command like 'reset'
// 3. show favorites first
bool show = (fav && dv.has_state(DeviceValueState::DV_FAVORITE)) || (!fav && !dv.has_state(DeviceValueState::DV_FAVORITE));
if (show && !dv.has_state(DeviceValueState::DV_WEB_EXCLUDE) && dv.full_name && (dv.hasValue() || (dv.type == DeviceValueType::CMD))) {
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
uint8_t fahrenheit = 0;
@@ -842,7 +843,6 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {
obj["m"] = dv.state >> 4; // send back the mask state. We're only interested in the high nibble
obj["w"] = dv.has_cmd; // if writable
obj["i"] = dv.id; // add the unique ID
}
}

View File

@@ -383,11 +383,6 @@ class EMSdevice {
// device values
std::vector<DeviceValue> devicevalues_;
uint8_t dv_index_ = 0; // unique counter for each added device value
uint8_t get_next_dv_id() {
return (dv_index_++);
}
};
} // namespace emsesp

View File

@@ -137,7 +137,6 @@ class DeviceValue {
int16_t min; // min range
uint16_t max; // max range
uint8_t state; // DeviceValueState::*
uint8_t id; // internal unique counter
DeviceValue(uint8_t device_type,
uint8_t tag,
@@ -152,8 +151,7 @@ class DeviceValue {
bool has_cmd,
int16_t min,
uint16_t max,
uint8_t state,
uint8_t id)
uint8_t state)
: device_type(device_type)
, tag(tag)
, value_p(value_p)
@@ -167,8 +165,7 @@ class DeviceValue {
, has_cmd(has_cmd)
, min(min)
, max(max)
, state(state)
, id(id) {
, state(state) {
}
bool hasValue();