customizations: tag not part of name, don't show Custom Entities as device

This commit is contained in:
MichaelDvP
2024-09-20 13:30:47 +02:00
parent cf9bd4d824
commit c2b52f731c
3 changed files with 23 additions and 10 deletions

View File

@@ -268,10 +268,16 @@ const Customizations = () => {
const formatName = (de: DeviceEntity, withShortname: boolean) => const formatName = (de: DeviceEntity, withShortname: boolean) =>
(de.n && de.n[0] === '!' (de.n && de.n[0] === '!'
? LL.COMMAND(1) + ': ' + de.n.slice(1) ? de.t
? LL.COMMAND(1) + ': ' + de.t + ' ' + de.n.slice(1)
: LL.COMMAND(1) + ': ' + de.n.slice(1)
: de.cn && de.cn !== '' : de.cn && de.cn !== ''
? de.cn ? de.t
: de.n) + (withShortname ? ' ' + de.id : ''); ? de.t + ' ' + de.cn
: de.cn
: de.t
? de.t + ' ' + de.n
: de.n) + (withShortname ? ' ' + de.id : '');
const getMaskNumber = (newMask: string[]) => { const getMaskNumber = (newMask: string[]) => {
let new_mask = 0; let new_mask = 0;
@@ -449,11 +455,14 @@ const Customizations = () => {
<MenuItem disabled key={-1} value={-1}> <MenuItem disabled key={-1} value={-1}>
{LL.SELECT_DEVICE()}... {LL.SELECT_DEVICE()}...
</MenuItem> </MenuItem>
{devices.devices.map((device: Device) => ( {devices.devices.map(
<MenuItem key={device.id} value={device.id}> (device: Device) =>
{device.n}&nbsp;({device.tn}) device.id < 90 && (
</MenuItem> <MenuItem key={device.id} value={device.id}>
))} {device.n}&nbsp;({device.tn})
</MenuItem>
)
)}
</TextField> </TextField>
)} )}
{selectedDevice !== -1 && {selectedDevice !== -1 &&

View File

@@ -134,6 +134,7 @@ export interface DeviceEntity {
v?: unknown; // value, in any format, optional v?: unknown; // value, in any format, optional
n?: string; // fullname, optional n?: string; // fullname, optional
cn?: string; // custom fullname, optional cn?: string; // custom fullname, optional
t?: string; // tag for name
m: DeviceEntityMask; // mask m: DeviceEntityMask; // mask
w: boolean; // writeable w: boolean; // writeable
mi?: number; // min value mi?: number; // min value

View File

@@ -1080,7 +1080,8 @@ void EMSdevice::generate_values_web_customization(JsonArray output) {
auto fullname = Helpers::translated_word(dv.fullname); auto fullname = Helpers::translated_word(dv.fullname);
if (dv.type != DeviceValueType::CMD) { if (dv.type != DeviceValueType::CMD) {
if (fullname) { if (fullname) {
obj["n"] = dv.has_tag() ? std::string(tag_to_string(dv.tag)) + " " + fullname : fullname; // prefix tag // obj["n"] = dv.has_tag() ? std::string(tag_to_string(dv.tag)) + " " + fullname : fullname; // prefix tag
obj["n"] = fullname;
// TAG https://github.com/emsesp/EMS-ESP32/issues/1338 // TAG https://github.com/emsesp/EMS-ESP32/issues/1338
// obj["n"] = (dv.has_tag()) ? fullname + " " + tag_to_string(dv.tag) : fullname; // suffix tag // obj["n"] = (dv.has_tag()) ? fullname + " " + tag_to_string(dv.tag) : fullname; // suffix tag
@@ -1094,7 +1095,9 @@ void EMSdevice::generate_values_web_customization(JsonArray output) {
} else { } else {
obj["n"] = "!" + std::string(fullname); // prefix commands with a ! obj["n"] = "!" + std::string(fullname); // prefix commands with a !
} }
if (dv.has_tag()) {
obj["t"] = tag_to_string(dv.tag);
}
obj["m"] = dv.state >> 4; // send back the mask state. We're only interested in the high nibble 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["w"] = dv.has_cmd; // if writable