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

@@ -37,7 +37,7 @@ import CancelIcon from '@mui/icons-material/Cancel';
import SendIcon from '@mui/icons-material/TrendingFlat';
import SaveIcon from '@mui/icons-material/Save';
import RemoveIcon from '@mui/icons-material/RemoveCircleOutline';
import FavoriteIcon from '@mui/icons-material/Favorite';
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import DeviceIcon from './DeviceIcon';
@@ -500,7 +500,7 @@ const DashboardData: FC = () => {
return (
<StyledTableCell component="th" scope="row">
{name}&nbsp;
<PlayArrowIcon color="primary" sx={{ fontSize: 10 }} />
<PlayArrowIcon color="primary" sx={{ fontSize: 12 }} />
</StyledTableCell>
);
}
@@ -509,7 +509,7 @@ const DashboardData: FC = () => {
return (
<StyledTableCell component="th" scope="row">
{name}&nbsp;
<FavoriteIcon color="error" sx={{ fontSize: 10 }} />
<FavoriteBorderIcon color="success" sx={{ fontSize: 10 }} />
</StyledTableCell>
);
}

View File

@@ -213,7 +213,7 @@ const SettingsCustomization: FC = () => {
</TableHead>
<TableBody>
{deviceEntities.map((de) => (
<TableRow key={de.i} hover>
<TableRow key={de.s} hover>
<StyledTableCell padding="checkbox">
<ToggleButtonGroup
size="small"

View File

@@ -148,7 +148,6 @@ export interface DeviceEntity {
s: string; // shortname
m: number; // mask
w?: boolean; // writeable
i: number; // unique id
}
export interface MaskedEntities {

View File

@@ -593,21 +593,21 @@ const emsesp_devicedata_4 = {
const emsesp_deviceentities_1 = [
{
v: '(0)',
n: '00error code',
n: 'error code',
s: 'errorcode',
m: 0,
i: 1,
},
{
v: '14:54:39 06/06/2021',
n: '00date/time',
n: 'date/time',
s: 'datetime',
m: 0,
i: 2,
},
{
v: 18.22,
n: '00hc1 selected room temperature',
n: 'hc1 selected room temperature',
s: 'hc1/seltemp',
m: 0,
w: true,
@@ -615,14 +615,14 @@ const emsesp_deviceentities_1 = [
},
{
v: 22.6,
n: '00hc1 current room temperature',
n: 'hc1 current room temperature',
s: 'hc1/curtemp',
m: 0,
i: 4,
},
{
v: 'auto',
n: '00hc1 mode',
n: 'hc1 mode',
s: 'hc1/mode',
m: 0,
w: true,

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();